Interacting with smart contracts
Overview
Interacting with smart contracts involves performing various functions, such as transferring assets, triggering actions, or storing data. This document provides a high-level overview of how to interact with smart contracts and directs you to relevant third-party tools for 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 (e.g., transferring tokens)
- Listening to contract events
Pre-Requisites
- Deployed Smart Contract: Ensure your contract is deployed on the Rayls Privacy Ledger.
- Contract ABI and Address: Obtain the contract’s Application Binary Interface (ABI) and its deployed contract address.
Interacting with Smart Contracts
There are different routes, when attempting smart contract interaction, such as using the Rayls Custody Light or JSON-RPC requests. Follow the steps below for interacting with smart contract through your Rayls Privacy Ledger.
Pre-Requisites:
- RPC Connection with Privacy Ledger (JSON-RPC)
- 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, such as MetaMask or any other application that will allow you to manage your private keys and sign transactions.
- Access to Rayls Privacy Ledger: Ensure you are connected to the Privacy Ledger node through its RPC endpoint (e.g.,
- Rayls Custody
- 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 awallet_id
that you will use in subsequent API calls.
- Before deploying the contract, you must create a secure wallet using the
- Access to Rayls Custody API:
Step-by-Step
Contract Address:
- Obtain the Contract Address and ABI
- To interact with a specific smart contract, you'll need its address and ABI. For more information on how to obtain contract address and ABI.
- In Remix, the ABI will be available in the compiler output panel.
- In Truffle, after compiling, the ABI is stored in the
build/contracts/<ContractName>.json
file.
- Once the contract is deployed on your Rayls Privacy Ledger, you can retrieve the
contract address
from the transaction receipt, using a method likeeth_getTransactionReceipt
to retrieve the receipt.
- To interact with a specific smart contract, you'll need its address and ABI. For more information on how to obtain contract address and ABI.
- Choose a Method of Interaction
- Select which tool best fits your need from Rayls Custody to Remix, Truffle, and development libraries, such as Web3.js or Ethers.js to interact with smart contracts manually or programmatically.
- Select which tool best fits your need from Rayls Custody to Remix, Truffle, and development libraries, such as Web3.js or Ethers.js to interact with smart contracts manually or programmatically.
- Execute the Transaction
- When executing a state-changing function (e.g., transferring tokens), you'll need to send a signed transaction.
-
For more advanced smart contract interactions or development, consider exploring the following resources:
This guide is a starting point for interacting with smart contracts. For further customization, development, or integration with your applications, refer to the official documentation of the tools mentioned above.
Updated about 2 months ago