Node.js 未处理的PromisejectionWarning:错误:合同代码无法';不能储存,请检查您的气体限值
我试图将我的simple solidity智能合约部署到Rinkeby网络上,但我不断收到错误: 未处理的PromisejectionWarning:错误:无法创建合同代码 已储存,请检查您的气体限值 我的代码很简单Node.js 未处理的PromisejectionWarning:错误:合同代码无法';不能储存,请检查您的气体限值,node.js,ethereum,solidity,smartcontracts,Node.js,Ethereum,Solidity,Smartcontracts,我试图将我的simple solidity智能合约部署到Rinkeby网络上,但我不断收到错误: 未处理的PromisejectionWarning:错误:无法创建合同代码 已储存,请检查您的气体限值 我的代码很简单 pragma solidity ^0.4.18; contract Greetings{ string public message; function Greetings(string initialMessage) public{ message =
pragma solidity ^0.4.18;
contract Greetings{
string public message;
function Greetings(string initialMessage) public{
message = initialMessage;
}
function setMessage(string newMessage) public {
message = newMessage;
}
}
我的部署脚本是:
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();
有趣的是,我过去能够成功部署,但当我创建了一个新项目并重新编写了相同的代码时,我现在遇到了这个错误。请帮忙 有完全相同的问题!这似乎是由“truffle hdwallet provider”版本0.0.5中的错误引起的。在我的课程中,它显然使用了“0.0.3” 如果你做到以下几点应该没问题,这对我很有效
npm uninstall truffle-hdwallet-provider
npm install --save truffle-hdwallet-provider@0.0.3
然后我运行了成功部署的同一个契约
祝你好运 我认为字节码被视为单个数字,而不是一系列字节。请尝试以下操作,而不是提交数据:字节码:
data:'0x0' + bytecode
它将字节码值作为字符串“保留”此问题可以通过添加“0x”作为字节码前缀来解决:
.deploy({ data: '0x' + bytecode, arguments: ['Hi there!'] })
更多信息请访问。此解决方案更有意义!这应该是公认的答案。谢谢你,我被困了一段时间了!这与字节码之前添加的“0x”一起解决了我遇到的同一个问题,我打算放弃我的课程。