Skip to content

Instantly share code, notes, and snippets.

@mager
Created February 2, 2018 13:42
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 mager/7f0d9203013e323cd91f4fed1ed5e609 to your computer and use it in GitHub Desktop.
Save mager/7f0d9203013e323cd91f4fed1ed5e609 to your computer and use it in GitHub Desktop.
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