Last active
August 24, 2022 03:15
-
-
Save ajb413/eb27d18ecac0842a60d884ed1b72761b to your computer and use it in GitHub Desktop.
A Node.js script for deploying a smart contract to the locally hosted Ethereum instance.
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 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