Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 0 additions & 31 deletions CAPABILITIES.md

This file was deleted.

4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

## Unreleased

## [0.1.1] - 2024-08-27

- Fixed a bug where `listHistoricalBalances` method was parsing conventional ETH balances instead of atomic units

## [0.1.0] - 2024-08-22

### Added
Expand Down
18 changes: 8 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,9 @@

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.

The SDK currently supports Customer-custodied Wallets on the Base Sepolia test network.
The SDK supports various verbs on Developer-custodied Wallets across multiple networks, as documented [here](https://docs.cdp.coinbase.com/cdp-sdk/docs/networks).

**NOTE: The Coinbase SDK is currently in Alpha. The SDK:**

- **may make backwards-incompatible changes between releases**
- **should not be used on Mainnet (i.e. with real funds)**

Currently, the SDK is intended for use on testnet for quick bootstrapping of crypto wallets at hackathons, code academies, and other development settings.
**CDP SDK v0 is a pre-alpha release, which means that the APIs and SDK methods are subject to change. We will continuously release updates to support new capabilities and improve the developer experience.**

## Documentation

Expand Down Expand Up @@ -154,15 +149,17 @@ console.log(`Faucet transaction: ${faucetTransaction}`);
// 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 Wallet.create();
const transfer = await wallet.createTransfer({ amount: 0.00001, assetId: Coinbase.assets.Eth, destination: anotherWallet });
let transfer = await wallet.createTransfer({ amount: 0.00001, assetId: Coinbase.assets.Eth, destination: anotherWallet });
transfer = await transfer.wait();
```


### Gasless USDC Transfers

To transfer USDC without needing to hold ETH for gas, you can use the `createTransfer` method with the `gasless` option set to `true`.
```typescript
const transfer = await wallet.createTransfer({ amount: 0.00001, assetId: Coinbase.assets.Usdc, destination: anotherWallet, gasless: true });
let transfer = await wallet.createTransfer({ amount: 0.00001, assetId: Coinbase.assets.Usdc, destination: anotherWallet, gasless: true });
transfer = await transfer.wait();
```


Expand All @@ -178,8 +175,9 @@ console.log(`Wallet successfully created: ${mainnetWallet}`);

// Trade 0.00001 ETH to USDC
let trade = await wallet.createTrade({ amount: 0.00001, fromAssetId: Coinbase.assets.Eth, toAssetId: Coinbase.assets.Usdc });
trade = await trade.wait();

console.log(`Second trade successfully completed: ${trade}`);
console.log(`Trade successfully completed: ${trade}`);
```

### Re-Instantiating Wallets
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"license": "ISC",
"description": "Coinbase Platform SDK",
"repository": "https://github.com/coinbase/coinbase-sdk-nodejs",
"version": "0.1.0",
"version": "0.1.1",
"main": "dist/index.js",
"types": "dist/index.d.ts",
"scripts": {
Expand Down
11 changes: 0 additions & 11 deletions src/coinbase/balance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,15 +52,4 @@ export class Balance {
asset,
);
}

/**
* Converts a BalanceModel of which the amount is in the most common denomination such as ETH, BTC, etc.
*
* @param {BalanceModel} model - The balance model object.
* @returns {Balance} The Balance object.
*/
public static fromModelWithAmountInWholeUnits(model: BalanceModel): Balance {
const asset = Asset.fromModel(model.asset);
return new Balance(new Decimal(model.amount), asset.getAssetId(), asset);
}
}
4 changes: 2 additions & 2 deletions src/coinbase/staking_balance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ export class StakingBalance {
* @returns The Balance.
*/
public bondedStake(): Balance {
return Balance.fromModelWithAmountInWholeUnits(this.model.bonded_stake);
return Balance.fromModel(this.model.bonded_stake);
}

/**
Expand All @@ -79,7 +79,7 @@ export class StakingBalance {
* @returns The Balance.
*/
public unbondedBalance(): Balance {
return Balance.fromModelWithAmountInWholeUnits(this.model.unbonded_balance);
return Balance.fromModel(this.model.unbonded_balance);
}

/**
Expand Down
23 changes: 0 additions & 23 deletions src/tests/balance_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,27 +49,4 @@ describe("Balance", () => {
expect(balance.assetId).toBe(Coinbase.assets.Eth);
});
});

describe(".fromModelWithAmountInWholeUnits", () => {
const amount = new Decimal(32);
const balanceModel: BalanceModel = {
asset: {
asset_id: Coinbase.assets.Eth,
network_id: Coinbase.networks.BaseSepolia,
decimals: 18,
contract_address: "0x",
},
amount: "32",
};

const balance = Balance.fromModelWithAmountInWholeUnits(balanceModel);

it("returns a new Balance object with the correct amount", () => {
expect(balance.amount).toEqual(amount);
});

it("returns a new Balance object with the correct asset_id", () => {
expect(balance.assetId).toBe(Coinbase.assets.Eth);
});
});
});
4 changes: 2 additions & 2 deletions src/tests/staking_historical_balance_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@ describe("StakingBalance", () => {
};

const bondedStake = {
amount: "32",
amount: "32000000000000000000",
asset: asset,
};
const unbondedBalance = {
amount: "2",
amount: "2000000000000000000",
asset: asset,
};

Expand Down
8 changes: 4 additions & 4 deletions src/tests/wallet_address_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -368,15 +368,15 @@ describe("WalletAddress", () => {
address: newAddress.address_id,
date: "2024-05-01",
bonded_stake: {
amount: "32",
amount: "32000000000000000000",
asset: {
asset_id: Coinbase.assets.Eth,
network_id: Coinbase.networks.EthereumHolesky,
decimals: 18,
},
},
unbonded_balance: {
amount: "2",
amount: "2000000000000000000",
asset: {
asset_id: Coinbase.assets.Eth,
network_id: Coinbase.networks.EthereumHolesky,
Expand All @@ -389,15 +389,15 @@ describe("WalletAddress", () => {
address: newAddress.address_id,
date: "2024-05-02",
bonded_stake: {
amount: "34",
amount: "34000000000000000000",
asset: {
asset_id: Coinbase.assets.Eth,
network_id: Coinbase.networks.EthereumHolesky,
decimals: 18,
},
},
unbonded_balance: {
amount: "3",
amount: "3000000000000000000",
asset: {
asset_id: Coinbase.assets.Eth,
network_id: Coinbase.networks.EthereumHolesky,
Expand Down
8 changes: 4 additions & 4 deletions src/tests/wallet_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -200,15 +200,15 @@ describe("Wallet Class", () => {
address: addressID,
date: "2024-05-01",
bonded_stake: {
amount: "32",
amount: "32000000000000000000",
asset: {
asset_id: Coinbase.assets.Eth,
network_id: Coinbase.networks.EthereumHolesky,
decimals: 18,
},
},
unbonded_balance: {
amount: "2",
amount: "2000000000000000000",
asset: {
asset_id: Coinbase.assets.Eth,
network_id: Coinbase.networks.EthereumHolesky,
Expand All @@ -221,15 +221,15 @@ describe("Wallet Class", () => {
address: addressID,
date: "2024-05-02",
bonded_stake: {
amount: "32",
amount: "32000000000000000000",
asset: {
asset_id: Coinbase.assets.Eth,
network_id: Coinbase.networks.EthereumHolesky,
decimals: 18,
},
},
unbonded_balance: {
amount: "2",
amount: "2000000000000000000",
asset: {
asset_id: Coinbase.assets.Eth,
network_id: Coinbase.networks.EthereumHolesky,
Expand Down