-
Notifications
You must be signed in to change notification settings - Fork 267
Deploying contracts using RPC calls
This document is intented to show how to publish RSK Smart contracts using RPC calls, if you'are looking for a more friendly way you may take a look at Truffle framework.
First we need to get a RPC client to gerenate messages and send them to the RSK Smart node, there are lots of them, in this case we will use Postman that is available for Linux, Windows and MacOS.
Once Postman is installed in your system we can start with the basics.
As we mentioned earlier RSK Smart is compatible with Ethereum protocol so, if you need a deeper information on the JSON RPC protocol you can find it here.
Open Postman and type "http://localhost:4444" this is the default RSK Smart local node port and in the body tab write. Set the HTTP method to POST
'{"jsonrpc":"2.0","method":"eth_coinbase","params":[],"id":64}'
We've created our first JSON RPC call, in this case we retrieved the coinbase, as you can see in the value of the "method" property. And that's it. This is how you can get the coinbase information from your RSK Smart local node.
We will need to have the code already compiled, there are many ways to do that:
- Use the browser compiler
- Use the command line compiler
After compile just copy the bytecodes (save the interface you will need it for reference on how to use the conract)
6060604052341561000c57fe5b5b6101598061001c6000396000f30060606040526000357c0100000000000000000000000000000000000000000000000000000000900463ffffffff168063cfae32171461003b575bfe5b341561004357fe5b61004b6100d4565b604051808060200182810382528381815181526020019150805190602001908083836000831461009a575b80518252602083111561009a57602082019150602081019050602083039250610076565b505050905090810190601f1680156100c65780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b6100dc610119565b604060405190810160405280600381526020017f486921000000000000000000000000000000000000000000000000000000000081525090505b90565b6020604051908101604052806000815250905600a165627a7a72305820ed71008611bb64338581c5758f96e31ac3b0c57e1d8de028b72f0b8173ff93a10029
To publish our contract we will use the eth_sendTransaction method
{
"jsonrpc" : "2.0",
"method" : "eth_sendTransaction",
"params" : [{
"from" : "0xcd2a3d9f938e13cd947ec05abc7fe734df8dd826",
"data" : "6060604052341561000c57fe5b5b6101598061001c6000396000f30060606040526000357c0100000000000000000000000000000000000000000000000000000000900463ffffffff168063cfae32171461003b575bfe5b341561004357fe5b61004b6100d4565b604051808060200182810382528381815181526020019150805190602001908083836000831461009a575b80518252602083111561009a57602082019150602081019050602083039250610076565b505050905090810190601f1680156100c65780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b6100dc610119565b604060405190810160405280600381526020017f486921000000000000000000000000000000000000000000000000000000000081525090505b90565b6020604051908101604052806000815250905600a165627a7a72305820ed71008611bb64338581c5758f96e31ac3b0c57e1d8de028b72f0b8173ff93a10029"
}
],
"id" : 1
}
And should be enought and the result will be something like this
{
"jsonrpc": "2.0",
"id": 1,
"result": "0x6755e3fa3a927b0b0c43764fc014334fd00cc121ec645566776ec2c8c2ae41c2"
}
This result is the contract address, you must use it to get the contract information
{
"jsonrpc" : "2.0",
"method" : "eth_getTransactionReceipt",
"params" : ["0x6755e3fa3a927b0b0c43764fc014334fd00cc121ec645566776ec2c8c2ae41c2"],
"id" : 1
}
Then it returns
{
"jsonrpc": "2.0",
"id": 1,
"result": {
"transactionHash": "0x6755e3fa3a927b0b0c43764fc014334fd00cc121ec645566776ec2c8c2ae41c2",
"transactionIndex": "0x0",
"blockHash": "0xc17d6960b338ef21be44d48208ead2f6d8e8a63d42c89ef61d28ddc4ee7c5d87",
"blockNumber": "0x897",
"cumulativeGasUsed": "0x015f90",
"gasUsed": "0x015f90",
"contractAddress": "0x73ec81da0c72dd112e06c09a6ec03b5544d26f05",
"logs": [],
"from": "0xcd2a3d9f938e13cd947ec05abc7fe734df8dd826",
"to": "0x00",
"root": "0x9182b4ffc855052ce52ad12d38eb2de42f068f3b6df9c218e7dba46fc404be21"
}
}````
From here we get the contract address, in this case *0x73ec81da0c72dd112e06c09a6ec03b5544d26f05*
Then we call the contract
````javascript
{
"jsonrpc" : "2.0",
"method" : "eth_call",
"params" : [{
"to" : "0x73ec81da0c72dd112e06c09a6ec03b5544d26f05",
"data" : "0xcfae321700000000000000000000000000000000000000000000000000000005"
}, "latest"],
"id" : 1
}