Skip to content

Instantly share code, notes, and snippets.

@mager mager/deploy.js
Created Feb 2, 2018

Embed
What would you like to do?
Compile & deploy a BigGame contract
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
You can’t perform that action at this time.