Management API Reference

Smart wallets

Requesting signatures and 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, or wagmi.
  • for the embedded wallet specifically, create a transactionIntent from the server and signMessage it with the embedded signer (client).
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
  • params: any parameters to include with the request

Signatures#

The request method of the EIP-1193 provider can be used to request signatures. First, get the provider:

client.tsx
openfortConfig.ts

_10
import openfort from "./openfortConfig"
_10
// This example assumes you have already checked that Openfort 'embeddedState' is
_10
// `ready` and the user is `authenticated`
_10
const provider = openfort.getEthereumProvider();

Then use the provider's request method with eth_sign or related methods:


_10
const message = "Sign this message";
_10
const signature = await provider.request({
_10
method: 'personal_sign',
_10
params: [message, address]
_10
});

Popular web3 libraries provide convenient methods for requesting signatures:

LibraryMethod
EthersUse the signer's signMessage method
WagmiUse the useSignMessage hook
ViemUse the signMessage action

Transactions#

Get the provider and optionally configure gas policy to make a sponsored transaction:

client.tsx

_10
import openfort from "./openfortConfig"
_10
// This example assumes you have already checked that Openfort 'embeddedState' is
_10
// `ready` and the user is `authenticated`
_10
const provider = await openfort.getEthereumProvider({
_10
policy: 'pol_...',
_10
}

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.


_10
const transactionRequest = {
_10
to: '0xRecipientAddress',
_10
value: 100000,
_10
};
_10
const txHash = 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.

Popular web3 libraries provide methods for sending transactions:

LibraryMethod
EthersUse the signer's sendTransaction method.
WagmiUse the useSendTransaction hook.
ViemsendTransaction action

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:

  • to: the address of the smart contract to call
  • data: the encoded function call data
  • value: any value to send (for payable functions)

To prepare the calldata for a smart contract interaction, we recommend using viem's encodeFunctionData method, like so:


_10
import { encodeFunctionData } from 'viem';
_10
_10
_10
const data = encodeFunctionData({
_10
abi: contractAbi,
_10
functionName: 'methodName',
_10
args: [arg1, arg2]
_10
});

You can then send a transaction from the wallet as normal, and pass the calldata in the data field of the transaction request:


_10
const transactionRequest = {
_10
to: '0xTheContractAddress',
_10
data: data,
_10
value: 100000, // Only necessary for payable methods
_10
};
_10
const txHash = await provider.request({
_10
method: 'eth_sendTransaction',
_10
params: [transactionRequest]
_10
});

Batched transactions#

Smart wallets support sending a batch of transactions in a single, atomic submission to the network.

To send a batched transactions with a smart wallet, call the wallet_sendCalls method with a calls array the transactions to batch together.

As an example, you might batch together a transaction to approve a USDC spender and to transfer USDC like so:


_32
const transactionRequest = {
_32
to: '0xTheContractAddress',
_32
data: data,
_32
value: 100000, // Only necessary for payable methods
_32
};
_32
const txHash = await provider.request({
_32
method: 'wallet_sendCalls',
_32
params: [
_32
{
_32
calls: [
_32
// Approve transaction
_32
{
_32
to: USDC_ADDRESS,
_32
data: encodeFunctionData({
_32
abi: USDC_ABI,
_32
functionName: 'approve',
_32
args: ['insert-spender-address', BigInt(1e6)],
_32
}),
_32
},
_32
// Transfer transaction
_32
{
_32
to: USDC_ADDRESS,
_32
data: encodeFunctionData({
_32
abi: USDC_ABI,
_32
functionName: 'transfer',
_32
args: ['insert-recipient-address', BigInt(1e6)],
_32
}),
_32
},
_32
],
_32
},
_32
],
_32
});

Popular web3 libraries provide methods for sending batched transactions:

LibraryMethod
WagmiUse the useWriteContracts hook.
ViemsendCalls action

Examples#