Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

coinbase-sdk v0.0.2 #22

Merged
merged 17 commits into from
Apr 30, 2024
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
Binary file removed .DS_Store
Binary file not shown.
27 changes: 27 additions & 0 deletions .github/workflows/e2e_test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
name: Run End-To-End Tests

on: [pull_request]

jobs:
test:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2

- name: Set up Ruby
uses: ruby/setup-ruby@v1
with:
ruby-version: 2.7

- name: Install dependencies
run: |
gem install bundler -v 2.4.22
bundle install --jobs 4 --retry 3

- name: Run e2e tests
env:
API_KEY_NAME: ${{ secrets.API_KEY_NAME }}
API_KEY_PRIVATE_KEY: ${{ secrets.API_KEY_PRIVATE_KEY }}
WALLET_DATA: ${{ secrets.WALLET_DATA }}
run: bundle exec rspec spec/e2e/production.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Run Tests
name: Run Unit Tests

on: [pull_request]

Expand All @@ -19,5 +19,5 @@ jobs:
gem install bundler -v 2.4.22
bundle install --jobs 4 --retry 3

- name: Run tests
- name: Run unit tests
run: bundle exec rake test
6 changes: 4 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
Gemfile.lock
coinbase_cloud_api_key.json
.yardoc
.yardoc
lib/**/.DS_Store
.idea
.DS_Store
7 changes: 7 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,16 @@ AllCops:
NewCops: disable
SuggestExtensions: false
TargetRubyVersion: 2.7
Exclude:
# Exclude autogenerated files.
- 'lib/coinbase/client.rb'
- 'lib/coinbase/client/**/*'
# Tests can be long.
Metrics/BlockLength:
Enabled: false
# Classes can be long.
Metrics/ClassLength:
Max: 1000
Metrics/MethodLength:
Max: 50
# Methods can have many parameters.
Expand Down
19 changes: 18 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,29 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## Unreleased

- Faucet
- Trade
- Individual private key export
- Allow disabling debug tracing
- Error specifications

## [0.0.2] - 2024-05-01

### Added

- Configuration via Config object
- API Key-based authentication
- API clients to use server-side architecture
- User object and default_user
- Send and receive ERC-20s

## [0.0.1] - 2024-04-19

Initial release of the Coinbase Ruby SDK. Purely client-side implementation.

### Added

- Wallet creation and export
- Address creation
- Send and receive ETH
- Supported networks: Base Sepolia
- Supported networks: Base Sepolia
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
.PHONY: format
format:
bundle exec rubocop -a
bundle exec rubocop -A

.PHONY: lint
lint:
Expand Down
93 changes: 55 additions & 38 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,17 @@ one asset into another.
The SDK currently supports Customer-custodied Wallets on the Base Sepolia test network.

**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.


