EvmError: MemoryOOG error when deploying a contract
In a deploy script i want to deploy 13 contrancts. Then I encountered this error [MemoryOOG] EvmError: MemoryOOG
Hi, thanks for reporting this.
You can avoid this error by setting the block_gas_limit configuration in your Foundry environment to a higher value, so that your script is able to run without being out of gas. After Foundry runs the script with this higher limit to create the transactions locally, it will then broadcast the transactions to your connected chain as normal.
For example, you can set the following in foundry.toml:
block_gas_limit = 3000000000
Side note: It looks like you are pre-deploying the implementation contracts in your initContract() function. This isn't necessary when using Upgrades.deployTransparentProxy, because Upgrades.deployTransparentProxy automatically deploys the implementation before the proxy.
ok,i will setup block_gas_limit = 3000000000 in foundry.toml try again.
Additionally, in initContract() i want to pre-deploying contracts. If I don't do this, I'll get this error.
← [Revert] vm.getCode: no bytecode for contract; is it abstract or unlinked?
└─ ← [Revert] vm.getCode: no bytecode for contract; is it abstract or unlinked?
Additionally, in initContract() i want to pre-deploying contracts. If I don't do this, I'll get this error. ← [Revert] vm.getCode: no bytecode for contract; is it abstract or unlinked? └─ ← [Revert] vm.getCode: no bytecode for contract; is it abstract or unlinked?
Are you using linked libraries in your contracts? That error looks like it is caused by https://github.com/foundry-rs/book/issues/1361 since we use vm.getCode to get the implementation contract to deploy.
With your initContract() approach, you could try moving that outside of the broadcast section, so that the pre-deploys are not broadcast onchain. Otherwise, the implementations would be deployed twice (which isn't a problem but just wastes gas).
For example:
function run() public {
...
initContract();
vm.startBroadcast(privateKey);
...
yeah,it's good advertise to move initContract() out of broadcast.