Signing the payload is the critical step. The API returns
payloadToSign, and you must sign it with the user’s wallet before calling /v1/execute.Documentation Index
Fetch the complete documentation index at: /llms.txt
Use this file to discover all available pages before exploring further.
Add gasless transactions to your app with Privy embedded wallets using the REST API
payloadToSign, and you must sign it with the user’s wallet before calling /v1/execute.import { useSignAuthorization, useWallets } from "@privy-io/react-auth";
const { signAuthorization } = useSignAuthorization();
const { wallets } = useWallets();
const embeddedWallet = wallets?.[0];
if (!embeddedWallet) throw new Error("No wallet found");
const ownerAddress = embeddedWallet.address;
let quoteResponse = await fetch("https://api.biconomy.io/v1/quote", {
method: "POST",
headers: {
"X-API-Key": "YOUR_API_KEY",
"Content-Type": "application/json",
},
body: JSON.stringify({
mode: "eoa-7702",
ownerAddress,
composeFlows: [...],
}),
});
if (quoteResponse.status === 412) {
const { authorizations } = await quoteResponse.json();
const signedAuths = await Promise.all(
authorizations.map(async (authItem) => {
const authorization = await signAuthorization({
contractAddress: authItem.address,
chainId: authItem.chainId,
nonce: authItem.nonce,
});
return {
...authorization,
yParity: authorization.yParity,
v: authorization.v?.toString(),
};
})
);
quoteResponse = await fetch("https://api.biconomy.io/v1/quote", {
method: "POST",
headers: {
"X-API-Key": "YOUR_API_KEY",
"Content-Type": "application/json",
},
body: JSON.stringify({
mode: "eoa-7702",
ownerAddress,
composeFlows: [...],
authorizations: signedAuths,
}),
});
}
const quote = await quoteResponse.json();
const payload = quote.payloadToSign[0];
const signablePayload = payload.signablePayload ?? payload;
// eoa-7702 returns "simple" payloads (personal message)
const signature = await embeddedWallet.signMessage({
message: signablePayload.message,
});
await fetch("https://api.biconomy.io/v1/execute", {
method: "POST",
headers: {
"X-API-Key": "YOUR_API_KEY",
"Content-Type": "application/json",
},
body: JSON.stringify({
...quote,
payloadToSign: [{ ...payload, signature }],
}),
});