## Documentation
[Click here for full SDK documentation](https://coinbase.github.io/coinbase-sdk-ruby/)

- [Platform API Documentation](https://docs.cdp.coinbase.com/platform-apis/docs/welcome)
- [Ruby SDK Documentation](https://coinbase.github.io/coinbase-sdk-ruby/)

## Installation

Expand Down Expand Up @@ -65,61 +66,75 @@ require 'coinbase'

### Initialization

The SDK requires a Base Sepolia RPC node, and uses the public instance (https://sepolia.base.org) by default.
This instance is rate-limited, but you can also provision your own on the
[Coinbase Developer Platform](https://portal.cloud.coinbase.com/products/base).
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 `configure` method:

```ruby
api_key_name = 'Copy your API Key name here.'
api_key_private_key = 'Copy your API Key\'s private key here.'

You can configure the SDK with your Base Sepolia RPC node by copying your node URL from the CDP portal
and setting the following:
Coinbase.configure do |config|
config.api_key_name = api_key_name
config.api_key_private_key = api_key_private_key
end
```

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

```ruby
Coinbase.base_sepolia_rpc_url = 'https://api.developer.coinbase.com/rpc/v1/base/your-node-id'
u = Coinbase.default_user
```

### Wallets and Addresses

A Wallet is a collection of Addresses on the Base Sepolia Network, which can be used to send and receive crypto.
### Wallets, Addresses, and Transfers

The SDK provides customer-custodied wallets, which means that you are responsible for securely storing the data required
to re-create wallets. The following code snippet demonstrates this:
Now, create a Wallet from the User. Wallets are created with a single default Address.

```ruby
# Create a Wallet with one Address by default.
w1 = Coinbase::Wallet.new
w1 = u.create_wallet
```

# Export the data required to re-create the wallet.
data = w1.export
Next, view the default Address of your Wallet. You will need this default Address in order to fund the Wallet for your first Transfer.

# At this point, you should implement your own "store" method to securely persist
# the data required to re-create the wallet at a later time.
store(data)
```ruby
# A Wallet has a default Address.
a = w1.default_address
a.to_s
```

# The wallet can be re-created using the exported data.
# w2 will be equivalent to w1.
w2 = Wallet.new(seed: data.seed, address_count: data.address_count)
Wallets do not have funds on them to start. In order to fund the Address, you will need to send funds to the Wallet you generated above. If you don't have testnet funds, get funds from a [faucet](https://docs.base.org/docs/tools/network-faucets/).

```ruby
# Create a new Wallet to transfer funds to.
# Then, we can transfer 0.00001 ETH out of the Wallet to another Wallet.
w2 = u.create_wallet
w1.transfer(0.00001, :eth, w2).wait!
```

### Transfers
### Re-Instantiating Wallets

The following creates an in-memory wallet. After the wallet is funded with ETH, it transfers 0.00001 ETH to a different wallet.
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.

```ruby
# Wallets are self-custodial with in-memory key management on Base Sepolia.
# This should NOT be used in mainnet with real funds.
w1 = Coinbase::Wallet.new
# Optional: Create a new Wallet if you do not already have one.
# Export the data required to re-instantiate the Wallet.
w3 = u.create_wallet
data = w3.export
```

# A wallet has a default address.
a = w1.default_address
a.to_s
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.

# At this point, fund the wallet out-of-band.
# Then, we can transfer 0.00001 ETH out of the wallet to another wallet.
w2 = Coinbase::Wallet.new
```ruby
# At this point, you should implement your own "store" method to securely persist
# the data required to re-instantiate the Wallet at a later time.
store(data)
```

# We wait for the transfer to complete.
# Base Sepolia is fast, so it should take only a few seconds.
w1.transfer(0.00001, :eth, w2).wait!
The below code demonstrates how to re-instantiate a Wallet from the data export.

```ruby
# The Wallet can be re-instantiated using the exported data.
# w2 will be equivalent to w1.
w4 = u.import_wallet(data)
```

## Development
Expand All @@ -134,6 +149,7 @@ RUBY_CFLAGS=-DUSE_FFI_CLOSURE_ALLOC rbenv install 2.7.0
```

### Set-up

Clone the repo by running:

```bash
Expand Down Expand Up @@ -174,6 +190,7 @@ make lint
```

### Testing

To run all tests, run:

```bash
Expand Down Expand Up @@ -201,4 +218,4 @@ To generate documentation from the Ruby comments, run:

```bash
make docs
```
```
9 changes: 6 additions & 3 deletions coinbase.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

Gem::Specification.new do |spec|
spec.name = 'coinbase-sdk'
spec.version = '0.0.1'
spec.version = '0.0.2'
spec.authors = ['Yuga Cohler']
spec.files = Dir['lib/**/*.rb']
spec.summary = 'Coinbase Ruby SDK'
Expand All @@ -15,12 +15,15 @@ Gem::Specification.new do |spec|

spec.metadata['rubygems_mfa_required'] = 'true'

spec.add_runtime_dependency 'bigdecimal'
spec.add_runtime_dependency 'eth'
spec.add_runtime_dependency 'faraday'
spec.add_runtime_dependency 'faraday-multipart'
spec.add_runtime_dependency 'jimson'
spec.add_runtime_dependency 'jwt'
spec.add_runtime_dependency 'marcel'
spec.add_runtime_dependency 'money-tree'
spec.add_runtime_dependency 'securerandom'

spec.add_development_dependency 'dotenv'
spec.add_development_dependency 'pry'
spec.add_development_dependency 'rake'
spec.add_development_dependency 'rspec'
Expand Down
Loading
Loading