Send Transactions
To request signatures or transactions from a connected wallet, you can either:
- use the wallet's EIP-1193 provider to send JSON-RPC requests to the wallet directly.
- pass the wallet to a library like
viem
,ethers
, orwagmi
. - for the embedded wallet specifically, create a
transactionIntent
from the backend andsignMessage
it with the embedded signer.
The guide below explains how to request signatures and transactions via the EIP-1193 provider directly.
The request method#
At a high-level, the EIP-1193 provider implements a method called request
that accepts an object with the following fields:
- method: the name of a JSON-RPC request to send to the wallet (e.g.
personal_sign
) - params: any parameters to include with the request
You can use the
request
method to interface with the wallet per the instructions below. Get EIP-1193 provider via its getEthereumProvider method:
Gas sponsorship#
Simply add a policy to the provider object to sponsor the gas for the transaction. Learn more about gas sponsorship in the sponsorship guide.
Transactions#
Then, using the provider's request
method, send a eth_sendTransaction
JSON-RPC to the wallet. In the params
array, include as the first entry an object containing the transaction's parameters, such as to, value, data, gasLimit, maxPriorityFeePerGas, maxFeePerGas, and gasPrice.
_10const transactionRequest = {_10 to: '0xTheRecipientAddress',_10 value: 100000,_10};_10const transactionHash = await provider.request({_10 method: 'eth_sendTransaction',_10 params: [transactionRequest],_10});
See these docs for the parameters that can be passed in eth_sendTransaction
.
You do not need to specify from as we populate it from the user's connected wallet, and you can pass either a number, bigint, or a hexadecimal string into the value parameter.
If you've integrated Openfort with another web3 library, you can also use that library's syntax for requesting a transaction from the client-side:
Library | Method |
---|---|
Ethers | Use the signer's sendTransaction method. |
Wagmi | Use the useSendTransaction hook. |
Smart contracts#
Calling a smart contract is a special case of sending a transaction. To call a smart contract, you should send a transaction with the following parameters in the transaction request:
- to: the address of the smart contract to call
- data: any calldata to pass as part of the smart contract call
- value: any value to send from the user's wallet to the smart contract To prepare the calldata for a smart contract interaction, we recommend using viem's encodeFunctionData method, like so:
_10import {encodeFunctionData} from 'viem';_10..._10const data = encodeFunctionData({_10 abi: insertYourContractAbiAsJson_10 functionName: 'insertTheNameOfTheMethodToCall'_10})
You can then send a transaction from the wallet as normal, and pass the calldata in the data field of the transaction request:
_10const transactionRequest = {_10 to: '0xTheContractAddress',_10 data: data,_10 value: 100000, // Only necessary for payable methods_10};_10const transactionHash = await provider.request({_10 method: 'eth_sendTransaction',_10 params: [transactionRequest],_10});