Sending RPC Requests
Last updated
Was this helpful?
Last updated
Was this helpful?
Communication with the wallet is sent via RPC requests. This guide will show you how to send an RPC request and how to interpret responses.
Obtain a chain provider
With the steps mentioned in , get a chain provider for the networks you want to interact with. In the following examples we will use both ethereum and constellation providers.
For listing the active accounts in the wallet you can send the following calls to RPC method and RPC method.
Read more about and .
TypeScript
TypeScript
For interaction with ethereum smart contracts you can use the RPC method and the RPC method, respectively for read and write operations. In the following example we will be using the package, and a from the . The package will help us encode method parameters based on the contract's ABI. It is encouraged to use external libraries to encode contract call parameters.
Interaction with smart contracts is done through an ABI (Application Binary Interface), you can read more about it in the article from the .
In the next example we will use the greet
method from the contract. It reads a greet string saved in the network state. For interacting with the contract we will create an ethers instance, and therefore an ethers . In the background the package will call for us.
In the next example we will use the setGreeting
method from the contract. It sets a greet string in the network state. For interacting with the contract we will create an ethers instance, and therefore an ethers . In the background the package will call for us.
Write calls need to be confirmed by the user. Read more .
As the ethereum chain reveals the RPC method you can send any kind of transaction you need (Token Transfer, Contract Interaction, ETH Transfers, etc.).
You can send ERC20 tokens using the transfer
method from any ERC20 contract. For interacting with the contract we will create an ethers instance, and therefore an ethers . In the background the package will call for us.
You can approve spend of ERC20 tokens to external contracts using the approve
method from any ERC20 contract. For interacting with the contract we will create an ethers instance, and therefore an ethers . In the background the package will call for us.
You can send ETH (The ethereum's native currency) sending a simple transaction to the network. For interacting with the network we will create an ethers and an ethers . In the background the package will call for us.