Skip to content

Instantly share code, notes, and snippets.

@gregorynicholas
Forked from ajb413/deploy.js
Created November 8, 2020 18:23
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 gregorynicholas/5ccfb969b74e163fdd2bc12cf5103849 to your computer and use it in GitHub Desktop.
Save gregorynicholas/5ccfb969b74e163fdd2bc12cf5103849 to your computer and use it in GitHub Desktop.
A Node.js script for deploying a smart contract to the locally hosted Ethereum instance.
const fs = require('fs');
const Web3 = require('web3');
const web3 = new Web3('http://localhost:8545');
const bytecode = fs.readFileSync('./build/FirstContract.bin');
const abi = JSON.parse(fs.readFileSync('./build/FirstContract.abi'));
(async function () {
const ganacheAccounts = await web3.eth.getAccounts();
const myWalletAddress = ganacheAccounts[0];
const myContract = new web3.eth.Contract(abi);
myContract.deploy({
data: bytecode.toString()
}).send({
from: myWalletAddress,
gas: 5000000
}).then((deployment) => {
console.log('FirstContract was successfully deployed!');
console.log('FirstContract can be interfaced with at this address:');
console.log(deployment.options.address);
}).catch((err) => {
console.error(err);
});
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment