Skip to content

Instantly share code, notes, and snippets.

@iurimatias
Last active August 29, 2015 14:24
Show Gist options
  • Save iurimatias/b098589bbddf3d03ae56 to your computer and use it in GitHub Desktop.
Save iurimatias/b098589bbddf3d03ae56 to your computer and use it in GitHub Desktop.
// copy paste to nodejs
var web3 = require('web3');
web3.setProvider(new web3.providers.HttpProvider("http://localhost:8101"));
web3.eth.defaultAccount = web3.eth.accounts[0];
source = 'contract SimpleStorage {\n uint public foo;\n\n function SimpleStorage(uint y) {\n foo = y;\n }\n}\n'
compiled_contracts = web3.eth.compile.solidity(source)
contract = compiled_contracts.SimpleStorage
contractObject = web3.eth.contract(contract.info.abiDefinition)
contractObject.new(150, {from: web3.eth.defaultAccount, data: contract.code}, function(err, contract) {
if (err) {
console.log("error");
console.error(err);
return;
}
console.log("deployed at " + contract.address);
})
// wait for transaction to mine first before continuing!!
var SimpleStorageContract = web3.eth.contract(contract.info.abiDefinition);
var SimpleStorage = SimpleStorageContract.at(contractAddress);
console.log("value is " + SimpleStorage.foo() + " and it should be 150");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment