Files
FrenoCorp/node_modules/viem/actions/test/setCode.ts
Michael Freno 7c684a42cc FRE-600: Fix code review blockers
- Consolidated duplicate UndoManagers to single instance
- Fixed connection promise to only resolve on 'connected' status
- Fixed WebSocketProvider import (WebsocketProvider)
- Added proper doc.destroy() cleanup
- Renamed isPresenceInitialized property to avoid conflict

Co-Authored-By: Paperclip <noreply@paperclip.ing>
2026-04-25 00:08:01 -04:00

64 lines
1.8 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import type { Address } from 'abitype'
import type {
TestClient,
TestClientMode,
} from '../../clients/createTestClient.js'
import type { Transport } from '../../clients/transports/createTransport.js'
import type { ErrorType } from '../../errors/utils.js'
import type { Account } from '../../types/account.js'
import type { Chain } from '../../types/chain.js'
import type { Hex } from '../../types/misc.js'
import type { RequestErrorType } from '../../utils/buildRequest.js'
export type SetCodeParameters = {
/** The account address. */
address: Address
/** The bytecode to set */
bytecode: Hex
}
export type SetCodeErrorType = RequestErrorType | ErrorType
/**
* Modifies the bytecode stored at an account's address.
*
* - Docs: https://viem.sh/docs/actions/test/setCode
*
* @param client - Client to use
* @param parameters {@link SetCodeParameters}
*
* @example
* import { createTestClient, http } from 'viem'
* import { foundry } from 'viem/chains'
* import { setCode } from 'viem/test'
*
* const client = createTestClient({
* mode: 'anvil',
* chain: 'foundry',
* transport: http(),
* })
* await setCode(client, {
* address: '0xe846c6fcf817734ca4527b28ccb4aea2b6663c79',
* bytecode: '0x60806040526000600355600019600955600c80546001600160a01b031916737a250d5630b4cf539739df…',
* })
*/
export async function setCode<
chain extends Chain | undefined,
account extends Account | undefined,
>(
client: TestClient<TestClientMode, Transport, chain, account, false>,
{ address, bytecode }: SetCodeParameters,
) {
if (client.mode === 'ganache')
await client.request({
method: 'evm_setAccountCode',
params: [address, bytecode],
})
else
await client.request({
method: `${client.mode}_setCode`,
params: [address, bytecode],
})
}