常见EVM错误

2023-12-18 11:33:27 浏览数 (1)

Returned error: {"jsonrpc":"2.0","error":"[ethjs-query] while formatting outputs from RPC '{"value":{"code":-32603,"data":{"code":-32000,"message":"transaction underpriced"}}}'","id":4815365370376783}

gasprice定价过低,调高定价

Remix上合约调试时不能仅依赖事件是否发出为成功依据,而应该以状态变量为准,因为事件有可能不发!

部署时报错:code=CALL_EXCEPTION

检查gaslimit:5b8d80==6000000 ⇒contracts/src.ts/deploy.ts 6000000改8000000

Contract creation initialization returns data with length of more than 24576 bytes. The deployment will likely fail if the current network has activated the eip 170.

合约过大,需要拆分。参考另一篇《delegatecall》

ProviderError: sender doesn't have enough funds to send tx. The max upfront cost is: 4845817880859375 and the sender's account only has: 0

合约部署账户没有钱,打点原生币过去就行了

CompilerError: Stack too deep, try removing local variables.

变量声明太多了,可以用结构体封装一些,或者把部分代码挪出去变成函数

Error: Transaction reverted: function call to a non-contract account

接口正在尝试调用一个不存在的合约。检查合约确实是否存在,或者在合约中增加代码检查如果是合约地址就调用,否则就不调用。

Explicit type conversion not allowed from "address" to "uint256".solidity(9640)

在 Solidity 0.8.0 版本中,引入了一个更为安全的类型系统,不再允许直接将 address 类型转换为 uint256 类型。因此,你需要使用 type 关键字进行显式类型转换。

代码语言:javascript复制
uint256 size;
assembly {
    size := extcodesize(_addr)
}

Explicit type conversion not allowed from "bytes memory" to "address".solidity(9640)

代码语言:javascript复制
function bytesToAddress(bytes memory data) internal pure returns (address) {
    require(data.length == 20, "Invalid address length");
    address result;
    assembly {
        result := mload(add(data, 32))
    }
    return result;
}

abi: length larger than int64: 48129323291152180489044384789343333891201197466736324414383260238138438582324

合约有bug,检查是否修改了合约但忘记重新部署

ProviderError: replacement transaction underpriced

gasprice过低,hardhat可以设置如下代码修复:

代码语言:javascript复制
const contract = await Contract.deploy({
  gasPrice: ethers.parseUnits("25", "gwei"), // fuji中的 gas 价格最低是25 Gwei
});

0 人点赞