Search code examples
rpctrufflersk

How can I deploy a smart contract to RSK without using Truffle?


After compiling a Solidity file using solc, how can I deploy the output bytecode as a smart contract to RSK? I know how to do this using Truffle already, but what alternatives are there available for this task?


Solution

  • RSK is (mostly) compatible with Ethereum. In particular, for dev tools, it has JSON-RPC compatibility plus VM compatibility. So if you are a Ethereum developer, you can use tools/ libs that you are familiar with. Here are several methods, apart from Truffle:

    If you want to do this manually, you can do so using the terminal by sending a transaction using curl via JSON-RPC like this:

    curl \
      -X POST \
      -H "Content-Type:application/json" \
      --data '{"jsonrpc":"2.0","method":"eth_sendTransaction","params":[{"from":"FROM_ADDRESS","to":"0x00","gasPrice":"0x3938700","gas":"0x67C28", "data":"SIGNED_CONTRACT_DEPLOYMENT_BYTECODE"}],"id":1}' \
      http://localhost:4444
    
    • Use the eth_estimateGas RPC to obtain the value of gas.
    • Use the eth_gasPrice RPC to obtain the value of gasPrice.

    Note that the above command assumes that you have RSKj running on localhost.

    Also note that just like any other transaction which modifies the state of the blockchain, you will need to sign the deployment transaction as well, in order to produce SIGNED_CONTRACT_DEPLOYMENT_BYTECODE. You can use the eth_sign RPC for this, or the equivalent method in your wallet.