Created
February 2, 2018 13:42
-
-
Save mager/7f0d9203013e323cd91f4fed1ed5e609 to your computer and use it in GitHub Desktop.
Compile & deploy a BigGame 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 path = require('path'); | |
const fs = require('fs'); | |
const solc = require('solc'); | |
const source = fs.readFileSync(bigGamePath, 'utf8'); | |
const HDWalletProvider = require('truffle-hdwallet-provider'); | |
const Web3 = require('web3'); | |
const { MNEMONIC, INFURA_HOST } = process.env; | |
const provider = new HDWalletProvider(MNEMONIC, INFURA_HOST); | |
const web3 = new Web3(provider); | |
const bigGamePath = path.resolve( | |
__dirname, | |
'contracts', | |
'BigGame.sol', | |
); | |
const { interface, bytecode } = solc.compile(source, 1).contracts[':BigGame']; | |
const deploy = async () => { | |
const accounts = await web3.eth.getAccounts(); | |
console.log('Attempting to deploy from account', accounts[0]); | |
try { | |
const contract = await new web3.eth.Contract(JSON.parse(interface)) | |
.deploy({ data: bytecode }) | |
.send({ gas: '1200000', from: accounts[0] }); | |
console.log(interface); | |
console.log('Contract deployed to', contract.options.address); | |
} catch (error) { | |
console.error(error); | |
} | |
}; | |
deploy(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment