Skip to content

Commit

Permalink
Merge pull request #176 from coinbase/v0.1.0
Browse files Browse the repository at this point in the history
V0.1.0 SDK Release
  • Loading branch information
alex-stone authored Aug 22, 2024
2 parents 9be2165 + 451c638 commit ec60f5a
Show file tree
Hide file tree
Showing 53 changed files with 2,424 additions and 1,279 deletions.
26 changes: 11 additions & 15 deletions CAPABILITIES.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,24 +6,20 @@ those capabilities for the NodeJS SDK:
## Developer Wallets

| Concept | Base-Sepolia | Base-Mainnet | Ethereum-Holesky | Ethereum-Mainnet |
| ------------- | :----------: | :----------: | :--------------: | :--------------: |
| Addresses |||||
| Send |||||
| Trade |||||
| Faucet |||||
| Server-Signer |||||
| Stake [^1] |||||

[^1]: Currently only available for Shared ETH Staking.
|---------------|:------------:|:------------:|:----------------:|:----------------:|
| Addresses |||||
| Send |||||
| Trade |||||
| Faucet |||||
| Server-Signer |||||
| Stake |||||

## End-User Wallets

| Concept | Base-Sepolia | Base-Mainnet | Ethereum-Holesky | Ethereum-Mainnet |
| ------------------ | :----------: | :----------: | :--------------: | :--------------: |
| External Addresses |||||
| Stake [^2] |||||

[^2]: Dedicated ETH Staking is currently only available on Testnet (Ethereum-Holesky).
|--------------------|:------------:|:------------:|:----------------:|:----------------:|
| External Addresses |||||
| Stake |||||

## Testnet vs. Mainnet

Expand All @@ -32,4 +28,4 @@ The Coinbase SDK supports both testnets and mainnets.
- Testnets are for building and testing applications. Funds are not real, and you can get test currencies from a faucet.
- Mainnet is where the funds, contracts and applications are real.

Wallets, assets, etc, cannot be moved from testnet to mainnet (or vice versa).
Wallets, assets, etc. cannot be moved from testnet to mainnet (or vice versa).
31 changes: 30 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,34 @@
# Coinbase Node.js SDK Changelog

## Unreleased

## [0.1.0] - 2024-08-22

### Added

- Add `listHistoricalBalances` wallet method, that lists the historical balances for the wallet's default address.
- Add toAddressId() method to Transaction class

### Removed

- Remove user concept from the SDK
- Remove "pending" status from StakingOperationStatusEnum
- Add staking operation class helper methods like `isTerminalState`, `isFailedState` and `isCompleteState`.
- Add validator status enum

### Changed

- The `createTransfer` and `createTrade` functions no longer wait for the transactions to confirm or
fail on-chain.
- Now they return a `Transfer` and `Trade` object respectively, which support the `wait`
function, e.g. `await transfer.wait()`.
- This ensures that the developer has a reference to the object in case there is a timeout while
waiting to land on-chain.
- Update `reload()` method to work with both External and Wallet address.
- Update `createStakingOperation` logic to make sure we only pull in newer unsigned txs from the server.
This is especially important for External Address use-case where tx signing and broadcast status is maintained on client side, and we risk overwriting the existing txs.
- Increase default timeout for `createStakingOperation` to 10 min.

## [0.0.16] - 2024-08-14

### Added
Expand All @@ -8,7 +37,7 @@
- Support for retrieving historical staking balances information
- USD value conversion details to the StakingReward object
- Gasless USDC Sends
- Support for Etherum-Mainnet and Polygon-Mainnet
- Support for Ethereum-Mainnet and Polygon-Mainnet

## [0.0.15] - 2024-08-12

Expand Down
36 changes: 20 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ nvm use node

Optional: Initialize the npm

This command initializes a new npm project with default settings and configures it to use ES modules by setting the type field to "module" in the package.json file.
This command initializes a new npm project with default settings and configures it to use ES modules by setting the type field to "module" in the package.json file.

