Interacting with smart contracts

Overview

Interacting with smart contracts covers a range of functions, including transferring assets, triggering actions and storing data. This page gives a high-level view of how to interact with smart contracts and points to the third-party tools that handle more advanced interactions.

In Rayls, interactions can be triggered manually by users or automatically by other contracts, depending on the setup. Common interactions include:

  • Querying data from the contract (read-only)
  • Executing state-changing functions, such as transferring tokens
  • Listening to contract events

Pre-Requisites

  • Deployed Smart Contract: Ensure your contract is deployed in the Sovereign ledger.
  • Contract ABI and Address: Obtain the contract's Application Binary Interface (ABI) and its deployed contract address.

Interacting with Smart Contracts

There are several routes to smart contract interaction, including Rayls Custody Light and JSON-RPC requests. Follow the steps below to interact with a smart contract through your Sovereign ledger.

Pre-Requisites:

  • RPC connection with the Sovereign ledger (JSON-RPC)
    • Access to the Sovereign ledger: Ensure you are connected to the ledger node through its RPC endpoint (for example, http://your-ledger-url:8545).
    • Compiled Smart Contract: Have your smart contract's bytecode ready, compiled from Solidity via Remix, Truffle or a comparable tool.
    • Authorised Account: Ensure you have access to your authorised account on the Sovereign ledger, through MetaMask or any other application that lets you manage your private keys and sign transactions.
  • Rayls Custody
    • Access to the Rayls Custody API:
      • You need access to the Rayls Custody API endpoints. Ensure you are authorised and hold the credentials (API keys or tokens) needed to interact with the API endpoints for creating wallets, submitting transactions, and deploying smart contracts.
      • Authentication is handled through the POST /api/auth endpoint, which generates the tokens required for further API calls.
    • Create a Wallet:
      • Before interacting with the contract, create a secure wallet using the POST /api/wallet endpoint. This wallet manages the cryptographic keys used to sign transactions, and returns a wallet_id that you will use in subsequent API calls.

Step-by-Step

Contract Address:

  1. Obtain the Contract Address and ABI
    1. To interact with a specific smart contract, you will need its address and ABI.
      1. In Remix, the ABI is available in the compiler output panel.
      2. In Truffle, after compiling, the ABI is stored in the build/contracts/<ContractName>.json file.
    2. Once the contract is deployed in your Sovereign ledger, you can retrieve the contract address from the transaction receipt, using a method such as eth_getTransactionReceipt.
  2. Choose a Method of Interaction
    1. Select the tool that best fits your need, from Rayls Custody to Remix, Truffle, and development libraries such as Web3.js or Ethers.js, depending on whether you are interacting manually or programmatically.
  3. Execute the Transaction
    1. When executing a state-changing function, such as transferring tokens, you will need to send a signed transaction.
    2. For more advanced smart contract interactions or development, see the following resources:
      1. Web3.js
      2. Ethers.js

This page is a starting point for interacting with smart contracts. For further customisation, development, or integration with your applications, refer to the official documentation of the tools listed above.


Did this page help you?