// 1. Request gasless action
const actionRequest = { ...params, gasless: true };
const actionResponse = await getAction(actionRequest);
// 2. Check execution type
if (actionResponse.execute.type === "GASLESS") {
const { execute } = actionResponse;
// 3. Sign approval if required
if (execute.approval) {
const { domain, types, message } = execute.approval.input;
execute.approval.output = await wallet.signTypedData(
domain,
types,
message
);
}
// 4. Sign main transaction
const { domain, types, message } = execute.tx.input;
execute.tx.output = await wallet.signTypedData(domain, types, message);
// 5. Submit for broadcast
const submitResponse = await fetch("/api/submit", {
method: "POST",
headers: {
"Content-Type": "application/json",
"x-api-key": YOUR_API_KEY,
},
body: JSON.stringify({
chainId: actionRequest.srcChainId,
approval: execute.approval,
tx: execute.tx,
}),
});
const { success, id } = await submitResponse.json();
console.log(`Transaction submitted: ${id}`);
}