You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+53-14Lines changed: 53 additions & 14 deletions
Original file line number
Diff line number
Diff line change
@@ -1,9 +1,6 @@
1
1
# Coinbase Node.js SDK
2
2
3
-
The Coinbase Node.js SDK enables the simple integration of crypto into your app.
4
-
By calling Coinbase's Platform APIs, the SDK allows you to provision crypto wallets,
5
-
send crypto into/out of those wallets, track wallet balances, and trade crypto from
6
-
one asset into another.
3
+
The Coinbase Node.js SDK enables the simple integration of crypto into your app. By calling Coinbase's Platform APIs, the SDK allows you to provision crypto wallets, send crypto into/out of those wallets, track wallet balances, and trade crypto from one asset into another.
7
4
8
5
The SDK currently supports Customer-custodied Wallets on the Base Sepolia test network.
9
6
@@ -12,8 +9,7 @@ The SDK currently supports Customer-custodied Wallets on the Base Sepolia test n
12
9
-**may make backwards-incompatible changes between releases**
13
10
-**should not be used on Mainnet (i.e. with real funds)**
14
11
15
-
Currently, the SDK is intended for use on testnet for quick bootstrapping of crypto wallets at
16
-
hackathons, code academies, and other development settings.
12
+
Currently, the SDK is intended for use on testnet for quick bootstrapping of crypto wallets at hackathons, code academies, and other development settings.
After running `npx ts-node` to start the REPL, you can import the SDK as follows:
39
35
40
36
```typescript
41
-
import { Coinbase } from'@coinbase/coinbase-sdk';
37
+
import { Coinbase } from"@coinbase/coinbase-sdk";
42
38
```
39
+
43
40
### Requirements
44
41
45
42
- Node.js 18 or higher
@@ -51,18 +48,17 @@ import { Coinbase } from '@coinbase/coinbase-sdk';
51
48
To start, [create a CDP API Key](https://portal.cdp.coinbase.com/access/api). Then, initialize the Platform SDK by passing your API Key name and API Key's private key via the `Coinbase` constructor:
52
49
53
50
```typescript
54
-
const apiKeyName ='Copy your API Key name here.';
51
+
const apiKeyName ="Copy your API Key name here.";
55
52
56
-
const apiKeyPrivateKey ='Copy your API Key\'s private key here.';
53
+
const apiKeyPrivateKey ="Copy your API Key's private key here.";
const transfer =awaitwallet.createTransfer(0.00001, Coinbase.assetList.Eth, anotherWallet);
106
102
```
107
103
104
+
### Re-Instantiating Wallets
105
+
106
+
The SDK creates Wallets with developer managed keys, which means you are responsible for securely storing the keys required to re-instantiate Wallets. The below code walks you through how to export a Wallets and store it in a secure location.
107
+
108
+
```typescript
109
+
// Export the data required to re-instantiate the Wallet.
110
+
const data =wallet.export();
111
+
```
112
+
113
+
In order to persist the data for the Wallet, you will need to implement a store method to store the data export in a secure location. If you do not store the Wallet in a secure location you will lose access to the Wallet and all of the funds on it.
114
+
115
+
```typescript
116
+
// At this point, you should implement your own "store" method to securely persist
117
+
// the data required to re-instantiate the Wallet at a later time.
118
+
awaitstore(data);
119
+
```
120
+
121
+
For convenience during testing, we provide a `saveWallet` method that stores the Wallet data in your local file system. This is an insecure method of storing wallet seeds and should only be used for development purposes.
122
+
123
+
```typescript
124
+
user.saveWallet(wallet);
125
+
```
126
+
127
+
To encrypt the saved data, set encrypt to true. Note that your CDP API key also serves as the encryption key for the data persisted locally. To re-instantiate wallets with encrypted data, ensure that your SDK is configured with the same API key when invoking `saveWallet` and `loadWallets`.
128
+
129
+
```typescript
130
+
user.saveWallet(wallet, true);
131
+
```
132
+
133
+
The below code demonstrates how to re-instantiate a Wallet from the data export.
134
+
135
+
```typescript
136
+
// The Wallet can be re-instantiated using the exported data.
137
+
const importedWallet =awaituser.import(data);
138
+
```
139
+
140
+
To import Wallets that were persisted to your local file system using `saveWallet`, use the below code.
141
+
142
+
```typescript
143
+
// The Wallet can be re-instantiated using the exported data.
144
+
const wallets =awaituser.loadWallets();
145
+
const reinitWallet =wallets[wallet.getId()];
146
+
```
147
+
108
148
## Development
109
149
110
150
### Node.js Version
@@ -155,8 +195,7 @@ npx jest ./src/coinbase/tests/wallet_test.ts
155
195
156
196
### REPL
157
197
158
-
The repository is equipped with a REPL to allow developers to play with the SDK. To start
159
-
it, run:
198
+
The repository is equipped with a REPL to allow developers to play with the SDK. To start it, run:
0 commit comments