Skip to content

Instantly share code, notes, and snippets.

@mcgingras
Created January 19, 2018 16:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mcgingras/d588e5586efce08f369becf1755291e7 to your computer and use it in GitHub Desktop.
Save mcgingras/d588e5586efce08f369becf1755291e7 to your computer and use it in GitHub Desktop.
Web3 v1.0 + testrpc: deploying a contract
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