@atxp/worldchain 0.6.4
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 +237 -0
- package/dist/cache.js +11 -0
- package/dist/cache.js.map +1 -0
- package/dist/index.cjs +882 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.ts +235 -0
- package/dist/index.js +869 -0
- package/dist/index.js.map +1 -0
- package/dist/mainWalletPaymentMaker.js +136 -0
- package/dist/mainWalletPaymentMaker.js.map +1 -0
- package/dist/minikit.js +254 -0
- package/dist/minikit.js.map +1 -0
- package/dist/smartWalletHelpers.js +46 -0
- package/dist/smartWalletHelpers.js.map +1 -0
- package/dist/spendPermissionShim.js +119 -0
- package/dist/spendPermissionShim.js.map +1 -0
- package/dist/worldchainAccount.js +136 -0
- package/dist/worldchainAccount.js.map +1 -0
- package/dist/worldchainPaymentMaker.js +206 -0
- package/dist/worldchainPaymentMaker.js.map +1 -0
- package/package.json +58 -0
package/README.md
ADDED
|
@@ -0,0 +1,237 @@
|
|
|
1
|
+
# @atxp/worldchain
|
|
2
|
+
|
|
3
|
+
ATXP for World Chain Mini Apps - Enable seamless payments in World Chain applications using MiniKit.
|
|
4
|
+
|
|
5
|
+
## Overview
|
|
6
|
+
|
|
7
|
+
`@atxp/worldchain` provides a complete solution for integrating ATXP (Autonomous Transaction eXecution Protocol) payments into World Chain Mini Apps. It handles World Chain-specific wallet interactions, USDC transfers, and MiniKit integration while abstracting away the complexity of blockchain transactions.
|
|
8
|
+
|
|
9
|
+
## Installation
|
|
10
|
+
|
|
11
|
+
```bash
|
|
12
|
+
npm install @atxp/worldchain
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
### Peer Dependencies
|
|
16
|
+
|
|
17
|
+
```bash
|
|
18
|
+
npm install viem @worldcoin/minikit-js
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
## Quick Start
|
|
22
|
+
|
|
23
|
+
### 1. Create a Worldchain Account
|
|
24
|
+
|
|
25
|
+
```typescript
|
|
26
|
+
import { createMiniKitWorldchainAccount } from '@atxp/worldchain';
|
|
27
|
+
import { MiniKit } from '@worldcoin/minikit-js';
|
|
28
|
+
|
|
29
|
+
const account = await createMiniKitWorldchainAccount({
|
|
30
|
+
walletAddress: '0x1234...', // User's wallet address
|
|
31
|
+
miniKit: MiniKit
|
|
32
|
+
});
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
### 2. Set up ATXP Client
|
|
36
|
+
|
|
37
|
+
```typescript
|
|
38
|
+
import { atxpClient } from '@atxp/client';
|
|
39
|
+
|
|
40
|
+
const client = await atxpClient({
|
|
41
|
+
account,
|
|
42
|
+
mcpServer: 'https://your-mcp-server.com',
|
|
43
|
+
onPayment: async ({ payment }) => {
|
|
44
|
+
console.log('Payment successful:', payment);
|
|
45
|
+
},
|
|
46
|
+
onPaymentFailure: async ({ payment, error }) => {
|
|
47
|
+
console.log('Payment failed:', payment, error);
|
|
48
|
+
}
|
|
49
|
+
});
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
### 3. Make MCP Tool Calls
|
|
53
|
+
|
|
54
|
+
```typescript
|
|
55
|
+
const result = await client.callTool({
|
|
56
|
+
name: 'your_tool_name',
|
|
57
|
+
arguments: { prompt: 'Generate an image' }
|
|
58
|
+
});
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
## React Integration Example
|
|
62
|
+
|
|
63
|
+
Here's how to integrate ATXP Worldchain into a React application:
|
|
64
|
+
|
|
65
|
+
```typescript
|
|
66
|
+
import { createMiniKitWorldchainAccount, WorldchainAccount } from '@atxp/worldchain';
|
|
67
|
+
import { atxpClient } from '@atxp/client';
|
|
68
|
+
import { MiniKit } from '@worldcoin/minikit-js';
|
|
69
|
+
import { useCallback, useEffect, useState } from 'react';
|
|
70
|
+
|
|
71
|
+
export const AtxpProvider = ({ children }) => {
|
|
72
|
+
const [atxpAccount, setAtxpAccount] = useState<WorldchainAccount | null>(null);
|
|
73
|
+
const [atxpClient, setAtxpClient] = useState(null);
|
|
74
|
+
|
|
75
|
+
const loadAccount = useCallback(async (walletAddress: string) => {
|
|
76
|
+
const account = await createMiniKitWorldchainAccount({
|
|
77
|
+
walletAddress,
|
|
78
|
+
miniKit: MiniKit
|
|
79
|
+
});
|
|
80
|
+
setAtxpAccount(account);
|
|
81
|
+
|
|
82
|
+
const client = await atxpClient({
|
|
83
|
+
account,
|
|
84
|
+
mcpServer: 'https://your-mcp-server.com',
|
|
85
|
+
onPayment: async ({ payment }) => {
|
|
86
|
+
console.log('Payment successful:', payment);
|
|
87
|
+
}
|
|
88
|
+
});
|
|
89
|
+
setAtxpClient(client);
|
|
90
|
+
}, []);
|
|
91
|
+
|
|
92
|
+
// Initialize when wallet connects
|
|
93
|
+
useEffect(() => {
|
|
94
|
+
if (walletAddress && !atxpAccount) {
|
|
95
|
+
loadAccount(walletAddress);
|
|
96
|
+
}
|
|
97
|
+
}, [walletAddress, atxpAccount, loadAccount]);
|
|
98
|
+
|
|
99
|
+
const generateImage = useCallback(async (prompt: string) => {
|
|
100
|
+
if (!atxpClient) return null;
|
|
101
|
+
|
|
102
|
+
const response = await atxpClient.callTool({
|
|
103
|
+
name: 'image_generator',
|
|
104
|
+
arguments: { prompt }
|
|
105
|
+
});
|
|
106
|
+
|
|
107
|
+
return response;
|
|
108
|
+
}, [atxpClient]);
|
|
109
|
+
|
|
110
|
+
return (
|
|
111
|
+
<AtxpContext.Provider value={{ atxpAccount, generateImage }}>
|
|
112
|
+
{children}
|
|
113
|
+
</AtxpContext.Provider>
|
|
114
|
+
);
|
|
115
|
+
};
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
## API Reference
|
|
119
|
+
|
|
120
|
+
### `createMiniKitWorldchainAccount(options)`
|
|
121
|
+
|
|
122
|
+
Creates and initializes a Worldchain account with MiniKit integration.
|
|
123
|
+
|
|
124
|
+
#### Parameters
|
|
125
|
+
|
|
126
|
+
- `walletAddress: string` - The user's wallet address
|
|
127
|
+
- `miniKit: typeof MiniKit` - MiniKit instance for transaction signing
|
|
128
|
+
- `logger?: Logger` - Optional logger for debugging
|
|
129
|
+
- `customRpcUrl?: string` - Optional custom RPC URL (defaults to public Worldchain RPC)
|
|
130
|
+
|
|
131
|
+
#### Returns
|
|
132
|
+
|
|
133
|
+
`Promise<WorldchainAccount>` - Initialized Worldchain account
|
|
134
|
+
|
|
135
|
+
### `WorldchainAccount`
|
|
136
|
+
|
|
137
|
+
The main account class that handles Worldchain interactions.
|
|
138
|
+
|
|
139
|
+
#### Key Features
|
|
140
|
+
|
|
141
|
+
- **USDC Transfers**: Handles ERC-20 USDC transfers via MiniKit
|
|
142
|
+
- **Message Signing**: Signs messages using World App's secure signing
|
|
143
|
+
- **Smart Wallet Integration**: Works with Worldchain's account abstraction
|
|
144
|
+
- **Spend Permissions**: Manages recurring payment permissions
|
|
145
|
+
|
|
146
|
+
### `WorldchainPaymentMaker`
|
|
147
|
+
|
|
148
|
+
Handles payment processing for ATXP transactions.
|
|
149
|
+
|
|
150
|
+
### `MainWalletPaymentMaker`
|
|
151
|
+
|
|
152
|
+
Alternative payment processor for main wallet integrations.
|
|
153
|
+
|
|
154
|
+
### Caching System
|
|
155
|
+
|
|
156
|
+
```typescript
|
|
157
|
+
import { BrowserCache, MemoryCache } from '@atxp/worldchain';
|
|
158
|
+
|
|
159
|
+
// Browser-based cache for persistent storage
|
|
160
|
+
const cache = new BrowserCache();
|
|
161
|
+
|
|
162
|
+
// Memory cache for temporary storage
|
|
163
|
+
const memoryCache = new MemoryCache();
|
|
164
|
+
```
|
|
165
|
+
|
|
166
|
+
## Configuration
|
|
167
|
+
|
|
168
|
+
### Default Configuration
|
|
169
|
+
|
|
170
|
+
The package comes with sensible defaults:
|
|
171
|
+
|
|
172
|
+
- **Chain**: Worldchain Mainnet (Chain ID: 480)
|
|
173
|
+
- **RPC**: Public Worldchain RPC endpoint
|
|
174
|
+
- **Allowance**: 10 USDC
|
|
175
|
+
- **Permission Period**: 30 days
|
|
176
|
+
- **Wallet Mode**: Regular (non-ephemeral)
|
|
177
|
+
|
|
178
|
+
### Custom RPC Endpoint
|
|
179
|
+
|
|
180
|
+
```typescript
|
|
181
|
+
const account = await createMiniKitWorldchainAccount({
|
|
182
|
+
walletAddress: '0x1234...',
|
|
183
|
+
customRpcUrl: 'https://your-worldchain-rpc.com',
|
|
184
|
+
miniKit: MiniKit
|
|
185
|
+
});
|
|
186
|
+
```
|
|
187
|
+
|
|
188
|
+
## Error Handling
|
|
189
|
+
|
|
190
|
+
The library provides detailed error handling for common scenarios:
|
|
191
|
+
|
|
192
|
+
### Insufficient Balance
|
|
193
|
+
|
|
194
|
+
```typescript
|
|
195
|
+
try {
|
|
196
|
+
await client.callTool({ name: 'expensive_tool', arguments: {} });
|
|
197
|
+
} catch (error) {
|
|
198
|
+
if (error.message.includes('transfer amount exceeds balance')) {
|
|
199
|
+
// Handle insufficient USDC balance
|
|
200
|
+
console.log('Please add USDC to your wallet');
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
```
|
|
204
|
+
|
|
205
|
+
### Transaction Failures
|
|
206
|
+
|
|
207
|
+
```typescript
|
|
208
|
+
const client = await atxpClient({
|
|
209
|
+
account,
|
|
210
|
+
mcpServer: 'https://your-server.com',
|
|
211
|
+
onPaymentFailure: async ({ payment, error }) => {
|
|
212
|
+
if (error.message.includes('Transaction receipt')) {
|
|
213
|
+
// Payment verification failed - transaction may still be pending
|
|
214
|
+
console.log('Payment verification failed, please wait and try again');
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
});
|
|
218
|
+
```
|
|
219
|
+
|
|
220
|
+
## Supported Networks
|
|
221
|
+
|
|
222
|
+
- **Worldchain Mainnet** (Chain ID: 480)
|
|
223
|
+
|
|
224
|
+
## Requirements
|
|
225
|
+
|
|
226
|
+
- Node.js 16+ or modern browser environment
|
|
227
|
+
- World App with MiniKit support
|
|
228
|
+
- USDC balance on Worldchain
|
|
229
|
+
|
|
230
|
+
## Example Application
|
|
231
|
+
|
|
232
|
+
See the complete example in https://github.com/atxp-dev/worldchain-demo-app which demonstrates:
|
|
233
|
+
|
|
234
|
+
- React Context integration
|
|
235
|
+
- Image generation with ATXP payments
|
|
236
|
+
- Error handling and user feedback
|
|
237
|
+
- Async operation management
|
package/dist/cache.js
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { JsonCache } from '@atxp/common';
|
|
2
|
+
export { BrowserCache, MemoryCache } from '@atxp/common';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Type-safe cache wrapper for permission data
|
|
6
|
+
*/
|
|
7
|
+
class IntermediaryCache extends JsonCache {
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export { IntermediaryCache };
|
|
11
|
+
//# sourceMappingURL=cache.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cache.js","sources":["../src/cache.ts"],"sourcesContent":[null],"names":[],"mappings":";;;AAcA;;AAEG;AACG,MAAO,iBAAkB,SAAQ,SAAuB,CAAA;AAAG;;;;"}
|