Created
January 19, 2018 16:33
-
-
Save mcgingras/d588e5586efce08f369becf1755291e7 to your computer and use it in GitHub Desktop.
Web3 v1.0 + testrpc: deploying a contract
This file contains 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
const fs = require('fs'); | |
const solc = require('solc'); | |
const Web3 = require('web3'); | |
// make sure you have a testrpc instance running on port 8545 (default) | |
const web3 = new Web3(new Web3.providers.HttpProvider("http://localhost:8545")); | |
web3.eth.getAccounts() | |
.then((accounts) => { | |
const code = fs.readFileSync('/path-to-contract.sol').toString(); | |
const compiledCode = solc.compile(code); | |
const byteCode = compiledCode.contracts[':Contract-name'].bytecode; | |
const abiDefinition = JSON.parse(compiledCode.contracts[':Contract-name'].interface); | |
const Contract = new web3.eth.Contract(abiDefinition, | |
{data: byteCode, from: accounts[0], gas: 4700000} | |
); | |
let deployedContract = null; | |
Contract.deploy() | |
.send(function (error, transactionHash) { | |
console.log('transactionHash', transactionHash); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment