Created
November 14, 2017 12:21
-
-
Save makevoid/399b303e910d44deb71e6b50a81e24c4 to your computer and use it in GitHub Desktop.
Web3 Beta deploy code
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
#! /usr/bin/env node | |
const c = console | |
const Web3 = require('web3') | |
const {promisify} = require('util') | |
const web3 = new Web3('ws://localhost:8546') // ws are faster | |
// const web3 = new Web3('http://localhost:8545') // standard http json rpc | |
const eth = web3.eth | |
const interf = require("./build/contracts/contract-name-truffle-interface.json") | |
const main = async () => { | |
const accounts = await eth.getAccounts() | |
account = accounts[0] | |
c.log("Account:", account) | |
const balance = await eth.getBalance(account) | |
c.log("Balance:", balance) | |
c.log("Interface:", interf) | |
c.log(interf) | |
const abi = interf.abi | |
const bytecode = interf.bytecode | |
const address = interf.address // for existing contract | |
// existing contract: | |
// const MyContractClass = new eth.Contract(abi, address, { from: account }) // contract class | |
// new contract: | |
const MyContractClass = new eth.Contract(abi, { from: account, data: bytecode }) // contract class | |
// estimate gas not usually needed in private chain | |
// const MyCtrEstimateGas = promisify(MyContractClass.deploy().estimateGas) | |
const MyCtrDeploy = promisify(MyContractClass.deploy().send) | |
// const gasEst = await MyCtrEstimateGas() | |
// c.log("Gas estimation:", gasEst) // 1270000 | |
const deployment = await MyCtrDeploy({ | |
from: account, | |
// for private chain | |
// gas: 50....million, | |
// for public chain | |
// gas: 1270000, (from the estimation) | |
// gasPrice: '17000000000' (good currently) | |
}) | |
c.log(deployment) | |
} | |
main() | |
.catch((err) => { | |
c.error(err) | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment