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.
- Access to the Sovereign ledger: Ensure you are connected to the ledger node through its RPC endpoint (for example,
- 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/authendpoint, 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/walletendpoint. This wallet manages the cryptographic keys used to sign transactions, and returns awallet_idthat you will use in subsequent API calls.
- Before interacting with the contract, create a secure wallet using the
- Access to the Rayls Custody API:
Step-by-Step
Contract Address:
- Obtain the Contract Address and ABI
- To interact with a specific smart contract, you will need its address and ABI.
- In Remix, the ABI is available in the compiler output panel.
- In Truffle, after compiling, the ABI is stored in the
build/contracts/<ContractName>.jsonfile.
- Once the contract is deployed in your Sovereign ledger, you can retrieve the
contract addressfrom the transaction receipt, using a method such aseth_getTransactionReceipt.
- To interact with a specific smart contract, you will need its address and ABI.
- Choose a Method of Interaction
- 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.
- Execute the Transaction
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.
Updated 17 days ago
