Skip to content

Commit e88b6a4

Browse files
authored
Merge pull request #2 from gelatodigital/feat/relayer/implementation
feat: relayer
2 parents c562589 + 1e73940 commit e88b6a4

28 files changed

Lines changed: 769 additions & 41 deletions

examples/bundler/sponsored/src/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,11 +46,11 @@ const main = async () => {
4646
]
4747
});
4848

49-
console.log('userOpHash:', hash);
49+
console.log(`hash: ${hash}`);
5050

5151
const { receipt } = await bundler.waitForUserOperationReceipt({ hash });
5252

53-
console.log('transaction hash:', receipt.transactionHash);
53+
console.log(`transaction hash ${receipt.transactionHash}`);
5454
process.exit(0);
5555
};
5656

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
GELATO_API_KEY="Get your api key at https://app.gelato.cloud/"
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
{
2+
"name": "relayer-sponsored-payment",
3+
"private": true,
4+
"version": "0.0.1",
5+
"scripts": {
6+
"dev": "tsx src/index.ts"
7+
},
8+
"dependencies": {
9+
"@gelatonetwork/ferry-sdk": "workspace:*",
10+
"viem": "catalog:"
11+
},
12+
"devDependencies": {
13+
"@types/node": "latest",
14+
"dotenv": "^17.2.3",
15+
"tsx": "^4.21.0",
16+
"typescript": "catalog:"
17+
}
18+
}
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
import {
2+
createGelatoEvmRelayerClient,
3+
type Status,
4+
StatusCode,
5+
sponsored
6+
} from '@gelatonetwork/ferry-sdk';
7+
import 'dotenv/config';
8+
import { baseSepolia } from 'viem/chains';
9+
10+
const GELATO_API_KEY = process.env['GELATO_API_KEY'];
11+
12+
if (!GELATO_API_KEY) {
13+
throw new Error('GELATO_API_KEY is not set');
14+
}
15+
16+
const main = async () => {
17+
const relayer = createGelatoEvmRelayerClient({ apiKey: GELATO_API_KEY, testnet: true });
18+
19+
const hash = await relayer.sendTransaction({
20+
chainId: baseSepolia.id,
21+
data: '0xd09de08a',
22+
payment: sponsored(),
23+
to: '0xE27C1359cf02B49acC6474311Bd79d1f10b1f8De'
24+
});
25+
26+
console.log(`hash: ${hash}`);
27+
28+
let status: Status;
29+
while (true) {
30+
status = await relayer.getStatus({ id: hash });
31+
32+
if (status.status !== StatusCode.Pending && status.status !== StatusCode.Submitted) {
33+
break;
34+
}
35+
}
36+
37+
if (status.status === StatusCode.Confirmed) {
38+
console.log(`transaction hash ${status.receipt.transactionHash}`);
39+
process.exit(0);
40+
} else {
41+
console.log(`transaction failed, message: ${status.message}, data: ${status.data}`);
42+
process.exit(1);
43+
}
44+
};
45+
46+
main().catch((error) => {
47+
console.error(error);
48+
process.exit(1);
49+
});
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"extends": "../../../tsconfig.json"
3+
}

package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,7 @@
2323
"@changesets/cli": "2.29.7",
2424
"@types/node": "latest",
2525
"lefthook": "2.0.2",
26-
"typescript": "catalog:",
27-
"viem": "catalog:"
26+
"typescript": "catalog:"
2827
},
2928
"engines": {
3029
"node": ">=23"

0 commit comments

Comments
 (0)