Last active
March 27, 2018 14:26
-
-
Save Gim6626/4b9ea368f8a9120a6622e7026614495e to your computer and use it in GitHub Desktop.
This file contains hidden or 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
// Usage: nodejs deploy-ad-contract-test-5.js PATH_TO_COMPILED_JSON CONTRACT_CLASS_NAME TOKENS_PER_PLACEMENT TOKENS_PER_VIEW TOKEN_REWARD_ADDRESS CLIENT_ADDRESS BLOGGER_ADDRESS | |
// Requires running geth node, to launch it execute: geth console --rinkeby --rpc --rpcapi db,eth,net,web3,personal --cache=2048 --rpcport 8545 --rpcaddr 127.0.0.1 --rpccorsdomain "*" 2>> geth.log | |
// To compile ".sol" file to ".json", required for this file, do: solc SOURCE_SOL_FILE_PATH --combined-json abi,asm,ast,bin,bin-runtime,clone-bin,devdoc,interface,opcodes,srcmap,srcmap-runtime,userdoc > DESTINATION_JSON_FILE_PATH | |
let eth_secrets = require('./eth_secrets'); | |
let fs = require('fs'); | |
let Web3 = require('web3'); // Requires web3 0.* version, does not work with web3 1.* | |
let web3 = new Web3(); | |
web3.setProvider(new web3.providers.HttpProvider('http://localhost:8545')); | |
let source_path = process.argv[2]; | |
let source_filename = new String(source_path).substring(source_path.lastIndexOf('/') + 1); | |
let source = fs.readFileSync(source_path); | |
let contracts = JSON.parse(source)['contracts']; | |
contract_id = source_filename.replace('.json', '.sol') + ':' + process.argv[3]; | |
abi_str = contracts[contract_id]["abi"]; | |
let abi = JSON.parse(abi_str); | |
console.log('Contract ABI: ' + abi_str); | |
let code = '0x' + contracts[contract_id].bin; | |
let gasEstimate = Math.ceil(web3.eth.estimateGas({data: code}) * 1.1); | |
let Contract = web3.eth.contract(abi); | |
web3.personal.unlockAccount(web3.personal.listAccounts[0], eth_secrets.main_eth_account_passphrase); | |
tokens_per_placement = process.argv[4]; | |
tokens_per_view = process.argv[5]; | |
token_reward = process.argv[6]; | |
client = process.argv[7]; | |
blogger = process.argv[8]; | |
var contract = Contract.new(tokens_per_placement, tokens_per_view, token_reward, client, blogger, { | |
from: web3.personal.listAccounts[0], | |
data: code, | |
gas: gasEstimate | |
}, function(err, myContract){ | |
if(!err) { | |
if(!myContract.address) { | |
console.log('Transaction hash: ' + myContract.transactionHash); | |
} else { | |
console.log('Contract address: ' + myContract.address); | |
} | |
} else { | |
console.log(err); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment