@turnkey/gas-station 0.3.0 → 0.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +5 -74
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -27,7 +27,7 @@ Perfect for building dApps where users don't need ETH for gas, enabling seamless
|
|
|
27
27
|
### 1. Install Dependencies
|
|
28
28
|
|
|
29
29
|
```bash
|
|
30
|
-
pnpm install @turnkey/sdk-server @turnkey/viem viem
|
|
30
|
+
pnpm install @turnkey/gas-station @turnkey/sdk-server @turnkey/viem viem
|
|
31
31
|
```
|
|
32
32
|
|
|
33
33
|
### 2. Set Up Environment
|
|
@@ -88,7 +88,7 @@ const userAccount = await createAccount({
|
|
|
88
88
|
const paymasterAccount = await createAccount({
|
|
89
89
|
client: turnkeyClient.apiClient(),
|
|
90
90
|
organizationId: process.env.ORGANIZATION_ID!,
|
|
91
|
-
signWith: process.env.
|
|
91
|
+
signWith: process.env.PAYMASTER_ADDRESS as `0x${string}`,
|
|
92
92
|
});
|
|
93
93
|
|
|
94
94
|
// Create viem wallet clients
|
|
@@ -163,7 +163,7 @@ new GasStationClient({
|
|
|
163
163
|
- Sign an EIP-7702 authorization for the gas station contract
|
|
164
164
|
- Returns authorization that can be submitted by paymaster
|
|
165
165
|
|
|
166
|
-
**`createIntent():
|
|
166
|
+
**`createIntent(): IntentBuilder`**
|
|
167
167
|
|
|
168
168
|
- Create a builder for composing transactions
|
|
169
169
|
- Intent must be signed before execution
|
|
@@ -242,24 +242,6 @@ const swapIntent = await userClient
|
|
|
242
242
|
await paymasterClient.execute(swapIntent);
|
|
243
243
|
```
|
|
244
244
|
|
|
245
|
-
### NFT Minting
|
|
246
|
-
|
|
247
|
-
```typescript
|
|
248
|
-
const nonce = await userClient.getNonce();
|
|
249
|
-
const mintIntent = await userClient
|
|
250
|
-
.createIntent()
|
|
251
|
-
.callContract({
|
|
252
|
-
contract: nftContract,
|
|
253
|
-
abi: NFT_ABI,
|
|
254
|
-
functionName: "mint",
|
|
255
|
-
args: [tokenId],
|
|
256
|
-
value: parseEther("0.1"), // Optional ETH to send
|
|
257
|
-
})
|
|
258
|
-
.sign(nonce);
|
|
259
|
-
|
|
260
|
-
await paymasterClient.execute(mintIntent);
|
|
261
|
-
```
|
|
262
|
-
|
|
263
245
|
### User Onboarding
|
|
264
246
|
|
|
265
247
|
```typescript
|
|
@@ -461,7 +443,7 @@ const eoaPolicy = buildIntentSigningPolicy({
|
|
|
461
443
|
eoaUserId: "user-id",
|
|
462
444
|
restrictions: {
|
|
463
445
|
allowedContracts: ["0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913"],
|
|
464
|
-
|
|
446
|
+
disallowEthTransfer: true, // No ETH transfers
|
|
465
447
|
},
|
|
466
448
|
});
|
|
467
449
|
|
|
@@ -644,7 +626,6 @@ The helper functions automatically:
|
|
|
644
626
|
|
|
645
627
|
- Ensure paymaster has ETH for gas
|
|
646
628
|
- Verify delegate contract address is correct
|
|
647
|
-
- Check EOA hasn't already been authorized
|
|
648
629
|
|
|
649
630
|
### Execution Failed
|
|
650
631
|
|
|
@@ -664,62 +645,12 @@ The helper functions automatically:
|
|
|
664
645
|
- Ensure chain ID matches the network
|
|
665
646
|
- Check intent was signed with correct nonce
|
|
666
647
|
|
|
667
|
-
## Advanced: Custom Contract Integration
|
|
668
|
-
|
|
669
|
-
For contracts beyond standard transfers:
|
|
670
|
-
|
|
671
|
-
```typescript
|
|
672
|
-
// Define your contract ABI
|
|
673
|
-
const MY_CONTRACT_ABI = [
|
|
674
|
-
{
|
|
675
|
-
name: "customFunction",
|
|
676
|
-
type: "function",
|
|
677
|
-
inputs: [
|
|
678
|
-
{ name: "param1", type: "uint256" },
|
|
679
|
-
{ name: "param2", type: "address" },
|
|
680
|
-
],
|
|
681
|
-
outputs: [],
|
|
682
|
-
},
|
|
683
|
-
];
|
|
684
|
-
|
|
685
|
-
// Build and execute
|
|
686
|
-
const nonce = await userClient.getNonce();
|
|
687
|
-
const intent = await userClient
|
|
688
|
-
.createIntent()
|
|
689
|
-
.callContract({
|
|
690
|
-
contract: myContractAddress,
|
|
691
|
-
abi: MY_CONTRACT_ABI,
|
|
692
|
-
functionName: "customFunction",
|
|
693
|
-
args: [12345, recipientAddress],
|
|
694
|
-
})
|
|
695
|
-
.sign(nonce);
|
|
696
|
-
|
|
697
|
-
// Execute gaslessly
|
|
698
|
-
await paymasterClient.execute(intent);
|
|
699
|
-
```
|
|
700
|
-
|
|
701
|
-
## Contract Deployment
|
|
702
|
-
|
|
703
|
-
You need to deploy two contracts:
|
|
704
|
-
|
|
705
|
-
1. **Delegate Contract** - Slim contract authorized via EIP-7702
|
|
706
|
-
2. **Execution Contract** - Contains `execute()` function and nonce storage
|
|
707
|
-
|
|
708
|
-
The execution contract should implement:
|
|
709
|
-
|
|
710
|
-
- `execute(address eoaAddress, uint128 nonce, address outputContract, uint256 ethAmount, bytes callData, bytes signature)`
|
|
711
|
-
- `getNonce(address eoaAddress) returns (uint128)`
|
|
712
|
-
|
|
713
|
-
See `abi/gas-station.ts` for the expected interface.
|
|
714
|
-
|
|
715
648
|
## Best Practices
|
|
716
649
|
|
|
717
650
|
1. **Client Separation**: Create separate client instances for users and paymasters
|
|
718
651
|
2. **Authorization**: Only call `authorize()` once per EOA
|
|
719
652
|
3. **Nonce Management**: Always fetch fresh nonce before creating intents
|
|
720
|
-
4. **
|
|
721
|
-
5. **Rate Limiting**: Implement paymaster rate limits to prevent abuse
|
|
722
|
-
6. **Monitoring**: Track gas costs and failed transactions for optimization
|
|
653
|
+
4. **Rate Limiting**: Implement paymaster rate limits to prevent abuse
|
|
723
654
|
|
|
724
655
|
## License
|
|
725
656
|
|