forked from gelatodigital/relay-examples-frontend-backend-v5
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtestCallWithSyncFeeERC2771WithSignature.ts
63 lines (44 loc) · 1.88 KB
/
testCallWithSyncFeeERC2771WithSignature.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
import {
CallWithSyncFeeERC2771Request,
CallWithSyncFeeRequest,
ERC2771Type,
GelatoRelay,
SponsoredCallRequest,
} from "@gelatonetwork/relay-sdk";
import { ethers } from "ethers";
import * as dotenv from "dotenv";
dotenv.config({ path: ".env" });
const ROOTSTOCK_ID = process.env.ROOTSTOCK_ID;
const GELATO_RELAY_API_KEY = process.env.GELATO_RELAY_API_KEY;
const RPC_URL = `https://rpc.mainnet.rootstock.io/${ROOTSTOCK_ID}`;
const provider = new ethers.JsonRpcProvider(RPC_URL);
const signer = new ethers.Wallet(process.env.PRIVATE_KEY as string, provider);
const relay = new GelatoRelay();
const testCallWithSyncFeeERC2771WithSignature = async () => {
const counter = "0x5dD1100f23278e0e27972eacb4F1B81D97D071B7";
const abi = ["function increment()"];
// const provider = new ethers.providers.Web3Provider(window.ethereum);
// const signer = provider.getSigner();
const user = await signer.getAddress();
const chainId = (await provider.getNetwork()).chainId;
// Generate the target payload
const contract = new ethers.Contract(counter, abi, signer);
const { data } = await contract.increment.populateTransaction();
// address of the token to pay fees
const feeToken = "0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE";
// populate the relay SDK request body
const request: CallWithSyncFeeERC2771Request = {
chainId,
target: counter,
data: data,
user: user,
feeToken: feeToken,
isRelayContext: true,
};
// sign the Payload and get struct and signature
const { struct, signature} = await relay.getSignatureDataERC2771(request,signer,ERC2771Type.CallWithSyncFee)
// send the request with signature
const response = await relay.callWithSyncFeeERC2771WithSignature(struct,{feeToken,isRelayContext:true},signature)
console.log(`https://relay.gelato.digital/tasks/status/${response.taskId}`);
};
testCallWithSyncFeeERC2771WithSignature();