This project showcases the implementation of the relay sdk v5 with front end (React) and back end (node) examples. The relay sdk implements ethers v6 that introduces some minor breaking changes when instantiating the providers and creating the payload data. Please refer to the ethers migration guide for further information
We are using React to showcase the relay-sdk integration
Please add the Gelat Relay sponsorsKey here
yarn start
The implementation code can be found here:
- sponsoredCallERC2771. Link to docs.
- sponsoredCall. Link to docs.
- callWithSyncFee. Link to docs.
- callWithSyncFeeERC2771. Link to docs.
Please copy .env.example
to .env
and add the GELATO_RELAY_API_KEY, PRIVATE_KEY and ROOTSTOCK_ID. Then you can run:
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;
}