diff --git a/.changeset/wet-wasps-study.md b/.changeset/wet-wasps-study.md new file mode 100644 index 0000000000..d6b30f79c0 --- /dev/null +++ b/.changeset/wet-wasps-study.md @@ -0,0 +1,5 @@ +--- +"viem": patch +--- + +Added support for `'evm_setAccountCode'` to `setCode` action. diff --git a/src/actions/test/setCode.ts b/src/actions/test/setCode.ts index e215a5ebe7..8c3a3a8d1f 100644 --- a/src/actions/test/setCode.ts +++ b/src/actions/test/setCode.ts @@ -50,8 +50,14 @@ export async function setCode< client: TestClient, { address, bytecode }: SetCodeParameters, ) { - await client.request({ - method: `${client.mode}_setCode`, - params: [address, bytecode], - }) + if (client.mode === 'ganache') + await client.request({ + method: 'evm_setAccountCode', + params: [address, bytecode], + }) + else + await client.request({ + method: `${client.mode}_setCode`, + params: [address, bytecode], + }) } diff --git a/src/types/eip1193.ts b/src/types/eip1193.ts index bfdd6c0e7a..2f8fd437d3 100644 --- a/src/types/eip1193.ts +++ b/src/types/eip1193.ts @@ -1335,7 +1335,7 @@ export type TestRpcSchema = [ * @link https://ganache.dev/#evm_setAccountBalance */ { - Method: `evm_setAccountBalance` + Method: 'evm_setAccountBalance' Parameters: [ /** The address of the target account. */ address: Address, @@ -1344,12 +1344,26 @@ export type TestRpcSchema = [ ] ReturnType: void }, + /** + * @description Modifies the bytecode stored at an account's address. + * @link https://ganache.dev/#evm_setAccountCode + */ + { + Method: 'evm_setAccountCode' + Parameters: [ + /** The address of the contract. */ + address: Address, + /** Data bytecode. */ + data: string, + ] + ReturnType: void + }, /** * @description Enables or disables, based on the single boolean argument, the automatic mining of new blocks with each new transaction submitted to the network. * @link https://hardhat.org/hardhat-network/docs/reference#evm_setautomine */ { - Method: `evm_setAutomine` + Method: 'evm_setAutomine' Parameters: [boolean] ReturnType: void }, @@ -1367,7 +1381,7 @@ export type TestRpcSchema = [ * @link https://github.com/trufflesuite/ganache/blob/ef1858d5d6f27e4baeb75cccd57fb3dc77a45ae8/src/chains/ethereum/ethereum/RPC-METHODS.md#evm_increasetime */ { - Method: `evm_increaseTime` + Method: 'evm_increaseTime' Parameters: [seconds: Quantity] ReturnType: Quantity },