Skip to content

Instantly share code, notes, and snippets.

@NathanMaton
Last active December 7, 2017 22:02
Show Gist options
  • Save NathanMaton/c4b435d1381f196ed4d89a7240874b9a to your computer and use it in GitHub Desktop.
Save NathanMaton/c4b435d1381f196ed4d89a7240874b9a to your computer and use it in GitHub Desktop.
// package.json
{
"dependencies": {
"web3": "0.17.0-alpha",
"solc": "^0.4.4"
}
}
// HelloWorld.sol
contract HelloWorld {
function displayMessage() constant returns (string) {
return "Hello from a smart contract";
}
}
var source = `contract HelloWorld {
function displayMessage() constant returns (string) {
return "Hello from a smart contract";
}
}
`
var compiled = solc.compile(source)
var bytecode = compiled.contracts[":HelloWorld"].bytecode
//making a contract and deploying it on a test net.
compiled.contracts[":HelloWorld"].interface
//save public interface of contract
var abi = JSON.parse(compiled.contracts[":HelloWorld"].interface)
//create var with contract
var hwContract = web3.eth.contract(abi)
//deploy contract
var deployed = hwContract.new({
from: web3.eth.accounts[0],
data: compiled.contracts[":HelloWorld"].bytecode,
gas: 4700000,
gasPrice: 5,
}, (error, contract) => {})
//check transaction by hash
web3.eth.getTransaction("0xf59c7b48ba0f4c7dac40f6c2f54b88d4662cd4205eb626ce73ebe9bc5821f4a0")
hwContract.at(_)
//use deployed contract
deployed.displayMessage.call()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment