module.paths.push('/usr/lib/node_modules');
var fs = require('fs');
const contract_data = JSON.parse(
fs.readFileSync('path to your JSON file')
);
var openKey = "open Key (address)";
var privateKey = "privateKey";
var Web3 = require('web3');
var web3 = new Web3(new Web3.providers.HttpProvider("https://ropsten.infura.io/ "));
web3.eth.accounts.wallet.add("0x" + privateKey);
var contract = new web3.eth.Contract(contract_data.abi);
contract.deploy({
data: contract_data.unlinked_binary,
arguments: []
}).send({
from: openKey,
gas: 1500000,
gasPrice: '80000000'
}, function (error, transactionHash) {
}).on('error', function (error) {
console.log('error', error);
}).on('transactionHash', function (transactionHash) {
console.log('transactionHash', transactionHash);
}).on('receipt', function (receipt) {
console.log('receipt', receipt.contractAddress);
}).on('confirmation', function (confirmationNumber, receipt) {
console.log('confirmation', confirmationNumber);
});
Deploy An Ethereum Contract Programmatically
猜你喜欢
转载自my.oschina.net/swingcoder/blog/1822892
今日推荐
周排行