Using Gelato Relay, we relay your user's transactions on-chain, enabling secure gasless transactions for an ultra smooth UX for your app. This allows for a variety of new web3 experiences, as the user can now pay by only signing a message, or their transaction costs can be sponsored by the developer. As long as the gas costs are covered in one of the multiple payment methods that Gelato supports, we handle the rest reliably, quickly and securely.
The Gelato Relay SDK provides developers with various methods to interact with Gelato's infrastructure. Below are four essential SDK methods:
This method executes a function on behalf of the user, allowing them to submit tasks without holding any ETH in their wallets. It utilizes the EIP-2771 standard for meta transactions, enabling gasless transactions for users, and leverages Gelato 1balance for payment.
Combining the features of callWithSyncFee
and EIP-2771 meta transactions, this method provides gasless transaction capabilities. The target contract assumes responsibility for transferring the fee to Gelato's fee collector during transaction execution.
Similar to sponsoredCallERC2771
, this method enables gasless transactions using a different approach, suitable for environments where you have your own authentication logic. Also making use of Gelato 1balance.
When using callWithSyncFee relay method the target contract assumes responsibility for transferring the fee to Gelato's fee collector during transaction execution.
Important
"@gelatonetwork/relay-sdk": "^5.5.0",
Please copy .env.example
to .env
and add the following variables:
- GELATO_RELAY_API_KEY
- PRIVATE_KEY
- ALCHEMY_ID
yarn testSponsoredCallERC2771
code can be found here and here the docs
yarn testSponsoredCall
code can be found here and here the docs
yarn testCallWithSyncFee
code can be found here and here the docs
yarn testCallWithSyncFeeERC2771
code can be found here and here the docs
yarn testConcurrentSponsoredCallERC2771
code can be found here and here the docs
yarn testSponsoredCallERC2771WithSignature
code can be found here and here the docs
yarn testSponsoredGetDataToSignERC2771
code can be found here and here the docs
yarn testCallWithSyncFeeERC2771WithSignature
code can be found here and here the docs
yarn testCallWithSyncFeeGetDataToSignERC2771
code can be found here and here the [docs]( and here the docs )
Docs can be found here
relay.onTaskStatusUpdate((taskStatus: TransactionStatusResponse) => {
console.log("Task status update", taskStatus);
fetchStatusSocket(taskStatus, setMessage, setLoading);
});
const relayStatusWs = new WebSocket("wss://api.gelato.digital/tasks/ws/status");
relayStatusWs.onopen = (event) => {
relayStatusWs.send(
JSON.stringify({
action: "subscribe" as string,
taskId: response.taskId,
}),
);
relayStatusWs.onmessage = (event) => {
fetchStatusSocket(JSON.parse(event.data).payload, setMessage, setLoading);
};
};
Docs can be found here
let status = await relay.getTaskStatus(taskIdToQuery);`
Docs can be found here
let details = {
txHash: status?.transactionHash || undefined,
chainId: status?.chainId?.toString() || undefined,
blockNumber: status?.blockNumber?.toString() || undefined,
executionDate: status?.executionDate || undefined,
creationnDate: status?.creationDate || undefined,
taskState: (status?.taskState as TaskState) || undefined,
};
let body = ``;
let header = ``;
let txHash = details.txHash;
switch (details.taskState!) {
case TaskState.WaitingForConfirmation:
header = `Transaction Relayed`;
body = `Waiting for Confirmation`;
break;
case TaskState.Pending:
header = `Transaction Relayed`;
body = `Pending Status`;
break;
case TaskState.CheckPending:
header = `Transaction Relayed`;
body = `Simulating Transaction`;
break;
case TaskState.ExecPending:
header = `Transaction Relayed`;
body = `Pending Execution`;
break;
case TaskState.ExecSuccess:
header = `Transaction Executed`;
body = `Waiting to refresh...`;
destroyFetchTask.next();
setTimeout(() => {
console.log("finish");
setLoading(false);
}, 2000);
break;
case TaskState.Cancelled:
header = `Canceled`;
body = `TxHash: ${details.txHash}`;
destroyFetchTask.next();
break;
case TaskState.ExecReverted:
header = `Reverted`;
body = `TxHash: ${details.txHash}`;
destroyFetchTask.next();
break;
case TaskState.NotFound:
header = `Not Found`;
body = `TxHash: ${details.txHash}`;
destroyFetchTask.next();
break;
case TaskState.Blacklisted:
header = `BlackListed`;
body = `TxHash: ${details.txHash}`;
destroyFetchTask.next();
break;
default:
break;
}
Contract Name | Blueberry GelatoScout Link |
---|---|
CounterFeeCollector | Link |
CounterFeeCollectorERC2771 | Link |
CounterRelayContext | Link |
CounterRelayContextERC2771 | Link |
OneBalanceCounterERC2771 | Link |
OneBalanceSimpleCounter | Link |