微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

如何使用前端部署智能合约就像 REMIX IDE 正在做的那样

如何解决如何使用前端部署智能合约就像 REMIX IDE 正在做的那样

我只想知道是否有任何方法或机制可以像 REMIX IDE 那样通过单击来部署合约。我只想部署具有不同参数的新合约。我不想使用 truffle 或 REMIX 来部署我的合约,我只想要我自己的部署方法。 如果可能的话请让我知道。我只想知道其他人如何为每个新参数部署合约实例。 注意 参数表示构造函数中的值。 提前致谢

解决方法

myContract.deploy({
    data: '0x12345...',arguments: [123,'My String']
})
.send({
    from: '0x1234567890123456789012345678901234567891',gas: 1500000,gasPrice: '30000000000000'
},function(error,transactionHash){ ... })
.on('error',function(error){ ... })
.on('transactionHash',function(transactionHash){ ... })
.on('receipt',function(receipt){
   console.log(receipt.contractAddress) // contains the new contract address
})
.on('confirmation',function(confirmationNumber,receipt){ ... })
.then(function(newContractInstance){
    console.log(newContractInstance.options.address) // instance with the new contract address
});


// When the data is already set as an option to the contract itself
myContract.options.data = '0x12345...';

myContract.deploy({
    arguments: [123,gasPrice: '30000000000000'
})
.then(function(newContractInstance){
    console.log(newContractInstance.options.address) // instance with the new contract address
});


// Simply encoding
myContract.deploy({
    data: '0x12345...','My String']
})
.encodeABI();
> '0x12345...0000012345678765432'


// Gas estimation
myContract.deploy({
    data: '0x12345...','My String']
})
.estimateGas(function(err,gas){
    console.log(gas);
});

以下web3代码可用于现场部署合约

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。