@coinbase/cdp-wagmi 0.0.23 → 0.0.24
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 +159 -0
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -234,4 +234,163 @@ export default function WagmiTransaction() {
|
|
|
234
234
|
</div>
|
|
235
235
|
);
|
|
236
236
|
}
|
|
237
|
+
```
|
|
238
|
+
|
|
239
|
+
### Smart Accounts
|
|
240
|
+
|
|
241
|
+
This package has Smart Account support for the Wagmi `useSendCalls`, `useCallsStatus` and `useCapabilities` hooks. It requires a different CDP Config than for EOA wallets:
|
|
242
|
+
|
|
243
|
+
```tsx
|
|
244
|
+
const cdpConfig: Config = {
|
|
245
|
+
projectId: "your-project-id", // Copy your Project ID here.
|
|
246
|
+
createAccountOnLogin: "evm-smart" // Create a smart account by default when a user logs in and does not yet have one
|
|
247
|
+
}
|
|
248
|
+
```
|
|
249
|
+
|
|
250
|
+
After signing in, you can send a User Operation using Wagmi hooks:
|
|
251
|
+
|
|
252
|
+
```tsx
|
|
253
|
+
import { useState } from "react";
|
|
254
|
+
import { parseEther } from "viem";
|
|
255
|
+
import { useAccount, useSendCalls, useSendCalls, useCallsStatus, useCapabilities } from "wagmi";
|
|
256
|
+
|
|
257
|
+
/**
|
|
258
|
+
* The burn address (0x0000000000000000000000000000000000000000)
|
|
259
|
+
*/
|
|
260
|
+
const BURN_ADDRESS = "0x0000000000000000000000000000000000000000" as const;
|
|
261
|
+
|
|
262
|
+
/**
|
|
263
|
+
* The amount to send in ETH (0.00001 ETH)
|
|
264
|
+
*/
|
|
265
|
+
const AMOUNT_TO_SEND = "0.00001";
|
|
266
|
+
|
|
267
|
+
/**
|
|
268
|
+
* SendCalls component that allows users with Smart Accounts to send ETH to the burn address
|
|
269
|
+
*
|
|
270
|
+
* @returns JSX element with transaction sending functionality
|
|
271
|
+
*/
|
|
272
|
+
export function WagmiSendCalls() {
|
|
273
|
+
const { address, isConnected } = useAccount();
|
|
274
|
+
const { data: userOpHash, sendCalls, isPending, error } = useSendCalls();
|
|
275
|
+
// Check the status of a sent user operation
|
|
276
|
+
const { isLoading: isConfirming, isSuccess } = useCallsStatus({
|
|
277
|
+
id: userOpHash as Hex,
|
|
278
|
+
query: {
|
|
279
|
+
enabled: !!userOpHash,
|
|
280
|
+
},
|
|
281
|
+
});
|
|
282
|
+
const chainId = useChainId();
|
|
283
|
+
const { data: walletCapabilities } = useCapabilities({
|
|
284
|
+
chainId,
|
|
285
|
+
});
|
|
286
|
+
|
|
287
|
+
// Check the capabilities of the wallet to determine if you can use user operations
|
|
288
|
+
const isSendCallsSupported = useMemo(() => {
|
|
289
|
+
return walletCapabilities?.atomic?.status === "supported";
|
|
290
|
+
}, [walletCapabilities]);
|
|
291
|
+
|
|
292
|
+
const handleSendCalls = async () => {
|
|
293
|
+
if (!isConnected || !address) return;
|
|
294
|
+
|
|
295
|
+
try {
|
|
296
|
+
sendCalls(
|
|
297
|
+
{
|
|
298
|
+
calls: [
|
|
299
|
+
{
|
|
300
|
+
to: BURN_ADDRESS,
|
|
301
|
+
value: parseEther(AMOUNT_TO_SEND),
|
|
302
|
+
},
|
|
303
|
+
],
|
|
304
|
+
}
|
|
305
|
+
);
|
|
306
|
+
} catch (err) {
|
|
307
|
+
console.log("Failed to send user operation: ", err)
|
|
308
|
+
}
|
|
309
|
+
};
|
|
310
|
+
|
|
311
|
+
if (!isSendCallsSupported) {
|
|
312
|
+
return (
|
|
313
|
+
<div>
|
|
314
|
+
<p>
|
|
315
|
+
This wallet does not support sending calls on chain {chainId}. Ensure your wallet has a
|
|
316
|
+
smart account, and is on a supported chain.
|
|
317
|
+
</p>
|
|
318
|
+
</div>
|
|
319
|
+
);
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
return (
|
|
323
|
+
<div>
|
|
324
|
+
<div>
|
|
325
|
+
<p>
|
|
326
|
+
⚠️ Warning: This will send {AMOUNT_TO_SEND} ETH to the burn address (0x0000...0000).
|
|
327
|
+
This operation cannot be reversed and the ETH will be permanently lost.
|
|
328
|
+
</p>
|
|
329
|
+
</div>
|
|
330
|
+
|
|
331
|
+
<div>
|
|
332
|
+
<div>
|
|
333
|
+
<div>Amount: {AMOUNT_TO_SEND} ETH</div>
|
|
334
|
+
<div>To (Burn Address): {BURN_ADDRESS.slice(0, 6)}...{BURN_ADDRESS.slice(-4)}</div>
|
|
335
|
+
<div>From: {address?.slice(0, 6)}...{address?.slice(-4)}</div>
|
|
336
|
+
</div>
|
|
337
|
+
</div>
|
|
338
|
+
|
|
339
|
+
{error && (
|
|
340
|
+
<div>
|
|
341
|
+
<strong>Error:</strong> {error.message}
|
|
342
|
+
</div>
|
|
343
|
+
)}
|
|
344
|
+
|
|
345
|
+
{!userOpHash && !isPending && (
|
|
346
|
+
<button disabled={!address} onClick={handleSendCalls}>
|
|
347
|
+
Send {AMOUNT_TO_SEND} ETH to Burn Address
|
|
348
|
+
</button>
|
|
349
|
+
)}
|
|
350
|
+
|
|
351
|
+
{(isPending || isConfirming) && (
|
|
352
|
+
<div>
|
|
353
|
+
<div>Sending transaction...</div>
|
|
354
|
+
{hash && (
|
|
355
|
+
<div>
|
|
356
|
+
Hash: {hash.slice(0, 10)}...{hash.slice(-8)}
|
|
357
|
+
</div>
|
|
358
|
+
)}
|
|
359
|
+
</div>
|
|
360
|
+
)}
|
|
361
|
+
|
|
362
|
+
{isSuccess && userOpHash && (
|
|
363
|
+
<div>
|
|
364
|
+
<div>
|
|
365
|
+
<div>✅</div>
|
|
366
|
+
</div>
|
|
367
|
+
|
|
368
|
+
<div>
|
|
369
|
+
<div>Operation Sent!</div>
|
|
370
|
+
<div>Your operation has been successfully sent to the burn address</div>
|
|
371
|
+
</div>
|
|
372
|
+
|
|
373
|
+
<div>
|
|
374
|
+
<div>Amount: {AMOUNT_TO_SEND} ETH</div>
|
|
375
|
+
<div>To: {BURN_ADDRESS.slice(0, 6)}...{BURN_ADDRESS.slice(-4)}</div>
|
|
376
|
+
<div>
|
|
377
|
+
Block Explorer:{" "}
|
|
378
|
+
<a
|
|
379
|
+
href={`https://sepolia.basescan.org/tx/${userOpHash}`}
|
|
380
|
+
target="_blank"
|
|
381
|
+
rel="noopener noreferrer"
|
|
382
|
+
>
|
|
383
|
+
{hash.slice(0, 10)}...{hash.slice(-8)}
|
|
384
|
+
</a>
|
|
385
|
+
</div>
|
|
386
|
+
</div>
|
|
387
|
+
|
|
388
|
+
<button onClick={handleReset}>
|
|
389
|
+
Send Another Operation →
|
|
390
|
+
</button>
|
|
391
|
+
</div>
|
|
392
|
+
)}
|
|
393
|
+
</div>
|
|
394
|
+
);
|
|
395
|
+
}
|
|
237
396
|
```
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@coinbase/cdp-wagmi",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.24",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"files": [
|
|
6
6
|
"dist/**",
|
|
@@ -18,7 +18,7 @@
|
|
|
18
18
|
"react": ">=18.2.0",
|
|
19
19
|
"viem": "^2.33.0",
|
|
20
20
|
"wagmi": "^2.16.0",
|
|
21
|
-
"@coinbase/cdp-core": "^0.0.
|
|
21
|
+
"@coinbase/cdp-core": "^0.0.24"
|
|
22
22
|
},
|
|
23
23
|
"devDependencies": {
|
|
24
24
|
"@tanstack/react-query": "^5.0.0",
|
|
@@ -34,7 +34,7 @@
|
|
|
34
34
|
"@size-limit/webpack": "^11.2.0",
|
|
35
35
|
"@size-limit/webpack-why": "^11.2.0",
|
|
36
36
|
"size-limit": "^11.2.0",
|
|
37
|
-
"@coinbase/cdp-core": "^0.0.
|
|
37
|
+
"@coinbase/cdp-core": "^0.0.24"
|
|
38
38
|
},
|
|
39
39
|
"size-limit": [
|
|
40
40
|
{
|