Last active
May 9, 2018 12:41
-
-
Save l-margiela/0da37b5c2585445d571526db42110eb3 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
pragma solidity ^0.4.0; | |
contract C { | |
uint storedData; | |
function set(uint x) public { | |
storedData = x; | |
} | |
function get() public constant returns (uint) { | |
return storedData; | |
} | |
} |
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
const Web3 = require('web3') | |
let web3 = new Web3(new Web3.providers.HttpProvider('http://localhost:8545')) | |
const abi = [{"constant":false,"inputs":[{"name":"x","type":"uint256"}],"name":"set","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"get","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"}] | |
const bin = "0x608060405234801561001057600080fd5b5060df8061001f6000396000f3006080604052600436106049576000357c0100000000000000000000000000000000000000000000000000000000900463ffffffff16806360fe47b114604e5780636d4ce63c146078575b600080fd5b348015605957600080fd5b5060766004803603810190808035906020019092919050505060a0565b005b348015608357600080fd5b50608a60aa565b6040518082815260200191505060405180910390f35b8060008190555050565b600080549050905600a165627a7a7230582042e7b30d8687ff5ac86e18f73e5b5f9b86ecd49013798d1c754c537d6b26bf240029" | |
let contract = web3.eth.contract(abi) | |
let contractDeployed = contract.new({ from: web3.eth.coinbase, data: bin, gas: 2000000 }, (err, c) => { | |
if (err) { | |
console.error(err) | |
return | |
} | |
if(!c.address) { | |
return | |
} | |
console.log("address: " + c.address) | |
let instance = contract.at(c.address) | |
instance.set.call(10, (err, ok) => console.log('set', err, ok)) | |
instance.get.call((err, ok) => console.log('get', err, ok.toString())) /* (1) Here why 10 is not returned */ | |
}) |
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
yarn add [email protected] | |
ganache-cli & | |
node ./main.js |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment