Last active
May 17, 2016 01:31
-
-
Save 6londe/59501d2076c512b802f25a8a6d2d261c to your computer and use it in GitHub Desktop.
ethereum contract example in java
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
IP = "10.113.63.183"; | |
ETHEREUM_ACCOUNT_NUMBER = 0; | |
/* static contract info */ | |
CONTRACT_ADDRESS = '0x1d4B7B3386AD2f221C641f6EED3bb7D3f6d8eDCB'; | |
CONTRACT_ABI = JSON.parse('[{"constant":false,"inputs":[],"name":"kill","outputs":[],"type":"function"},{"constant":false,"inputs":[],"name":"changeMsg","outputs":[],"type":"function"},{"constant":true,"inputs":[],"name":"greet","outputs":[{"name":"","type":"string"}],"type":"function"},{"inputs":[{"name":"_greeting","type":"string"}],"type":"constructor"}]'); | |
$(document).ready(function () { | |
if (typeof web3 === 'undefined') { | |
web3 = new Web3(new Web3.providers.HttpProvider('http://' + IP + ':8545')); | |
} | |
if (web3.isConnected()) { | |
console.log( | |
'Connected to Ethereum' | |
+ '\nEthereum js api version: ' + web3.version.api | |
+ '\nClient/node version: ' + web3.version.node | |
+ '\nNetwork protocol version: ' + web3.version.network | |
+ '\nEthereum protocol version: ' + web3.version.ethereum | |
+ '\nAccount: ' + web3.eth.accounts[ETHEREUM_ACCOUNT_NUMBER] | |
+ '\nBalance: ' + (web3.toWei(web3.eth.accounts[ETHEREUM_ACCOUNT_NUMBER], "ether") / web3.toWei(1, 'ether') + ' ether') | |
); | |
} | |
contract = web3.eth.contract(CONTRACT_ABI); | |
contractInstance = contract.at(CONTRACT_ADDRESS); | |
console.log(contractInstance.greet()); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment