@coinbase/cdp-sdk 1.46.1 → 1.48.0
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/CHANGELOG.md +14 -0
- package/README.md +332 -0
- package/_cjs/actions/solana/sendTransaction.js +3 -0
- package/_cjs/actions/solana/sendTransaction.js.map +1 -1
- package/_cjs/actions/webhooks/createWebhookSubscription.js +48 -0
- package/_cjs/actions/webhooks/createWebhookSubscription.js.map +1 -0
- package/_cjs/actions/webhooks/index.js +6 -0
- package/_cjs/actions/webhooks/index.js.map +1 -0
- package/_cjs/client/cdp.js +5 -4
- package/_cjs/client/cdp.js.map +1 -1
- package/_cjs/client/end-user/endUser.js +19 -89
- package/_cjs/client/end-user/endUser.js.map +1 -1
- package/_cjs/client/end-user/toEndUserAccount.js +13 -43
- package/_cjs/client/end-user/toEndUserAccount.js.map +1 -1
- package/_cjs/client/solana/solana.js +2 -0
- package/_cjs/client/solana/solana.js.map +1 -1
- package/_cjs/client/webhooks/webhooks.js +58 -0
- package/_cjs/client/webhooks/webhooks.js.map +1 -0
- package/_cjs/index.js.map +1 -1
- package/_cjs/openapi-client/cdpApiClient.js +0 -32
- package/_cjs/openapi-client/cdpApiClient.js.map +1 -1
- package/_cjs/openapi-client/generated/coinbaseDeveloperPlatformAPIs.schemas.js +51 -11
- package/_cjs/openapi-client/generated/coinbaseDeveloperPlatformAPIs.schemas.js.map +1 -1
- package/_cjs/openapi-client/generated/{embedded-wallets-core-functionality/embedded-wallets-core-functionality.js → embedded-wallets/embedded-wallets.js} +37 -65
- package/_cjs/openapi-client/generated/embedded-wallets/embedded-wallets.js.map +1 -0
- package/_cjs/openapi-client/generated/evm-smart-accounts/evm-smart-accounts.js +2 -2
- package/_cjs/openapi-client/generated/evm-smart-accounts/evm-smart-accounts.js.map +1 -1
- package/_cjs/openapi-client/generated/sql-api/sql-api.js +12 -1
- package/_cjs/openapi-client/generated/sql-api/sql-api.js.map +1 -1
- package/_cjs/openapi-client/generated/webhooks/webhooks.js +32 -5
- package/_cjs/openapi-client/generated/webhooks/webhooks.js.map +1 -1
- package/_cjs/openapi-client/index.js +2 -2
- package/_cjs/openapi-client/index.js.map +1 -1
- package/_cjs/version.js +1 -1
- package/_esm/actions/solana/sendTransaction.js +3 -0
- package/_esm/actions/solana/sendTransaction.js.map +1 -1
- package/_esm/actions/webhooks/createWebhookSubscription.js +45 -0
- package/_esm/actions/webhooks/createWebhookSubscription.js.map +1 -0
- package/_esm/actions/webhooks/index.js +2 -0
- package/_esm/actions/webhooks/index.js.map +1 -0
- package/_esm/client/cdp.js +6 -5
- package/_esm/client/cdp.js.map +1 -1
- package/_esm/client/end-user/endUser.js +17 -87
- package/_esm/client/end-user/endUser.js.map +1 -1
- package/_esm/client/end-user/toEndUserAccount.js +13 -43
- package/_esm/client/end-user/toEndUserAccount.js.map +1 -1
- package/_esm/client/solana/solana.js +2 -0
- package/_esm/client/solana/solana.js.map +1 -1
- package/_esm/client/webhooks/webhooks.js +54 -0
- package/_esm/client/webhooks/webhooks.js.map +1 -0
- package/_esm/index.js.map +1 -1
- package/_esm/openapi-client/cdpApiClient.js +0 -32
- package/_esm/openapi-client/cdpApiClient.js.map +1 -1
- package/_esm/openapi-client/generated/coinbaseDeveloperPlatformAPIs.schemas.js +48 -8
- package/_esm/openapi-client/generated/coinbaseDeveloperPlatformAPIs.schemas.js.map +1 -1
- package/_esm/openapi-client/generated/{embedded-wallets-core-functionality/embedded-wallets-core-functionality.js → embedded-wallets/embedded-wallets.js} +36 -61
- package/_esm/openapi-client/generated/embedded-wallets/embedded-wallets.js.map +1 -0
- package/_esm/openapi-client/generated/evm-smart-accounts/evm-smart-accounts.js +2 -2
- package/_esm/openapi-client/generated/evm-smart-accounts/evm-smart-accounts.js.map +1 -1
- package/_esm/openapi-client/generated/sql-api/sql-api.js +10 -0
- package/_esm/openapi-client/generated/sql-api/sql-api.js.map +1 -1
- package/_esm/openapi-client/generated/webhooks/webhooks.js +30 -4
- package/_esm/openapi-client/generated/webhooks/webhooks.js.map +1 -1
- package/_esm/openapi-client/index.js +2 -2
- package/_esm/openapi-client/index.js.map +1 -1
- package/_esm/version.js +1 -1
- package/_types/actions/solana/sendTransaction.d.ts +2 -0
- package/_types/actions/solana/sendTransaction.d.ts.map +1 -1
- package/_types/actions/webhooks/createWebhookSubscription.d.ts +68 -0
- package/_types/actions/webhooks/createWebhookSubscription.d.ts.map +1 -0
- package/_types/actions/webhooks/index.d.ts +2 -0
- package/_types/actions/webhooks/index.d.ts.map +1 -0
- package/_types/client/cdp.d.ts +5 -6
- package/_types/client/cdp.d.ts.map +1 -1
- package/_types/client/end-user/endUser.d.ts +2 -52
- package/_types/client/end-user/endUser.d.ts.map +1 -1
- package/_types/client/end-user/endUser.types.d.ts +1 -63
- package/_types/client/end-user/endUser.types.d.ts.map +1 -1
- package/_types/client/end-user/toEndUserAccount.d.ts +0 -2
- package/_types/client/end-user/toEndUserAccount.d.ts.map +1 -1
- package/_types/client/solana/solana.d.ts +2 -0
- package/_types/client/solana/solana.d.ts.map +1 -1
- package/_types/client/solana/solana.types.d.ts +2 -0
- package/_types/client/solana/solana.types.d.ts.map +1 -1
- package/_types/client/webhooks/webhooks.d.ts +41 -0
- package/_types/client/webhooks/webhooks.d.ts.map +1 -0
- package/_types/index.d.ts +2 -1
- package/_types/index.d.ts.map +1 -1
- package/_types/openapi-client/cdpApiClient.d.ts.map +1 -1
- package/_types/openapi-client/generated/coinbaseDeveloperPlatformAPIs.schemas.d.ts +285 -85
- package/_types/openapi-client/generated/coinbaseDeveloperPlatformAPIs.schemas.d.ts.map +1 -1
- package/_types/openapi-client/generated/{embedded-wallets-core-functionality/embedded-wallets-core-functionality.d.ts → embedded-wallets/embedded-wallets.d.ts} +14 -32
- package/_types/openapi-client/generated/embedded-wallets/embedded-wallets.d.ts.map +1 -0
- package/_types/openapi-client/generated/evm-smart-accounts/evm-smart-accounts.d.ts +2 -2
- package/_types/openapi-client/generated/evm-smart-accounts/evm-smart-accounts.d.ts.map +1 -1
- package/_types/openapi-client/generated/sql-api/sql-api.d.ts +10 -1
- package/_types/openapi-client/generated/sql-api/sql-api.d.ts.map +1 -1
- package/_types/openapi-client/generated/webhooks/webhooks.d.ts +30 -5
- package/_types/openapi-client/generated/webhooks/webhooks.d.ts.map +1 -1
- package/_types/openapi-client/index.d.ts +16 -18
- package/_types/openapi-client/index.d.ts.map +1 -1
- package/_types/version.d.ts +1 -1
- package/actions/solana/sendTransaction.ts +3 -0
- package/actions/webhooks/createWebhookSubscription.ts +104 -0
- package/actions/webhooks/index.ts +6 -0
- package/client/cdp.ts +8 -8
- package/client/end-user/endUser.ts +55 -187
- package/client/end-user/endUser.types.ts +0 -72
- package/client/end-user/toEndUserAccount.ts +57 -152
- package/client/solana/solana.ts +2 -0
- package/client/solana/solana.types.ts +2 -0
- package/client/webhooks/webhooks.ts +61 -0
- package/index.ts +6 -4
- package/openapi-client/cdpApiClient.ts +0 -34
- package/openapi-client/generated/coinbaseDeveloperPlatformAPIs.schemas.ts +331 -93
- package/openapi-client/generated/{embedded-wallets-core-functionality/embedded-wallets-core-functionality.ts → embedded-wallets/embedded-wallets.ts} +45 -99
- package/openapi-client/generated/evm-smart-accounts/evm-smart-accounts.ts +3 -3
- package/openapi-client/generated/sql-api/sql-api.ts +19 -0
- package/openapi-client/generated/webhooks/webhooks.ts +42 -4
- package/openapi-client/index.ts +2 -2
- package/package.json +1 -1
- package/version.ts +1 -1
- package/_cjs/openapi-client/generated/embedded-wallets-core-functionality/embedded-wallets-core-functionality.js.map +0 -1
- package/_esm/openapi-client/generated/embedded-wallets-core-functionality/embedded-wallets-core-functionality.js.map +0 -1
- package/_types/openapi-client/generated/embedded-wallets-core-functionality/embedded-wallets-core-functionality.d.ts.map +0 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,19 @@
|
|
|
1
1
|
# CDP SDK Changelog
|
|
2
2
|
|
|
3
|
+
## 1.48.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- [#634](https://github.com/coinbase/cdp-sdk/pull/634) [`ed47c82`](https://github.com/coinbase/cdp-sdk/commit/ed47c821eca763742137500e3380371dd1b78ec1) Thanks [@milan-cb](https://github.com/milan-cb)! - Added CreateSubscription for Webhooks Client
|
|
8
|
+
|
|
9
|
+
- [#659](https://github.com/coinbase/cdp-sdk/pull/659) [`48ea200`](https://github.com/coinbase/cdp-sdk/commit/48ea20026283f10aa094af66dab4fc1d8feb051e) Thanks [@sammccord](https://github.com/sammccord)! - Consume refactored end user operations for delegated signing in end user client
|
|
10
|
+
|
|
11
|
+
## 1.47.0
|
|
12
|
+
|
|
13
|
+
### Minor Changes
|
|
14
|
+
|
|
15
|
+
- [#645](https://github.com/coinbase/cdp-sdk/pull/645) [`413b179`](https://github.com/coinbase/cdp-sdk/commit/413b179ff853f2786c5a5ab8f421eb09b035c9e7) Thanks [@sddioulde](https://github.com/sddioulde)! - Added solana fee sponsorship
|
|
16
|
+
|
|
3
17
|
## [1.46.1] - 2026-03-30
|
|
4
18
|
|
|
5
19
|
### Security fix
|
package/README.md
CHANGED
|
@@ -26,6 +26,15 @@
|
|
|
26
26
|
- [Add EVM Smart Account to End User](#add-evm-smart-account-to-end-user)
|
|
27
27
|
- [Add Solana Account to End User](#add-solana-account-to-end-user)
|
|
28
28
|
- [Validate Access Token](#validate-access-token)
|
|
29
|
+
- [Delegated Signing Operations](#delegated-signing-operations)
|
|
30
|
+
- [Revoke Delegation](#revoke-delegation)
|
|
31
|
+
- [EVM Signing](#evm-signing)
|
|
32
|
+
- [EVM Sending](#evm-sending)
|
|
33
|
+
- [EVM EIP-7702 Delegation](#evm-eip-7702-delegation)
|
|
34
|
+
- [Solana Signing](#solana-signing)
|
|
35
|
+
- [Solana Sending](#solana-sending)
|
|
36
|
+
- [Webhooks](#webhooks)
|
|
37
|
+
- [Create Subscription](#create-subscription)
|
|
29
38
|
- [Authentication tools](#authentication-tools)
|
|
30
39
|
- [Error Reporting](#error-reporting)
|
|
31
40
|
- [Usage Tracking](#usage-tracking)
|
|
@@ -434,6 +443,16 @@ console.log(
|
|
|
434
443
|
);
|
|
435
444
|
```
|
|
436
445
|
|
|
446
|
+
To have CDP sponsor the transaction fees, pass `useCdpSponsor: true`. When enabled, CDP pays the network fee so the sender does not need SOL for fees.
|
|
447
|
+
|
|
448
|
+
```typescript
|
|
449
|
+
const txResult = await cdp.solana.sendTransaction({
|
|
450
|
+
network: "solana-devnet",
|
|
451
|
+
transaction: serializedTx,
|
|
452
|
+
useCdpSponsor: true,
|
|
453
|
+
});
|
|
454
|
+
```
|
|
455
|
+
|
|
437
456
|
### EIP-7702 delegation
|
|
438
457
|
|
|
439
458
|
You can create an [EIP-7702](https://eips.ethereum.org/EIPS/eip-7702) delegation for an existing EOA, upgrading it with smart account capabilities on supported networks. The delegated EOA can then use batched transactions and gas sponsorship via paymaster.
|
|
@@ -1324,6 +1343,319 @@ try {
|
|
|
1324
1343
|
}
|
|
1325
1344
|
```
|
|
1326
1345
|
|
|
1346
|
+
## Delegated Signing Operations
|
|
1347
|
+
|
|
1348
|
+
When an end user has granted a delegation, you can sign and send transactions on their behalf using the `cdp.endUser` client methods or directly on the `EndUserAccount` object.
|
|
1349
|
+
|
|
1350
|
+
All delegated operations are available both as client methods (passing `userId` explicitly) and as convenience methods on the `EndUserAccount` object (where `userId` is automatically bound and `address` defaults to the first account if not specified).
|
|
1351
|
+
|
|
1352
|
+
### Revoke Delegation
|
|
1353
|
+
|
|
1354
|
+
Revoke all active delegations for an end user:
|
|
1355
|
+
|
|
1356
|
+
```typescript
|
|
1357
|
+
// Using the client method
|
|
1358
|
+
await cdp.endUser.revokeDelegationForEndUser({
|
|
1359
|
+
userId: "user-123",
|
|
1360
|
+
});
|
|
1361
|
+
|
|
1362
|
+
// Or using the EndUser object
|
|
1363
|
+
const endUser = await cdp.endUser.getEndUser({ userId: "user-123" });
|
|
1364
|
+
await endUser.revokeDelegation();
|
|
1365
|
+
```
|
|
1366
|
+
|
|
1367
|
+
For a complete example, see [end-users/revokeDelegation.ts](https://github.com/coinbase/cdp-sdk/blob/main/examples/typescript/end-users/revokeDelegation.ts).
|
|
1368
|
+
|
|
1369
|
+
### EVM Signing
|
|
1370
|
+
|
|
1371
|
+
#### Sign an EVM Transaction
|
|
1372
|
+
|
|
1373
|
+
```typescript
|
|
1374
|
+
const result = await cdp.endUser.signEvmTransaction({
|
|
1375
|
+
userId: "user-123",
|
|
1376
|
+
address: "0x1234...",
|
|
1377
|
+
transaction: "0x02...", // RLP-serialized EIP-1559 transaction, hex-encoded
|
|
1378
|
+
});
|
|
1379
|
+
console.log(result.signedTransaction);
|
|
1380
|
+
|
|
1381
|
+
// Or using the EndUser object
|
|
1382
|
+
const result = await endUser.signEvmTransaction({
|
|
1383
|
+
transaction: "0x02...",
|
|
1384
|
+
});
|
|
1385
|
+
console.log(result.signedTransaction);
|
|
1386
|
+
```
|
|
1387
|
+
|
|
1388
|
+
#### Sign an EVM Message (EIP-191)
|
|
1389
|
+
|
|
1390
|
+
```typescript
|
|
1391
|
+
const result = await cdp.endUser.signEvmMessage({
|
|
1392
|
+
userId: "user-123",
|
|
1393
|
+
address: "0x1234...",
|
|
1394
|
+
message: "Hello, World!",
|
|
1395
|
+
});
|
|
1396
|
+
console.log(result.signature);
|
|
1397
|
+
|
|
1398
|
+
// Or using the EndUser object
|
|
1399
|
+
const result = await endUser.signEvmMessage({
|
|
1400
|
+
message: "Hello, World!",
|
|
1401
|
+
});
|
|
1402
|
+
console.log(result.signature);
|
|
1403
|
+
```
|
|
1404
|
+
|
|
1405
|
+
#### Sign EVM Typed Data (EIP-712)
|
|
1406
|
+
|
|
1407
|
+
```typescript
|
|
1408
|
+
const result = await cdp.endUser.signEvmTypedData({
|
|
1409
|
+
userId: "user-123",
|
|
1410
|
+
address: "0x1234...",
|
|
1411
|
+
typedData: {
|
|
1412
|
+
domain: { name: "Example" },
|
|
1413
|
+
types: { Message: [{ name: "content", type: "string" }] },
|
|
1414
|
+
primaryType: "Message",
|
|
1415
|
+
message: { content: "Hello" },
|
|
1416
|
+
},
|
|
1417
|
+
});
|
|
1418
|
+
console.log(result.signature);
|
|
1419
|
+
|
|
1420
|
+
// Or using the EndUser object
|
|
1421
|
+
const result = await endUser.signEvmTypedData({
|
|
1422
|
+
typedData: {
|
|
1423
|
+
domain: { name: "Example" },
|
|
1424
|
+
types: { Message: [{ name: "content", type: "string" }] },
|
|
1425
|
+
primaryType: "Message",
|
|
1426
|
+
message: { content: "Hello" },
|
|
1427
|
+
},
|
|
1428
|
+
});
|
|
1429
|
+
console.log(result.signature);
|
|
1430
|
+
```
|
|
1431
|
+
|
|
1432
|
+
### EVM Sending
|
|
1433
|
+
|
|
1434
|
+
#### Send an EVM Transaction
|
|
1435
|
+
|
|
1436
|
+
```typescript
|
|
1437
|
+
const result = await cdp.endUser.sendEvmTransaction({
|
|
1438
|
+
userId: "user-123",
|
|
1439
|
+
address: "0x1234...",
|
|
1440
|
+
transaction: "0x02...", // RLP-serialized EIP-1559 transaction, hex-encoded
|
|
1441
|
+
network: "base-sepolia",
|
|
1442
|
+
});
|
|
1443
|
+
console.log(result.transactionHash);
|
|
1444
|
+
|
|
1445
|
+
// Or using the EndUser object
|
|
1446
|
+
const result = await endUser.sendEvmTransaction({
|
|
1447
|
+
transaction: "0x02...",
|
|
1448
|
+
network: "base-sepolia",
|
|
1449
|
+
});
|
|
1450
|
+
console.log(result.transactionHash);
|
|
1451
|
+
```
|
|
1452
|
+
|
|
1453
|
+
For a complete example, see [end-users/sendEvmTransaction.ts](https://github.com/coinbase/cdp-sdk/blob/main/examples/typescript/end-users/sendEvmTransaction.ts).
|
|
1454
|
+
|
|
1455
|
+
#### Send an EVM Asset
|
|
1456
|
+
|
|
1457
|
+
Send tokens (e.g. USDC) on behalf of an end user:
|
|
1458
|
+
|
|
1459
|
+
```typescript
|
|
1460
|
+
const result = await cdp.endUser.sendEvmAsset({
|
|
1461
|
+
userId: "user-123",
|
|
1462
|
+
address: "0x1234...",
|
|
1463
|
+
to: "0xabcd...",
|
|
1464
|
+
amount: "1000000",
|
|
1465
|
+
network: "base-sepolia",
|
|
1466
|
+
asset: "usdc", // optional, defaults to "usdc"
|
|
1467
|
+
useCdpPaymaster: true, // optional
|
|
1468
|
+
});
|
|
1469
|
+
console.log(result.transactionHash);
|
|
1470
|
+
|
|
1471
|
+
// Or using the EndUser object
|
|
1472
|
+
const result = await endUser.sendEvmAsset({
|
|
1473
|
+
to: "0xabcd...",
|
|
1474
|
+
amount: "1000000",
|
|
1475
|
+
network: "base-sepolia",
|
|
1476
|
+
});
|
|
1477
|
+
console.log(result.transactionHash);
|
|
1478
|
+
```
|
|
1479
|
+
|
|
1480
|
+
For a complete example, see [end-users/sendEvmAsset.ts](https://github.com/coinbase/cdp-sdk/blob/main/examples/typescript/end-users/sendEvmAsset.ts).
|
|
1481
|
+
|
|
1482
|
+
#### Send a User Operation (Smart Account)
|
|
1483
|
+
|
|
1484
|
+
Send a user operation via an end user's smart account:
|
|
1485
|
+
|
|
1486
|
+
```typescript
|
|
1487
|
+
const result = await cdp.endUser.sendUserOperation({
|
|
1488
|
+
userId: "user-123",
|
|
1489
|
+
address: "0x1234...", // smart account address
|
|
1490
|
+
network: "base-sepolia",
|
|
1491
|
+
calls: [
|
|
1492
|
+
{
|
|
1493
|
+
to: "0xabcd...",
|
|
1494
|
+
value: "0",
|
|
1495
|
+
data: "0x",
|
|
1496
|
+
},
|
|
1497
|
+
],
|
|
1498
|
+
useCdpPaymaster: true,
|
|
1499
|
+
});
|
|
1500
|
+
|
|
1501
|
+
// Or using the EndUser object (address defaults to the first smart account)
|
|
1502
|
+
const result = await endUser.sendUserOperation({
|
|
1503
|
+
network: "base-sepolia",
|
|
1504
|
+
calls: [
|
|
1505
|
+
{
|
|
1506
|
+
to: "0xabcd...",
|
|
1507
|
+
value: "0",
|
|
1508
|
+
data: "0x",
|
|
1509
|
+
},
|
|
1510
|
+
],
|
|
1511
|
+
useCdpPaymaster: true,
|
|
1512
|
+
});
|
|
1513
|
+
```
|
|
1514
|
+
|
|
1515
|
+
For a complete example, see [end-users/sendUserOperation.ts](https://github.com/coinbase/cdp-sdk/blob/main/examples/typescript/end-users/sendUserOperation.ts).
|
|
1516
|
+
|
|
1517
|
+
### EVM EIP-7702 Delegation
|
|
1518
|
+
|
|
1519
|
+
Create an EIP-7702 delegation on behalf of an end user, upgrading their EOA with smart account capabilities:
|
|
1520
|
+
|
|
1521
|
+
```typescript
|
|
1522
|
+
const result = await cdp.endUser.createEvmEip7702Delegation({
|
|
1523
|
+
userId: "user-123",
|
|
1524
|
+
address: "0x1234...",
|
|
1525
|
+
network: "base-sepolia",
|
|
1526
|
+
enableSpendPermissions: false, // optional
|
|
1527
|
+
});
|
|
1528
|
+
console.log(result.delegationOperationId);
|
|
1529
|
+
|
|
1530
|
+
// Or using the EndUser object
|
|
1531
|
+
const result = await endUser.createEvmEip7702Delegation({
|
|
1532
|
+
network: "base-sepolia",
|
|
1533
|
+
});
|
|
1534
|
+
console.log(result.delegationOperationId);
|
|
1535
|
+
```
|
|
1536
|
+
|
|
1537
|
+
For a complete example, see [end-users/createEvmEip7702Delegation.ts](https://github.com/coinbase/cdp-sdk/blob/main/examples/typescript/end-users/createEvmEip7702Delegation.ts).
|
|
1538
|
+
|
|
1539
|
+
### Solana Signing
|
|
1540
|
+
|
|
1541
|
+
#### Sign a Solana Message
|
|
1542
|
+
|
|
1543
|
+
```typescript
|
|
1544
|
+
const result = await cdp.endUser.signSolanaMessage({
|
|
1545
|
+
userId: "user-123",
|
|
1546
|
+
address: "So1ana...",
|
|
1547
|
+
message: "base64message...",
|
|
1548
|
+
});
|
|
1549
|
+
console.log(result.signature);
|
|
1550
|
+
|
|
1551
|
+
// Or using the EndUser object
|
|
1552
|
+
const result = await endUser.signSolanaMessage({
|
|
1553
|
+
message: "base64message...",
|
|
1554
|
+
});
|
|
1555
|
+
console.log(result.signature);
|
|
1556
|
+
```
|
|
1557
|
+
|
|
1558
|
+
For a complete example, see [end-users/signSolanaMessage.ts](https://github.com/coinbase/cdp-sdk/blob/main/examples/typescript/end-users/signSolanaMessage.ts).
|
|
1559
|
+
|
|
1560
|
+
#### Sign a Solana Transaction
|
|
1561
|
+
|
|
1562
|
+
```typescript
|
|
1563
|
+
const result = await cdp.endUser.signSolanaTransaction({
|
|
1564
|
+
userId: "user-123",
|
|
1565
|
+
address: "So1ana...",
|
|
1566
|
+
transaction: "base64tx...",
|
|
1567
|
+
});
|
|
1568
|
+
console.log(result.signedTransaction);
|
|
1569
|
+
|
|
1570
|
+
// Or using the EndUser object
|
|
1571
|
+
const result = await endUser.signSolanaTransaction({
|
|
1572
|
+
transaction: "base64tx...",
|
|
1573
|
+
});
|
|
1574
|
+
console.log(result.signedTransaction);
|
|
1575
|
+
```
|
|
1576
|
+
|
|
1577
|
+
### Solana Sending
|
|
1578
|
+
|
|
1579
|
+
#### Send a Solana Transaction
|
|
1580
|
+
|
|
1581
|
+
```typescript
|
|
1582
|
+
const result = await cdp.endUser.sendSolanaTransaction({
|
|
1583
|
+
userId: "user-123",
|
|
1584
|
+
address: "So1ana...",
|
|
1585
|
+
transaction: "base64tx...",
|
|
1586
|
+
network: "solana-devnet",
|
|
1587
|
+
});
|
|
1588
|
+
console.log(result.transactionSignature);
|
|
1589
|
+
|
|
1590
|
+
// Or using the EndUser object
|
|
1591
|
+
const result = await endUser.sendSolanaTransaction({
|
|
1592
|
+
transaction: "base64tx...",
|
|
1593
|
+
network: "solana-devnet",
|
|
1594
|
+
});
|
|
1595
|
+
console.log(result.transactionSignature);
|
|
1596
|
+
```
|
|
1597
|
+
|
|
1598
|
+
#### Send a Solana Asset
|
|
1599
|
+
|
|
1600
|
+
```typescript
|
|
1601
|
+
const result = await cdp.endUser.sendSolanaAsset({
|
|
1602
|
+
userId: "user-123",
|
|
1603
|
+
address: "So1ana...",
|
|
1604
|
+
to: "Recipi...",
|
|
1605
|
+
amount: "1000000",
|
|
1606
|
+
network: "solana-devnet",
|
|
1607
|
+
asset: "usdc", // optional, defaults to "usdc"
|
|
1608
|
+
createRecipientAta: true, // optional, creates recipient's associated token account
|
|
1609
|
+
});
|
|
1610
|
+
console.log(result.transactionSignature);
|
|
1611
|
+
|
|
1612
|
+
// Or using the EndUser object
|
|
1613
|
+
const result = await endUser.sendSolanaAsset({
|
|
1614
|
+
to: "Recipi...",
|
|
1615
|
+
amount: "1000000",
|
|
1616
|
+
network: "solana-devnet",
|
|
1617
|
+
});
|
|
1618
|
+
console.log(result.transactionSignature);
|
|
1619
|
+
```
|
|
1620
|
+
|
|
1621
|
+
## Webhooks
|
|
1622
|
+
|
|
1623
|
+
You can use the webhooks SDK to subscribe to on-chain and wallet events and receive notifications at a URL of your choice.
|
|
1624
|
+
|
|
1625
|
+
### Create Subscription
|
|
1626
|
+
|
|
1627
|
+
Create a webhook subscription to receive event notifications:
|
|
1628
|
+
|
|
1629
|
+
```typescript
|
|
1630
|
+
const subscription = await cdp.webhooks.createSubscription({
|
|
1631
|
+
description: "Monitor wallet transactions",
|
|
1632
|
+
eventTypes: [
|
|
1633
|
+
"wallet.transaction.pending",
|
|
1634
|
+
"wallet.transaction.confirmed",
|
|
1635
|
+
"wallet.transaction.failed",
|
|
1636
|
+
],
|
|
1637
|
+
targetUrl: "https://example.com/webhook",
|
|
1638
|
+
targetHeaders: { "X-Custom-Header": "custom-value" }, // optional
|
|
1639
|
+
isEnabled: true, // optional, defaults to true
|
|
1640
|
+
metadata: { env: "production" }, // optional
|
|
1641
|
+
});
|
|
1642
|
+
|
|
1643
|
+
console.log("Subscription ID:", subscription.subscriptionId);
|
|
1644
|
+
console.log("Secret:", subscription.secret); // use to verify webhook signatures
|
|
1645
|
+
```
|
|
1646
|
+
|
|
1647
|
+
The available wallet event types are:
|
|
1648
|
+
|
|
1649
|
+
- `wallet.transaction.created`
|
|
1650
|
+
- `wallet.transaction.broadcast`
|
|
1651
|
+
- `wallet.transaction.pending`
|
|
1652
|
+
- `wallet.transaction.replaced`
|
|
1653
|
+
- `wallet.transaction.confirmed`
|
|
1654
|
+
- `wallet.transaction.failed`
|
|
1655
|
+
- `wallet.transaction.signed`
|
|
1656
|
+
|
|
1657
|
+
For a complete working example, see [webhooks/createWebhookSubscription.ts](https://github.com/coinbase/cdp-sdk/blob/main/examples/typescript/webhooks/createWebhookSubscription.ts).
|
|
1658
|
+
|
|
1327
1659
|
## Authentication tools
|
|
1328
1660
|
|
|
1329
1661
|
This SDK also contains simple tools for authenticating REST API requests to the [Coinbase Developer Platform (CDP)](https://docs.cdp.coinbase.com/). See the [Auth README](src/auth/README.md) for more details.
|
|
@@ -8,6 +8,7 @@ exports.sendTransaction = sendTransaction;
|
|
|
8
8
|
* @param {SendTransactionOptions} options - Parameters for sending the Solana transaction.
|
|
9
9
|
* @param {string} options.network - The network to send the transaction to.
|
|
10
10
|
* @param {string} options.transaction - The base64 encoded transaction to send.
|
|
11
|
+
* @param {boolean} [options.useCdpSponsor] - Whether CDP should sponsor the transaction fees.
|
|
11
12
|
* @param {string} [options.idempotencyKey] - An idempotency key.
|
|
12
13
|
*
|
|
13
14
|
* @returns A promise that resolves to the transaction result.
|
|
@@ -17,6 +18,7 @@ exports.sendTransaction = sendTransaction;
|
|
|
17
18
|
* const signature = await sendTransaction({
|
|
18
19
|
* network: "solana-devnet",
|
|
19
20
|
* transaction: "...",
|
|
21
|
+
* useCdpSponsor: true,
|
|
20
22
|
* });
|
|
21
23
|
* ```
|
|
22
24
|
*/
|
|
@@ -24,6 +26,7 @@ async function sendTransaction(apiClient, options) {
|
|
|
24
26
|
const signature = await apiClient.sendSolanaTransaction({
|
|
25
27
|
network: options.network,
|
|
26
28
|
transaction: options.transaction,
|
|
29
|
+
useCdpSponsor: options.useCdpSponsor,
|
|
27
30
|
}, options.idempotencyKey);
|
|
28
31
|
return {
|
|
29
32
|
transactionSignature: signature.transactionSignature,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sendTransaction.js","sourceRoot":"","sources":["../../../actions/solana/sendTransaction.ts"],"names":[],"mappings":";;
|
|
1
|
+
{"version":3,"file":"sendTransaction.js","sourceRoot":"","sources":["../../../actions/solana/sendTransaction.ts"],"names":[],"mappings":";;AA+BA,0CAiBC;AAtCD;;;;;;;;;;;;;;;;;;;;GAoBG;AACI,KAAK,UAAU,eAAe,CACnC,SAA+B,EAC/B,OAA+B;IAE/B,MAAM,SAAS,GAAG,MAAM,SAAS,CAAC,qBAAqB,CACrD;QACE,OAAO,EAAE,OAAO,CAAC,OAAO;QACxB,WAAW,EAAE,OAAO,CAAC,WAAW;QAChC,aAAa,EAAE,OAAO,CAAC,aAAa;KACrC,EACD,OAAO,CAAC,cAAc,CACvB,CAAC;IAEF,OAAO;QACL,oBAAoB,EAAE,SAAS,CAAC,oBAAoB;QACpD,SAAS,EAAE,SAAS,CAAC,oBAAoB;KAC1C,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createWebhookSubscription = createWebhookSubscription;
|
|
4
|
+
/**
|
|
5
|
+
* Creates a webhook subscription for wallet transaction events.
|
|
6
|
+
*
|
|
7
|
+
* @param client - The CDP OpenAPI client.
|
|
8
|
+
* @param options - The options for creating the webhook subscription.
|
|
9
|
+
* @returns The created webhook subscription.
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* ```ts
|
|
13
|
+
* const subscription = await createWebhookSubscription(client, {
|
|
14
|
+
* description: "Monitor wallet transactions",
|
|
15
|
+
* eventTypes: [
|
|
16
|
+
* "wallet.transaction.pending",
|
|
17
|
+
* "wallet.transaction.confirmed",
|
|
18
|
+
* "wallet.transaction.failed",
|
|
19
|
+
* ],
|
|
20
|
+
* targetUrl: "https://example.com/webhook",
|
|
21
|
+
* isEnabled: true,
|
|
22
|
+
* });
|
|
23
|
+
* ```
|
|
24
|
+
*/
|
|
25
|
+
async function createWebhookSubscription(client, options) {
|
|
26
|
+
const response = await client.createWebhookSubscription({
|
|
27
|
+
description: options.description,
|
|
28
|
+
eventTypes: options.eventTypes,
|
|
29
|
+
target: {
|
|
30
|
+
url: options.targetUrl,
|
|
31
|
+
headers: options.targetHeaders,
|
|
32
|
+
},
|
|
33
|
+
isEnabled: options.isEnabled ?? true,
|
|
34
|
+
metadata: options.metadata,
|
|
35
|
+
});
|
|
36
|
+
return {
|
|
37
|
+
subscriptionId: response.subscriptionId,
|
|
38
|
+
description: response.description,
|
|
39
|
+
eventTypes: response.eventTypes,
|
|
40
|
+
targetUrl: response.target.url,
|
|
41
|
+
targetHeaders: response.target.headers,
|
|
42
|
+
isEnabled: response.isEnabled,
|
|
43
|
+
secret: response.secret,
|
|
44
|
+
createdAt: response.createdAt,
|
|
45
|
+
updatedAt: response.updatedAt,
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
//# sourceMappingURL=createWebhookSubscription.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"createWebhookSubscription.js","sourceRoot":"","sources":["../../../actions/webhooks/createWebhookSubscription.ts"],"names":[],"mappings":";;AA6EA,8DA0BC;AA/CD;;;;;;;;;;;;;;;;;;;;GAoBG;AACI,KAAK,UAAU,yBAAyB,CAC7C,MAA4B,EAC5B,OAAyC;IAEzC,MAAM,QAAQ,GAAG,MAAM,MAAM,CAAC,yBAAyB,CAAC;QACtD,WAAW,EAAE,OAAO,CAAC,WAAW;QAChC,UAAU,EAAE,OAAO,CAAC,UAAU;QAC9B,MAAM,EAAE;YACN,GAAG,EAAE,OAAO,CAAC,SAAS;YACtB,OAAO,EAAE,OAAO,CAAC,aAAa;SAC/B;QACD,SAAS,EAAE,OAAO,CAAC,SAAS,IAAI,IAAI;QACpC,QAAQ,EAAE,OAAO,CAAC,QAAQ;KAC3B,CAAC,CAAC;IAEH,OAAO;QACL,cAAc,EAAE,QAAQ,CAAC,cAAc;QACvC,WAAW,EAAE,QAAQ,CAAC,WAAW;QACjC,UAAU,EAAE,QAAQ,CAAC,UAAU;QAC/B,SAAS,EAAE,QAAQ,CAAC,MAAM,CAAC,GAAG;QAC9B,aAAa,EAAE,QAAQ,CAAC,MAAM,CAAC,OAAO;QACtC,SAAS,EAAE,QAAQ,CAAC,SAAS;QAC7B,MAAM,EAAE,QAAQ,CAAC,MAAM;QACvB,SAAS,EAAE,QAAQ,CAAC,SAAS;QAC7B,SAAS,EAAE,QAAQ,CAAC,SAAS;KAC9B,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createWebhookSubscription = void 0;
|
|
4
|
+
var createWebhookSubscription_js_1 = require("./createWebhookSubscription.js");
|
|
5
|
+
Object.defineProperty(exports, "createWebhookSubscription", { enumerable: true, get: function () { return createWebhookSubscription_js_1.createWebhookSubscription; } });
|
|
6
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../actions/webhooks/index.ts"],"names":[],"mappings":";;;AAAA,+EAKwC;AAJtC,yIAAA,yBAAyB,OAAA"}
|
package/_cjs/client/cdp.js
CHANGED
|
@@ -8,6 +8,7 @@ const endUser_js_1 = require("./end-user/endUser.js");
|
|
|
8
8
|
const evm_js_1 = require("./evm/evm.js");
|
|
9
9
|
const policies_js_1 = require("./policies/policies.js");
|
|
10
10
|
const solana_js_1 = require("./solana/solana.js");
|
|
11
|
+
const webhooks_js_1 = require("./webhooks/webhooks.js");
|
|
11
12
|
/**
|
|
12
13
|
* The main client for interacting with the CDP API.
|
|
13
14
|
*/
|
|
@@ -20,6 +21,8 @@ class CdpClient {
|
|
|
20
21
|
policies;
|
|
21
22
|
/** Namespace containing all end user methods. */
|
|
22
23
|
endUser;
|
|
24
|
+
/** Namespace containing all webhook methods. */
|
|
25
|
+
webhooks;
|
|
23
26
|
/**
|
|
24
27
|
* The CdpClient is the main class for interacting with the CDP API.
|
|
25
28
|
*
|
|
@@ -35,7 +38,6 @@ class CdpClient {
|
|
|
35
38
|
* CDP_API_KEY_ID=your-api-key-id
|
|
36
39
|
* CDP_API_KEY_SECRET=your-api-key-secret
|
|
37
40
|
* CDP_WALLET_SECRET=your-wallet-secret
|
|
38
|
-
* CDP_PROJECT_ID=your-project-id
|
|
39
41
|
* ```
|
|
40
42
|
*
|
|
41
43
|
* Or passed as options to the constructor:
|
|
@@ -45,7 +47,6 @@ class CdpClient {
|
|
|
45
47
|
* apiKeyId: "your-api-key-id",
|
|
46
48
|
* apiKeySecret: "your-api-key-secret",
|
|
47
49
|
* walletSecret: "your-wallet-secret",
|
|
48
|
-
* projectId: "your-project-id",
|
|
49
50
|
* });
|
|
50
51
|
* ```
|
|
51
52
|
*
|
|
@@ -67,7 +68,6 @@ We recommend using https://github.com/Schniz/fnm for managing your Node.js versi
|
|
|
67
68
|
const apiKeyId = options.apiKeyId ?? process.env.CDP_API_KEY_ID ?? process.env.CDP_API_KEY_NAME;
|
|
68
69
|
const apiKeySecret = options.apiKeySecret ?? process.env.CDP_API_KEY_SECRET;
|
|
69
70
|
const walletSecret = options.walletSecret ?? process.env.CDP_WALLET_SECRET;
|
|
70
|
-
const projectId = options.projectId ?? process.env.CDP_PROJECT_ID;
|
|
71
71
|
if (!apiKeyId || !apiKeySecret) {
|
|
72
72
|
throw new Error(`
|
|
73
73
|
\nMissing required CDP Secret API Key configuration parameters.
|
|
@@ -114,7 +114,8 @@ For more information, see: https://github.com/coinbase/cdp-sdk/blob/main/typescr
|
|
|
114
114
|
this.evm = new evm_js_1.EvmClient();
|
|
115
115
|
this.solana = new solana_js_1.SolanaClient();
|
|
116
116
|
this.policies = new policies_js_1.PoliciesClient();
|
|
117
|
-
this.endUser = new endUser_js_1.
|
|
117
|
+
this.endUser = new endUser_js_1.EndUserClient();
|
|
118
|
+
this.webhooks = new webhooks_js_1.WebhooksClient();
|
|
118
119
|
}
|
|
119
120
|
}
|
|
120
121
|
exports.CdpClient = CdpClient;
|
package/_cjs/client/cdp.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cdp.js","sourceRoot":"","sources":["../../client/cdp.ts"],"names":[],"mappings":";;;AAAA,kDAA4C;AAC5C,yDAA8D;AAC9D,8CAAwC;AACxC,
|
|
1
|
+
{"version":3,"file":"cdp.js","sourceRoot":"","sources":["../../client/cdp.ts"],"names":[],"mappings":";;;AAAA,kDAA4C;AAC5C,yDAA8D;AAC9D,8CAAwC;AACxC,sDAAsD;AACtD,yCAAyC;AACzC,wDAAwD;AACxD,kDAAkD;AAClD,wDAAwD;AAexD;;GAEG;AACH,MAAa,SAAS;IACpB,4CAA4C;IACrC,GAAG,CAAY;IAEtB,+CAA+C;IACxC,MAAM,CAAe;IAE5B,iDAAiD;IAC1C,QAAQ,CAAiB;IAEhC,iDAAiD;IAC1C,OAAO,CAAgB;IAE9B,gDAAgD;IACzC,QAAQ,CAAiB;IAEhC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OAkCG;IACH,YAAY,UAA4B,EAAE;QACxC,IAAI,MAAM,CAAC,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC;YACrD,MAAM,IAAI,KAAK,CACb;kBACU,OAAO,CAAC,QAAQ,CAAC,IAAI;;SAE9B,CACF,CAAC;QACJ,CAAC;QAED,MAAM,QAAQ,GAAG,OAAO,CAAC,QAAQ,IAAI,OAAO,CAAC,GAAG,CAAC,cAAc,IAAI,OAAO,CAAC,GAAG,CAAC,gBAAgB,CAAC;QAChG,MAAM,YAAY,GAAG,OAAO,CAAC,YAAY,IAAI,OAAO,CAAC,GAAG,CAAC,kBAAkB,CAAC;QAC5E,MAAM,YAAY,GAAG,OAAO,CAAC,YAAY,IAAI,OAAO,CAAC,GAAG,CAAC,iBAAiB,CAAC;QAE3E,IAAI,CAAC,QAAQ,IAAI,CAAC,YAAY,EAAE,CAAC;YAC/B,MAAM,IAAI,KAAK,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA4BrB,CAAC,CAAC;QACC,CAAC;QAED,2BAAgB,CAAC,SAAS,CAAC;YACzB,GAAG,OAAO;YACV,QAAQ;YACR,YAAY;YACZ,YAAY;YACZ,MAAM,EAAE,KAAK;YACb,aAAa,EAAE,oBAAO;SACvB,CAAC,CAAC;QAEH,IACE,OAAO,CAAC,GAAG,CAAC,2BAA2B,KAAK,MAAM;YAClD,OAAO,CAAC,GAAG,CAAC,0BAA0B,KAAK,MAAM,EACjD,CAAC;YACD,wBAAS,CAAC,UAAU,GAAG,QAAQ,CAAC;QAClC,CAAC;QAED,IAAI,CAAC,GAAG,GAAG,IAAI,kBAAS,EAAE,CAAC;QAC3B,IAAI,CAAC,MAAM,GAAG,IAAI,wBAAY,EAAE,CAAC;QACjC,IAAI,CAAC,QAAQ,GAAG,IAAI,4BAAc,EAAE,CAAC;QACrC,IAAI,CAAC,OAAO,GAAG,IAAI,0BAAa,EAAE,CAAC;QACnC,IAAI,CAAC,QAAQ,GAAG,IAAI,4BAAc,EAAE,CAAC;IACvC,CAAC;CACF;AAvHD,8BAuHC"}
|