Skip to content

Instantly share code, notes, and snippets.

@s-tajima

s-tajima/call.js Secret

Created November 4, 2018 11:56
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 s-tajima/970901318960c038291ff90f4404fe35 to your computer and use it in GitHub Desktop.
Save s-tajima/970901318960c038291ff90f4404fe35 to your computer and use it in GitHub Desktop.
CODE BLUE 2018 Smart Contract Hacking Challenge Write Up
const fs = require('fs');
const Web3 = require('web3');
const web3 = new Web3("__ETHEREUM_NODE__")
var abi = fs.readFileSync('./contract.abi.json', 'utf8');
var account = web3.eth.accounts.privateKeyToAccount(__PRIVATE_KEY__);
web3.eth.accounts.wallet.add(account);
web3.eth.defaultAccount = account.address;
var contract = new web3.eth.Contract(JSON.parse(abi), "0x64ba926175Bc69bA757eF53A6D5EF616889C9999");
var value = web3.utils.toWei('0.001', 'ether')
var gas = 200000
var guess = 4
contract.methods.do_guess(guess).send({from: account.address, value: value, gas: gas})
.on('transactionHash', function(hash){
console.log("transaction hash: ", hash);
})
.on('receipt', function(receipt){
console.log("receipt: ", receipt);
})
.on('confirmation', function(confirmationNumber, receipt){
console.log("confirmationNumber: ", confirmationNumber);
})
.on('error', console.error);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment