@coinbase/cdp-sdk 1.0.1 → 1.1.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/README.md +39 -3
- package/dist/auth/utils/http.js +1 -1
- package/dist/client/cdp.d.ts +22 -5
- package/dist/client/cdp.js +56 -2
- package/package.json +5 -1
package/README.md
CHANGED
|
@@ -27,19 +27,55 @@ npm install @coinbase/cdp-sdk
|
|
|
27
27
|
|
|
28
28
|
## API Keys
|
|
29
29
|
|
|
30
|
-
To start, [create a CDP API Key](https://portal.cdp.coinbase.com/access/api). Save the `API Key ID` and `API Key Secret` for use in the SDK. You will also need to create a wallet secret in the
|
|
30
|
+
To start, [create a CDP API Key](https://portal.cdp.coinbase.com/access/api). Save the `API Key ID` and `API Key Secret` for use in the SDK. You will also need to create a wallet secret in the Portal to sign transactions.
|
|
31
31
|
|
|
32
32
|
## Usage
|
|
33
33
|
|
|
34
34
|
### Initialization
|
|
35
35
|
|
|
36
|
-
####
|
|
36
|
+
#### Load client config from shell
|
|
37
|
+
|
|
38
|
+
One option is to export your CDP API Key and Wallet Secret as environment variables:
|
|
39
|
+
|
|
40
|
+
```bash
|
|
41
|
+
export CDP_API_KEY_NAME="YOUR_API_KEY_ID"
|
|
42
|
+
export CDP_API_KEY_SECRET="YOUR_API_KEY_SECRET"
|
|
43
|
+
export CDP_WALLET_SECRET="YOUR_WALLET_SECRET"
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
Then, initialize the client:
|
|
37
47
|
|
|
38
48
|
```typescript
|
|
39
49
|
import { CdpClient } from "@coinbase/cdp-sdk";
|
|
50
|
+
|
|
51
|
+
const cdp = new CdpClient();
|
|
40
52
|
```
|
|
41
53
|
|
|
42
|
-
####
|
|
54
|
+
#### Load client config from `.env` file
|
|
55
|
+
|
|
56
|
+
Another option is to save your CDP API Key and Wallet Secret in a `.env` file:
|
|
57
|
+
|
|
58
|
+
```bash
|
|
59
|
+
touch .env
|
|
60
|
+
echo "CDP_API_KEY_NAME=YOUR_API_KEY_ID" >> .env
|
|
61
|
+
echo "CDP_API_KEY_SECRET=YOUR_API_KEY_SECRET" >> .env
|
|
62
|
+
echo "CDP_WALLET_SECRET=YOUR_WALLET_SECRET" >> .env
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
Then, load the client config from the `.env` file:
|
|
66
|
+
|
|
67
|
+
```typescript
|
|
68
|
+
import { CdpClient } from "@coinbase/cdp-sdk";
|
|
69
|
+
import dotenv from "dotenv";
|
|
70
|
+
|
|
71
|
+
dotenv.config();
|
|
72
|
+
|
|
73
|
+
const cdp = new CdpClient();
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
#### Pass the API Key and Wallet Secret to the client
|
|
77
|
+
|
|
78
|
+
Another option is to directly pass the API Key and Wallet Secret to the client:
|
|
43
79
|
|
|
44
80
|
```typescript
|
|
45
81
|
const cdp = new CdpClient({
|
package/dist/auth/utils/http.js
CHANGED
|
@@ -25,7 +25,7 @@ async function getAuthHeaders(options) {
|
|
|
25
25
|
// Add wallet auth if needed
|
|
26
26
|
if (requiresWalletAuth(options.requestMethod, options.requestPath)) {
|
|
27
27
|
if (!options.walletSecret) {
|
|
28
|
-
throw new Error("Wallet Secret not configured.
|
|
28
|
+
throw new Error("Wallet Secret not configured. Please set the CDP_WALLET_SECRET environment variable, or pass it as an option to the CdpClient constructor.");
|
|
29
29
|
}
|
|
30
30
|
const walletAuthToken = await (0, jwt_1.generateWalletJwt)({
|
|
31
31
|
walletSecret: options.walletSecret,
|
package/dist/client/cdp.d.ts
CHANGED
|
@@ -2,11 +2,11 @@ import { EvmClient } from "./evm";
|
|
|
2
2
|
import { SolanaClient } from "./solana";
|
|
3
3
|
interface CdpClientOptions {
|
|
4
4
|
/** The API key ID. */
|
|
5
|
-
apiKeyId
|
|
5
|
+
apiKeyId?: string;
|
|
6
6
|
/** The API key secret. */
|
|
7
|
-
apiKeySecret
|
|
7
|
+
apiKeySecret?: string;
|
|
8
8
|
/** The wallet secret. */
|
|
9
|
-
walletSecret
|
|
9
|
+
walletSecret?: string;
|
|
10
10
|
/** Whether to enable debugging. */
|
|
11
11
|
debugging?: boolean;
|
|
12
12
|
/** The host URL to connect to. */
|
|
@@ -30,14 +30,31 @@ export declare class CdpClient {
|
|
|
30
30
|
* - **Wallet Secret** (`walletSecret`): This secret is used specifically to authenticate requests to `POST`, and `DELETE`
|
|
31
31
|
* endpoints in the EVM and Solana Account APIs.
|
|
32
32
|
*
|
|
33
|
+
* These parameters can be set as environment variables:
|
|
34
|
+
* ```
|
|
35
|
+
* CDP_API_KEY_NAME=your-api-key-id
|
|
36
|
+
* CDP_API_KEY_SECRET=your-api-key-secret
|
|
37
|
+
* CDP_WALLET_SECRET=your-wallet-secret
|
|
38
|
+
* ```
|
|
39
|
+
*
|
|
40
|
+
* Or passed as options to the constructor:
|
|
41
|
+
*
|
|
42
|
+
* ```typescript
|
|
43
|
+
* const cdp = new CdpClient({
|
|
44
|
+
* apiKeyId: "your-api-key-id",
|
|
45
|
+
* apiKeySecret: "your-api-key-secret",
|
|
46
|
+
* walletSecret: "your-wallet-secret",
|
|
47
|
+
* });
|
|
48
|
+
* ```
|
|
49
|
+
*
|
|
33
50
|
* The CdpClient is namespaced by chain type: `evm` or `solana`.
|
|
34
51
|
*
|
|
35
52
|
* As an example, to create a new EVM account, use `cdp.evm.createAccount()`.
|
|
36
53
|
*
|
|
37
54
|
* To create a new Solana account, use `cdp.solana.createAccount()`.
|
|
38
55
|
*
|
|
39
|
-
* @param {CdpClientOptions} options - Configuration options for the CdpClient.
|
|
56
|
+
* @param {CdpClientOptions} [options] - Configuration options for the CdpClient.
|
|
40
57
|
*/
|
|
41
|
-
constructor(options
|
|
58
|
+
constructor(options?: CdpClientOptions);
|
|
42
59
|
}
|
|
43
60
|
export {};
|
package/dist/client/cdp.js
CHANGED
|
@@ -19,17 +19,71 @@ class CdpClient {
|
|
|
19
19
|
* - **Wallet Secret** (`walletSecret`): This secret is used specifically to authenticate requests to `POST`, and `DELETE`
|
|
20
20
|
* endpoints in the EVM and Solana Account APIs.
|
|
21
21
|
*
|
|
22
|
+
* These parameters can be set as environment variables:
|
|
23
|
+
* ```
|
|
24
|
+
* CDP_API_KEY_NAME=your-api-key-id
|
|
25
|
+
* CDP_API_KEY_SECRET=your-api-key-secret
|
|
26
|
+
* CDP_WALLET_SECRET=your-wallet-secret
|
|
27
|
+
* ```
|
|
28
|
+
*
|
|
29
|
+
* Or passed as options to the constructor:
|
|
30
|
+
*
|
|
31
|
+
* ```typescript
|
|
32
|
+
* const cdp = new CdpClient({
|
|
33
|
+
* apiKeyId: "your-api-key-id",
|
|
34
|
+
* apiKeySecret: "your-api-key-secret",
|
|
35
|
+
* walletSecret: "your-wallet-secret",
|
|
36
|
+
* });
|
|
37
|
+
* ```
|
|
38
|
+
*
|
|
22
39
|
* The CdpClient is namespaced by chain type: `evm` or `solana`.
|
|
23
40
|
*
|
|
24
41
|
* As an example, to create a new EVM account, use `cdp.evm.createAccount()`.
|
|
25
42
|
*
|
|
26
43
|
* To create a new Solana account, use `cdp.solana.createAccount()`.
|
|
27
44
|
*
|
|
28
|
-
* @param {CdpClientOptions} options - Configuration options for the CdpClient.
|
|
45
|
+
* @param {CdpClientOptions} [options] - Configuration options for the CdpClient.
|
|
29
46
|
*/
|
|
30
|
-
constructor(options) {
|
|
47
|
+
constructor(options = {}) {
|
|
48
|
+
const apiKeyId = options.apiKeyId ?? process.env.CDP_API_KEY_NAME;
|
|
49
|
+
const apiKeySecret = options.apiKeySecret ?? process.env.CDP_API_KEY_SECRET;
|
|
50
|
+
const walletSecret = options.walletSecret ?? process.env.CDP_WALLET_SECRET;
|
|
51
|
+
if (!apiKeyId || !apiKeySecret) {
|
|
52
|
+
throw new Error(`
|
|
53
|
+
\nMissing required CDP Secret API Key configuration parameters.
|
|
54
|
+
|
|
55
|
+
You can set them as environment variables:
|
|
56
|
+
|
|
57
|
+
CDP_API_KEY_NAME=your-api-key-id
|
|
58
|
+
CDP_API_KEY_SECRET=your-api-key-secret
|
|
59
|
+
|
|
60
|
+
You can also pass them as options to the constructor:
|
|
61
|
+
|
|
62
|
+
const cdp = new CdpClient({
|
|
63
|
+
apiKeyId: "your-api-key-id",
|
|
64
|
+
apiKeySecret: "your-api-key-secret",
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
If you're performing write operations, make sure to also set your wallet secret:
|
|
68
|
+
|
|
69
|
+
CDP_WALLET_SECRET=your-wallet-secret
|
|
70
|
+
|
|
71
|
+
This is also available as an option to the constructor:
|
|
72
|
+
|
|
73
|
+
const cdp = new CdpClient({
|
|
74
|
+
apiKeyId: "your-api-key-id",
|
|
75
|
+
apiKeySecret: "your-api-key-secret",
|
|
76
|
+
walletSecret: "your-wallet-secret",
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
For more information, see: https://github.com/coinbase/cdp-sdk/blob/main/typescript/README.md#api-keys.
|
|
80
|
+
`);
|
|
81
|
+
}
|
|
31
82
|
openapi_client_1.CdpOpenApiClient.configure({
|
|
32
83
|
...options,
|
|
84
|
+
apiKeyId,
|
|
85
|
+
apiKeySecret,
|
|
86
|
+
walletSecret,
|
|
33
87
|
source: "sdk",
|
|
34
88
|
sourceVersion: package_json_1.version,
|
|
35
89
|
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@coinbase/cdp-sdk",
|
|
3
|
-
"version": "1.0
|
|
3
|
+
"version": "1.1.0",
|
|
4
4
|
"description": "CDP SDK",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -53,6 +53,10 @@
|
|
|
53
53
|
".": {
|
|
54
54
|
"types": "./dist/index.d.ts",
|
|
55
55
|
"default": "./dist/index.js"
|
|
56
|
+
},
|
|
57
|
+
"./auth": {
|
|
58
|
+
"types": "./dist/auth/index.d.ts",
|
|
59
|
+
"default": "./dist/auth/index.js"
|
|
56
60
|
}
|
|
57
61
|
},
|
|
58
62
|
"scripts": {
|