You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

部署Solidity合约至Rinkeby网络时遭遇合约代码存储失败错误

Fixing "Contract Code Couldn't Be Stored" Error on Rinkeby Deployment

Hey Jason, let's walk through how to get your Greetings contract deployed to Rinkeby without that frustrating gas limit error. I've seen this issue pop up a bunch, and it usually comes down to one of these straightforward fixes:

1. Manually Set a Higher Gas Limit

The most common culprit here is auto-calculated gas being too low—string operations (like your contract's message storage) can use more gas than simple value types, and the automatic estimator sometimes misses that.

Add an explicit gasLimit parameter when deploying your contract in the script. A value between 300,000 and 500,000 will be more than enough for your simple contract. Here's how that might look in your code:

// Adjust this snippet to match your deployment script's structure
const Greetings = await ethers.getContractFactory("Greetings");
const greetingContract = await Greetings.deploy("Hello from Rinkeby!", {
  gasLimit: 500000
});
await greetingContract.deployed();

Don't stress about wasting test ETH—you only pay for the actual gas used, not the full limit you set.

2. Match Your Compiler Version to the Contract

Your contract uses pragma solidity ^0.4.18, so make sure your deployment tool (Hardhat, Truffle, etc.) is using the exact same Solidity version. Mismatched compilers can generate wonky bytecode that throws off gas estimates.

  • For Hardhat, update your hardhat.config.js:
    module.exports = {
      solidity: "0.4.18",
      // ... other config settings
    };
    
  • For Truffle, update truffle-config.js:
    module.exports = {
      compilers: {
        solc: {
          version: "0.4.18", // Exact match to your contract's pragma
        }
      },
      // ... other config settings
    };
    

3. Confirm You Have Enough Rinkeby ETH

Even though the error calls out gas limit, it's worth checking that your deployment account has enough testnet ETH. The total deployment cost is gasUsed * gasPrice, so a low balance can cause failures that look like gas limit issues. Grab some test ETH from a Rinkeby faucet if you're running low.

4. Double-Check Your Constructor Parameter

Your contract requires an initialMessage string in the constructor. Make sure your deployment script is passing this parameter correctly—missing or malformed arguments can cause deployment failures that manifest as gas-related errors.

Start with the manual gas limit fix first—it's the quickest win for most cases. If that doesn't work, move on to verifying the compiler version and your ETH balance.

内容的提问来源于stack exchange,提问作者Jason

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.27 03:39:10