Skip to content

Instantly share code, notes, and snippets.

@furusiyya
Created May 7, 2017 21:27
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save furusiyya/983fbd15f6ef61a9408c21e53a709e3e to your computer and use it in GitHub Desktop.
Save furusiyya/983fbd15f6ef61a9408c21e53a709e3e to your computer and use it in GitHub Desktop.
Created a custom token then transfer to other accounts
contractAddress = '0x18ed614ab06285ca9d294e96e5144eefe1160e6d'
Methods available in contract:
1 - balanceOf(account address)
2 - transfer(account address, amount)
In order to use json rpc we need to find the hash of the invoked method signature and encoded parameters
- Hash of method 1:
> gold.balanceOf.getData(eth.coinbase) //Return balance of contract base account
'0x70a08231000000000000000000000000e8a67c0b7e1bc9929dc5bc7aee4ff245745908c8'
- Hash of method 2:
> old.transfer.getData('0x86d6e0307825dea879bc9d605c0bb359b11715a7',10) // Transfer 10 ethers to '0x86d6e0307825dea879bc9d605c0bb359b11715a7'
'0xa9059cbb00000000000000000000000086d6e0307825dea879bc9d605c0bb359b11715a7000000000000000000000000000000000000000000000000000000000000000a'
So after finding hash I will just make json rpc calls, In first call I will find balance, in second call I will transfer
my custom tokens and in third call I will again find balance to make sure the transaction work successfully:
$ curl --data '{"jsonrpc":"2.0","method":"eth_call","params":[{"to":"0x18ed614ab06285ca9d294e96e5144eefe1160e6d","data": "0x70a08231000000000000000000000000e8a67c0b7e1bc9929dc5bc7aee4ff245745908c8"},"latest"],"id":1}' localhost:1113
{"jsonrpc":"2.0","id":1,"result":"0x00000000000000000000000000000000000000000000000000000000000003b6"} //Balance of base account
$ curl -X POST --data '{"jsonrpc":"2.0","method":"eth_sendTransaction","params":[{"from":"0xe8a67c0b7e1bc9929dc5bc7aee4ff245745908c8","to":"0x18ed614ab06285ca9d294e96e5144eefe1160e6d","data":"0xa9059cbb00000000000000000000000086d6e0307825dea879bc9d605c0bb359b11715a7000000000000000000000000000000000000000000000000000000000000000a"}],"id":1}' localhost:1113
{"jsonrpc":"2.0","id":1,"result":"0x37886c69333c9ff1730a68bf9b63678161fb42d7d541102d3b1409e89d722d19"}
$ curl --data '{"jsonrpc":"2.0","method":"eth_call","params":[{"to":"0x18ed614ab06285ca9d294e96e5144eefe1160e6d","data": "0x70a08231000000000000000000000000e8a67c0b7e1bc9929dc5bc7aee4ff245745908c8"},"latest"],"id":1}' localhost:1113
{"jsonrpc":"2.0","id":1,"result":"0x00000000000000000000000000000000000000000000000000000000000003ac"}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment