UnhandledPromiseRejectionWarning:错误:无法存储合同代码,请检查您的气体限制

Jas*_*son 15 node.js ethereum solidity smartcontracts

我试图将我简单的可靠性智能合约部署到Rinkeby网络上,但我一直收到错误:

UnhandledPromiseRejectionWarning:错误:无法存储合同代码,请检查您的气体限制.

我的可靠性代码很简单

pragma solidity ^0.4.18; 

contract Greetings{ 
  string public message; 

  function Greetings(string initialMessage) public{ 
    message = initialMessage;
  }  

  function setMessage(string newMessage) public {
    message = newMessage;
  }  
}
Run Code Online (Sandbox Code Playgroud)

我的部署脚本是:

const HDWalletProvider = require('truffle-hdwallet-provider'); 
const Web3 = require('web3');
const { interface,bytecode} = require('./compile');

const provider = new HDWalletProvider(  
  'twelve word mnemonic...', 
  'https://rinkeby.infura.io/GLm6McXWuaih4gqq8nTY'    
);

const web3 = new Web3(provider);

const deploy = async () => {
    accounts = await web3.eth.getAccounts(); 

    console.log('attempting to deploy from account',accounts[0]);

    const result = await new web3.eth.Contract(JSON.parse(interface)) 
      .deploy({data:bytecode, arguments:['Hello World']})      
      .send({from: accounts[0], gas:'1000000'});                              

    console.log('Contract deployed to', result.options.address); 
};

deploy();
Run Code Online (Sandbox Code Playgroud)

有趣的是,我曾经能够成功部署,但是当我创建一个新项目并重新执行相同的代码时,我现在得到了这个错误.请帮忙!

小智 32

有完全相同的问题!似乎它是由"truffle-hdwallet-provider"版本0.0.5中的错误引起的.在udemy课程期间,显然使用"0.0.3".

如果你这样做应该没问题,它对我有用.

npm uninstall truffle-hdwallet-provider
npm install --save truffle-hdwallet-provider@0.0.3
Run Code Online (Sandbox Code Playgroud)

然后我运行了已成功部署的同一合同.

祝好运!


Huy*_* Vo 14

可以通过添加'0x'作为字节码的前缀来解决此问题:

.deploy({ data: '0x' + bytecode, arguments: ['Hi there!'] })
Run Code Online (Sandbox Code Playgroud)

更多信息请访问https://ethereum.stackexchange.com/a/47654.