```bash
npm init -y; npm pkg set type="module"
Expand All @@ -68,13 +68,13 @@ yarn add @coinbase/coinbase-sdk
CommonJs:

```javascript
const { Coinbase } = require("@coinbase/coinbase-sdk");
const { Coinbase, Wallet } = require("@coinbase/coinbase-sdk");
```

ES modules:

```typescript
import { Coinbase } from "@coinbase/coinbase-sdk";
import { Coinbase, Wallet } from "@coinbase/coinbase-sdk";
```

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:
Expand All @@ -98,34 +98,38 @@ Another way to initialize the SDK is by sourcing the API key from the json file
const coinbase = Coinbase.configureFromJson({ filePath: "path/to/your/api-key.json" });
```

This will allow you to authenticate with the Platform APIs and get access to the default `User`.
This will allow you to authenticate with the Platform APIs.

CommonJs:

```javascript
const { Coinbase } = require("@coinbase/coinbase-sdk");
const { Coinbase, Wallet } = require("@coinbase/coinbase-sdk");
const coinbase = Coinbase.configureFromJson("path/to/your/api-key.json");
coinbase.getDefaultUser().then(user => {
console.log(user);

// List all Wallets for the CDP Project.
Wallet.listWallets().then(wallets => {
console.log(wallets);
});
```

Or using ES modules and async/await:

```typescript
import { Coinbase } from "@coinbase/coinbase-sdk";
import { Coinbase, Wallet } from "@coinbase/coinbase-sdk";
const coinbase = Coinbase.configureFromJson("path/to/your/api-key.json");
const user = await coinbase.getDefaultUser();
console.log(user);

// List all Wallets for the CDP Project.
const wallets = await Wallet.listWallets();
console.log(wallets);
```

### Wallets, Addresses, and Transfers

Now, create a Wallet from the User. Wallets are created with a single default Address.
Now, create a Wallet which will default to the Base Sepolia testnet network (if not specified).

```typescript
// Create a Wallet with one Address by default.
const wallet = await user.createWallet();
const wallet = await Wallet.create();
```

Next, view the default Address of your Wallet. You will need this default Address in order to fund the Wallet for your first Transfer.
Expand All @@ -149,7 +153,7 @@ console.log(`Faucet transaction: ${faucetTransaction}`);
```typescript
// Create a new Wallet to transfer funds to.
// Then, we can transfer 0.00001 ETH out of the Wallet to another Wallet.
const anotherWallet = await user.createWallet();
const anotherWallet = await Wallet.create();
const transfer = await wallet.createTransfer({ amount: 0.00001, assetId: Coinbase.assets.Eth, destination: anotherWallet });
```

Expand All @@ -166,7 +170,7 @@ const transfer = await wallet.createTransfer({ amount: 0.00001, assetId: Coinbas

```typescript
// Create a Wallet on `base-mainnet` to trade assets with.
let mainnetWallet = await user.createWallet({ networkId: Coinbase.networks.BaseMainnet });
let mainnetWallet = await Wallet.create({ networkId: Coinbase.networks.BaseMainnet });

console.log(`Wallet successfully created: ${mainnetWallet}`);

Expand Down Expand Up @@ -212,13 +216,13 @@ The below code demonstrates how to re-instantiate a Wallet from the data export.

```typescript
// The Wallet can be re-instantiated using the exported data.
const importedWallet = await user.importWallet(data);
const importedWallet = await Wallet.import(data);
```

To import Wallets that were persisted to your local file system using `saveSeed`, use the below code.

```typescript
const userWallet = await user.getWallet(wallet.getId());
const userWallet = await Wallet.fetch(wallet.getId());
await userWallet.loadSeed(seedFilePath);
```

Expand Down
Loading

0 comments on commit ec60f5a

Please sign in to comment.