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
var abiDefinition = [{"constant":false,"inputs":[{"name":"nickname","type":"bytes32"}],"name":"setNickname","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[{"name":"","type":"address"}],"name":"nicknameOf","outputs":[{"name":"","type":"bytes32"}],"payable":false,"stateMutability":"view","type":"function"}]; | |
var CaptureTheEther = web3.eth.contract(abiDefinition); | |
// load from deployed contract. replace the address with yours | |
var cte = CaptureTheEther.at("0x71c46Ed333C35e4E6c62D32dc7C8F00D125b4fee"); | |
// call `setNickname` function | |
cte.setNickname("your name", console.log); |
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
// construct contract object with ABI | |
var abiDefinition = [{"constant":false,"inputs":[{"name":"n","type":"uint8"}],"name":"guess","outputs":[],"payable":true,"stateMutability":"payable","type":"function"},{"constant":true,"inputs":[],"name":"isComplete","outputs":[{"name":"","type":"bool"}],"payable":false,"stateMutability":"view","type":"function"},{"inputs":[],"payable":true,"stateMutability":"payable","type":"constructor"}]; | |
var GuessTheNumberChallenge = web3.eth.contract(abiDefinition); | |
// load from deployed contract. replace the address with yours | |
var challenge = GuessTheNumberChallenge.at("0xb13afE1D0195a5C7876eE3e297a06A50b6f847A8"); | |
// call `guess` function | |
challenge.guess(42, {value: web3.toWei(1, 'ether')}, console.log); |
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
var answerHash = '0xdb81b4d58595fbbbb592d3661a34cdca14d7ab379441400cbfa1b78bc447c365'; | |
// iterate through all possible uint8 | |
for (var i = 0; i < 2 ** 8; i++) { | |
var hex = i.toString(16); | |
var padUint8 = web3.padLeft(hex, 2); | |
var hash = web3.sha3(padUint8, {encoding: 'hex'}); | |
if (hash == answerHash) { | |
console.log(`Found: ${i}`); | |
break; |
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
// transaction hash of contract deploy | |
var txHash = '0x75acf5e313e2c06e84d9e2609297b6a6f959773e7a4380daa66cc39ba59d6104'; | |
// get transaction | |
web3.eth.getTransaction('0x75acf5e313e2c06e84d9e2609297b6a6f959773e7a4380daa66cc39ba59d6104', (err, tx) => { | |
console.log(tx); | |
var blockNumber = tx.blockNumber; | |
web3.eth.getBlock(blockNumber, (err, block) => { | |
console.log(block); | |
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
const GuessTheNewNumberChallenge = artifacts.require('GuessTheNewNumberChallenge'); | |
contract('GuessTheNewNumberChallenge', ([account]) => { | |
it('should be completed', async () => { | |
let challenge = await GuessTheNewNumberChallenge.new({value: web3.toWei(1, 'ether')}); | |
assert( | |
await challenge.isComplete() === true, | |
'Challenge has not been completed!' | |
); |
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
const GuessTheNewNumberChallenge = artifacts.require('GuessTheNewNumberChallenge'); | |
const GuessTheNewNumberSolver = artifacts.require('GuessTheNewNumberSolver'); | |
contract('GuessTheNewNumberSolver', ([account]) => { | |
it('should solve the challenge', async () => { | |
let challenge = await GuessTheNewNumberChallenge.new({value: web3.toWei(1, 'ether')}); | |
let solver = await GuessTheNewNumberSolver.new(); | |
assert( | |
await solver.isComplete(challenge.address) === true, |
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
const GuessTheNewNumberChallenge = artifacts.require('GuessTheNewNumberChallenge'); | |
const GuessTheNewNumberSolver = artifacts.require('GuessTheNewNumberSolver'); | |
contract('GuessTheNewNumberSolver', ([account]) => { | |
it('should solve the challenge', async () => { | |
let challenge = await GuessTheNewNumberChallenge.new({value: web3.toWei(1, 'ether')}); | |
let solver = await GuessTheNewNumberSolver.new(); | |
await solver.guess(challenge.address, {value: web3.toWei(1, 'ether')}); |
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
pragma solidity ^0.4.21; | |
import "./GuessTheNewNumberChallenge.sol"; | |
contract GuessTheNewNumberSolver { | |
address owner; | |
function GuessTheNewNumberSolver() public { | |
owner = msg.sender; | |
} |
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
const PredictTheFutureChallenge = artifacts.require('PredictTheFutureChallenge'); | |
const PredictTheFutureSolver = artifacts.require('PredictTheFutureSolver'); | |
contract('PredictTheFutureSolver', ([account]) => { | |
it('should solve the challenge', async () => { | |
let challenge = await PredictTheFutureChallenge.new({value: web3.toWei(1, 'ether')}); | |
let solver = await PredictTheFutureSolver.new(); | |
let guess = 0; | |
await solver.lockInGuess(challenge.address, guess, {value: web3.toWei(1, 'ether')}); |
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
pragma solidity ^0.4.21; | |
contract Miner { | |
uint public blockNumber; | |
uint public blocks; | |
function Miner() public { | |
reset(); | |
} |