Skip to content

Commit 8b9716d

Browse files
feat: biconomy example (#154)
1 parent 0ddd228 commit 8b9716d

File tree

7 files changed

+209
-40
lines changed

7 files changed

+209
-40
lines changed

.changeset/config.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
"viem-adapter",
2727
"light-account-sponsored-payment",
2828
"simple-account-sponsored-payment",
29+
"biconomy-sponsored-payment",
2930
"nonces-example",
3031
"session-key"
3132
],
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
GELATO_API_KEY="Get your api key at https://app.gelato.cloud/"
2+
PRIVATE_KEY="0x<PRIVATE_KEY>" # Optional
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# Biconomy Sponsored Payment Example
2+
3+
## Prerequisites
4+
5+
- Node.js >= 23
6+
- pnpm >= 10.8.1
7+
8+
## Quick Start
9+
10+
1. Install dependencies:
11+
12+
```bash
13+
pnpm install
14+
```
15+
16+
## Running Examples
17+
18+
1. Run the example:
19+
20+
```bash
21+
pnpm dev
22+
```
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
{
2+
"name": "biconomy-sponsored-payment",
3+
"private": true,
4+
"version": "0.0.1",
5+
"scripts": {
6+
"dev": "tsx src/index.ts"
7+
},
8+
"dependencies": {
9+
"@gelatonetwork/smartwallet": "workspace:*",
10+
"viem": "catalog:"
11+
},
12+
"devDependencies": {
13+
"@types/node": "latest",
14+
"dotenv": "17.2.1",
15+
"tsx": "4.20.5",
16+
"typescript": "catalog:"
17+
}
18+
}
Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
import {
2+
createGelatoSmartWalletClient,
3+
type GelatoTaskStatus,
4+
sponsored
5+
} from "@gelatonetwork/smartwallet";
6+
import { custom, type GelatoSmartAccountExtension } from "@gelatonetwork/smartwallet/accounts";
7+
import "dotenv/config";
8+
import { createPublicClient, createWalletClient, type Hex, http } from "viem";
9+
import { entryPoint07Abi, entryPoint07Address } from "viem/account-abstraction";
10+
import { generatePrivateKey, privateKeyToAccount } from "viem/accounts";
11+
import { baseSepolia } from "viem/chains";
12+
import { ERC4337Encoding } from "../../../src/_dist/wallet";
13+
14+
const gelatoApiKey = process.env.GELATO_API_KEY;
15+
16+
if (!gelatoApiKey) {
17+
throw new Error("GELATO_API_KEY is not set");
18+
}
19+
20+
const privateKey = (process.env.PRIVATE_KEY ?? generatePrivateKey()) as Hex;
21+
const owner = privateKeyToAccount(privateKey);
22+
23+
const publicClient = createPublicClient({
24+
chain: baseSepolia,
25+
transport: http()
26+
});
27+
28+
(async () => {
29+
// Defining an EIP7702 account using as delegation address "0x00000000383e8cBe298514674Ea60Ee1d1de50ac" (Nexus v1.2.0)
30+
// Using ERC4337 and entry point v0.7
31+
const account = await custom<
32+
typeof entryPoint07Abi,
33+
"0.7",
34+
GelatoSmartAccountExtension,
35+
true
36+
>({
37+
authorization: {
38+
account: owner,
39+
address: "0x00000000383e8cBe298514674Ea60Ee1d1de50ac", // Nexus v1.2.0
40+
},
41+
client: publicClient,
42+
eip7702: true,
43+
entryPoint: {
44+
abi: entryPoint07Abi,
45+
address: entryPoint07Address,
46+
version: "0.7",
47+
},
48+
owner,
49+
scw: {
50+
encoding: ERC4337Encoding.ERC7579,
51+
},
52+
});
53+
54+
console.log("Account address:", account.address);
55+
56+
const client = createWalletClient({
57+
account,
58+
chain: baseSepolia,
59+
transport: http(),
60+
});
61+
62+
const swc = await createGelatoSmartWalletClient(client, {
63+
apiKey: gelatoApiKey,
64+
});
65+
66+
const response = await swc.execute({
67+
calls: [
68+
{
69+
data: "0xd09de08a",
70+
to: "0xEEeBe2F778AA186e88dCf2FEb8f8231565769C27",
71+
value: 0n,
72+
},
73+
],
74+
payment: sponsored(),
75+
});
76+
77+
console.log(`Your Gelato id is: ${response.id}`);
78+
console.log("Waiting for transaction to be confirmed...");
79+
80+
// Listen for events
81+
response.on("success", (status: GelatoTaskStatus) => {
82+
console.log(`Transaction successful: ${status.transactionHash}`);
83+
process.exit(0);
84+
});
85+
response.on("error", (error: Error) => {
86+
console.error(`Transaction failed: ${error.message}`);
87+
process.exit(1);
88+
});
89+
})();
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"extends": "../../tsconfig.json"
3+
}

0 commit comments

Comments
 (0)