Rayls Docs

Deploying smart contracts

Overview

In the Rayls ecosystem, deploying smart contracts within a Privacy Ledger (PL) has different routes, such as using the Rayls Custody or Direct Contact Privacy Ledger. This guide outlines the available options and best practices for deploying contracts in the Rayls Privacy Ledger.


Deployment Options

Here are the different routes to deploy a smart contract within the Rayls Privacy Ledger:


Via Privacy Ledger

To deploy a smart contract using direct contact with the Rayls Privacy Ledger you will need to set up a JSON-RPC (JRPC) communication, following these steps:

Pre-requisites:

  • Access to Rayls Privacy Ledger: Ensure you are connected to the Privacy Ledger node through its RPC endpoint (e.g., <http://your-ledger-url:8545).>)
  • Compiled Smart Contract: Have your smart contract’s bytecode ready (compiled from Solidity via Remix, Truffle, etc.).
  • Authorized Account: Ensure you have access to your authorized account on the Rayls Privacy Ledger to deploy the contract.

Step-by-Step

1. Compile the Smart Contract:

Use Remix or Truffle to compile your smart contract written in Solidity. The output includes:

  • Bytecode: The compiled smart contract code in hexadecimal form (starts with 0x).
  • ABI (Application Binary Interface): Optional, for interacting with the contract post-deployment.

2. Prepare the Deployment Transaction:

Create the JSON-RPC request to deploy the smart contract on the Rayls Privacy Ledger.

Example JSON-RPC request:

{  
  "jsonrpc": "2.0",  
  "method": "eth_sendTransaction",  
  "params": [{  
    "from": "0xYourAccountAddress",  // The address deploying the contract  
    "data": "0xYourContractBytecode", // The compiled contract bytecode  
  }],  
  "id": 1  
}

3. Send the Deployment Transaction:

Send the deployment transaction using curl or any JSON-RPC client. Here’s an example using curl:

curl -X POST http\://your-ledger-url:8545  
-H "Content-Type: application/json"  
--data '{  
  "jsonrpc":"2.0",  
  "method":"eth_sendTransaction",  
  "params":[{  
    "from":"0xYourAccountAddress",  
    "data":"0xYourContractBytecode",  
  }],  
  "id":1  
}'

This will send the contract bytecode to the Rayls Privacy Ledger for deployment.


4. Monitor the Transaction:

After submitting the transaction, monitor its status to ensure the contract is successfully deployed. Use the transaction hash (txHash) returned from the previous step to track it. Monitoring can be done via JSON-RPC request or via your Privacy Ledger block explorer.

Example JSON-RPC request to get the transaction receipt:

{  
  "jsonrpc": "2.0",  
  "method": "eth_getTransactionReceipt",  
  "params": ["0xYourTransactionHash"],  
  "id": 1  
}

Use curl to send the request:

curl -X POST  
http\://your-ledger-url:8545  
-H "Content-Type: application/json"  
--data '{  
  "jsonrpc":"2.0",  
  "method":"eth_getTransactionReceipt",  
  "params":["0xYourTransactionHash"],  
  "id":1  
}'

In the response, look for the contractAddress field to confirm that the contract has been successfully deployed on the Privacy Ledger.


Via Rayls Custody

To deploy a smart contract using the Rayls Custody you will need to follow these steps:

Pre-requisites

  • Access to Rayls Custody API:
    • You need access to the Rayls Custody API endpoints. Ensure you are authorized and have proper credentials (API keys or tokens) to interact with the API endpoints for creating wallets, submitting transactions, and deploying smart contracts.
    • Authentication can be done using the POST /api/auth endpoint to generate the necessary tokens for further API calls​
  • Create a Wallet:
    • Before deploying the contract, you must create a secure wallet using the POST /api/wallet endpoint. This wallet will manage the cryptographic keys used to sign transactions. You’ll get a wallet_id that you will use in subsequent API calls.

Step-by-Step

1. Prepare the Smart Contract Bytecode:

Compile your smart contract using standard Ethereum tools (e.g., Remix or Truffle) to generate the bytecode.

2. Create a Transaction for Deployment:

Use the POST /api/transaction endpoint to submit the bytecode of the smart contract. This endpoint allows you to send transactions that include contract deployments or other actions, securely signed via the custody wallet.

Example payload might include:

{  
  "wallet_id": "your-wallet-id",   // ID of the wallet from which the transaction is sent  
  "to": null,                      // Set to null when deploying a contract  
  "data": "0xYourContractBytecode", // Compiled contract bytecode (starts with 0x)  
  "nonce": "your-nonce-value",      // Transaction nonce (optional if not managed by Rayls)  
}

Endpoint:

POST /api/transaction

3. Monitor the Transaction:

Use the GET /api/transaction/{hash} endpoint to monitor the transaction status and ensure that the contract has been successfully deployed. Once confirmed, retrieve the contract address to interact with it further.

Read more about it in the Custody documentation


Conclusion

Deploying smart contracts on a Rayls Privacy Ledger is straightforward, with the Rayls Custody and/or Direct Contact with Privacy Ledger (JSON-RPC requests) serving as the primary tools. Rayls also enables easy integration from third-party tools, such as digital assets platforms and tokenization platforms that can offer more flexibility for deploying use-case specific smart contracts.

By leveraging the appropriate tools, developers can efficiently deploy and manage contracts within the Privacy Ledger, ensuring they are fully integrated into the Rayls ecosystem.