Created
May 18, 2016 18:57
-
-
Save ismaelbej/2d9ca7ad0ec3dff61a235fb53df43b1f to your computer and use it in GitHub Desktop.
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 Web3 = require("web3"); | |
var web3 = new Web3(new Web3.providers.HttpProvider("http://localhost:6020")); | |
var fs = require('fs'); | |
var test_code = fs.readFileSync('test.bin').toString(); | |
var test_abi = JSON.parse(fs.readFileSync('./test.abi').toString()); | |
var test_contract = web3.eth.contract(test_abi); | |
var test = test_contract.new({from: web3.eth.accounts[0], | |
data: test_code, | |
gas: 3000000}, | |
function (err, contract) { | |
if (err) { | |
console.log("Failed: ", err); | |
} else { | |
if (!contract.address) { | |
console.log("Transaction send: hash: ", contract.transactionHash); | |
} else { | |
console.log("Contract mined: address: ", contract.address); | |
} | |
} | |
}); | |
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 Web3 = require("web3"); | |
var web3 = new Web3(new Web3.providers.HttpProvider("http://localhost:6020")); | |
var fs = require('fs'); | |
var test_address = "0xddae573941cae8b9e95e7a5a54d2d6f1dc52203c"; | |
var test_abi = JSON.parse(fs.readFileSync('./test.abi').toString()); | |
var test_contract = web3.eth.contract(test_abi); | |
var test = test_contract.at(test_address); | |
var result = test.store.call(1); | |
console.log("result: ", result); | |
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
contract test { | |
struct ids { | |
bool used; | |
string data1; | |
string data2; | |
string data3; | |
} | |
mapping(uint => ids) public store; | |
function write(uint id, string data1, string data2, string data3) public { | |
store[id].used = true; | |
store[id].data1 = data1; | |
store[id].data2 = data2; | |
store[id].data3 = data3; | |
} | |
function read(uint id) public returns (string, string, string) { | |
return (store[id].data1, store[id].data2, store[id].data3); | |
} | |
} | |
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 Web3 = require("web3"); | |
var web3 = new Web3(new Web3.providers.HttpProvider("http://localhost:6020")); | |
var fs = require('fs'); | |
var test_address = "0xddae573941cae8b9e95e7a5a54d2d6f1dc52203c"; | |
var test_abi = JSON.parse(fs.readFileSync('./test.abi').toString()); | |
var test_contract = web3.eth.contract(test_abi); | |
var test = test_contract.at(test_address); | |
var txhash = test.write.sendTransaction(1, "marco", "polo", "extra", {from:web3.eth.accounts[0]}); | |
console.log("txhash: ", txhash); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment