Solidity合约部署失败:missing trie node错误求助
问题重现
部署包含storage数组初始化的Solidity合约时触发missing trie node错误,移除数组状态变量及相关函数后部署成功。
原合约代码
// SPDX-License-Identifier: MIT pragma solidity ^0.8.21; contract sample{ function fCalldata(uint[] calldata _x) public pure returns (uint[] calldata){ // 参数为 calldata 数组,不能被修改 // _x[0] = 0; return(_x); } uint[] x = [1,2,3]; // 状态变量,数组 x function fStorage() public { // 声明一个 storage 的变量,指向 x。修改xStorage 也会影响 x uint[] storage xStorage = x; xStorage[0] = 100; } }
错误信息
creation of sample errored: Error occurred: processing response error (body="{"jsonrpc":"2.0","id":74,"error":{"code":-32000,"message":"missing trie node c91d4ecd59dce3067d340b3aadfc0542974b4fb4db98af39f980a91ea00db9dc (path ) state 0xc91d4ecd59dce3067d340b3aadfc0542974b4fb4db98af39f980a91ea00db9dc is not available, not found"}}
", error={"code":-32000}, requestBody="{"method":"eth_getStorageAt","params":["0xb2a5a8a976688097483a68cdd2f534c6bb0351ac","0x0000000000000000000000000000000000000000000000000000000000000000","0x1"],"id":74,"jsonrpc":"2.0"}", requestMethod="POST", url="https://go.getblock.io/ee42d0a88f314707be11dd799b122cb9", code=SERVER_ERROR, version=web/5.7.1).
processing response error (body="{"jsonrpc":"2.0","id":74,"error":{"code":-32000,"message":"missing trie node c91d4ecd59dce3067d340b3aadfc0542974b4fb4db98af39f980a91ea00db9dc (path ) state 0xc91d4ecd59dce3067d340b3aadfc0542974b4fb4db98af39f980a91ea00db9dc is not available, not found"}}
", error={"code":-32000}, requestBody="{"method":"eth_getStorageAt","params":["0xb2a5a8a976688097483a68cdd2f534c6bb0351ac","0x0000000000000000000000000000000000000000000000000000000000000000","0x1"],"id":74,"jsonrpc":"2.0"}", requestMethod="POST", url="https://go.getblock.io/ee42d0a88f314707be11dd799b122cb9", code=SERVER_ERROR, version=web/5.7.1)
You may want to cautiously increase the gas limit if the transaction went out of gas.
错误原因
这个错误和合约代码本身无关,是你使用的GetBlock RPC节点存在状态数据缺失。部署带初始化storage数组的合约时,Remix会在部署后自动调用eth_getStorageAt接口读取合约存储来验证部署结果,但该节点找不到对应的状态trie节点,导致验证失败。
解决办法
- 更换RPC节点:换成Remix内置的官方测试网节点(比如Sepolia),或者其他稳定的节点服务,避免使用同步不完整的节点。
- 跳过Remix的自动验证:使用MetaMask等钱包的Injected Provider部署合约,部署完成后手动在Remix中加载合约地址,跳过部署后的自动存储检查。
- 清理Remix缓存:刷新Remix页面,清空本地编译缓存,重新编译合约后再尝试部署。
- 检查节点同步状态:联系GetBlock客服确认节点是否完全同步,或者切换到该服务商的其他可用节点。
内容的提问来源于stack exchange,提问作者Caseythekiwi

