【问题标题】:How can I deploy smart contract with front-end . Like REMIX IDE is doing如何使用前端部署智能合约。就像 REMIX IDE 正在做的那样
【发布时间】:2021-09-10 18:51:25
【问题描述】:
我只是想知道是否有任何方法或机制可以像 REMIX IDE 那样一键部署合约。我只想部署具有不同参数的新合同。我不想使用 truffle 或 REMIX 来部署我的合约,我只想要我自己的部署方法。
如果可能的话请让我知道。我只想知道其他人如何为每个新参数部署合约实例。
注意 参数表示构造函数中的值。
提前致谢
【问题讨论】:
标签:
blockchain
ethereum
smartcontracts
remix
decentralized-applications
【解决方案1】:
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, 'My String']
})
.send({
from: '0x1234567890123456789012345678901234567891',
gas: 1500000,
gasPrice: '30000000000000'
})
.then(function(newContractInstance){
console.log(newContractInstance.options.address) // instance with the new contract address
});
// Simply encoding
myContract.deploy({
data: '0x12345...',
arguments: [123, 'My String']
})
.encodeABI();
> '0x12345...0000012345678765432'
// Gas estimation
myContract.deploy({
data: '0x12345...',
arguments: [123, 'My String']
})
.estimateGas(function(err, gas){
console.log(gas);
});
以下web3代码可用于现场部署合约