Created
March 1, 2017 05:28
-
-
Save iisaint/ccd7f538eb63703579ff8455a33d355b to your computer and use it in GitHub Desktop.
Deploy a compiled smart contract
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
---- 前面省略 ---- | |
/* | |
* deploy contract | |
*/ | |
let gasEstimate = web3.eth.estimateGas({data: '0x' + bytecode}); | |
console.log('gasEstimate = ' + gasEstimate); | |
let MyContract = web3.eth.contract(abi); | |
console.log('deploying contract...'); | |
let myContractReturned = MyContract.new([], { | |
from: address, | |
data: '0x'+ bytecode, | |
gas: gasEstimate + 50000 | |
}, function (err, myContract) { | |
if (!err) { | |
// NOTE: The callback will fire twice! | |
// Once the contract has the transactionHash property set and once its deployed on an address. | |
// e.g. check tx hash on the first call (transaction send) | |
if (!myContract.address) { | |
console.log(`myContract.transactionHash = ${myContract.transactionHash}`); // The hash of the transaction, which deploys the contract | |
// check address on the second call (contract deployed) | |
} else { | |
console.log(`myContract.address = ${myContract.address}`); // the contract address | |
global.contractAddress = myContract.address; | |
} | |
// Note that the returned "myContractReturned" === "myContract", | |
// so the returned "myContractReturned" object will also get the address set. | |
} else { | |
console.log(err); | |
} | |
}); | |
(function wait () { | |
setTimeout(wait, 1000); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment