我正在学习如何使用solidity、和Javascript开发和部署。
我在Ganache.上成功地部署了一份合同现在,当我试图使用Rinkby Test Net在truffle-hdwallet-provider上部署它时,它就失败了。
我成功地使用web3创建了truffle-hdwallet-provider对象,我成功地获得了帐户列表,但是到testnet的部署总是失败的。
您可以在这里检查我的部署是否失败. https://rinkeby.etherscan.io/address/0x2f20b8F61813Df4e114D06123Db555325173F178
这是我的deploy script
const HDWalletProvider = require('truffle-hdwallet-provider');
const Web3 = require ('web3');
const {interface, bytecode} = require('./compile');
const provider = new HDWalletProvider(
'memonics', // this is correct
'https://rinkeby.infura.io/mylink' // this is correct
);
const web3 = new Web3(provider);
const deploy = async() =>{
const accounts = await web3.eth.getAccounts();
console.log('Attempting to deploy from account:', accounts[0]); //This excute fine
try {
const result = await new web3.eth.Contract(JSON.parse(interface)).deploy({ data: bytecode, arguments: ['Hi There!']}).send({ from: accounts[0], gas: '1000000'});
console.log('Contract deployed to ', result.options.address);
}
catch(err) {
console.log('ERROR'); // Here I get error
}
};
deploy();这是我的合同
pragma solidity ^0.4.17;
contract Inbox{
string public message;
constructor (string initialMessage) public {
message = initialMessage;
}
function setMessage(string newMessage) public {
message = newMessage;
}
}编辑:我试过使用Remix,它成功地部署了,但是当尝试使用时会产生错误:合同代码无法存储,请检查您的气体限制。I绑定了不同的气体值(最大可能),但仍然没有结果。
发布于 2018-06-20 17:45:42
我发现bytecode不包括导致这个问题的0x。
通过使用字节码来定义0x,解决了这个问题。
发布于 2018-09-18 11:03:13
我遇到了这个问题,并通过将扁平的代码粘贴到Remix中解决了这个问题,然后给出了更好的错误描述:我在契约中有一个接口没有正确实现(错误的函数签名)。检查您的接口实现。试图部署“抽象契约”会导致此错误。
发布于 2022-02-04 09:47:30
在字节码之前在deploy中使用这个deploy。
.deploy({ data:'0x0' + bytecode })
.send({ gas: "1000000", gasPrice: "5000000000", from: accounts[0] });https://stackoverflow.com/questions/50948757
复制相似问题