• This repository has been archived on 03/Mar/2020
  • Stars
    star
    241
  • Rank 167,643 (Top 4 %)
  • Language
    Ruby
  • License
    Apache License 2.0
  • Created almost 12 years ago
  • Updated almost 5 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

DEPRECATED — Ruby wrapper for the Coinbase API

Coinbase Wallet Gem

Gem Version Build Status

This is the official client library for the Coinbase Wallet API v2. We provide an intuitive, stable interface to integrate Coinbase Wallet into your Ruby project.

Important: As this library is targeted for newer API v2, it requires v2 permissions (i.e. wallet:accounts:read). If you're still using v1, please use older version of this library.

Installation

Add this line to your application's Gemfile:

gem 'coinbase'

Then execute:

bundle install

Or install it yourself as:

gem install coinbase

Authentication

API Key (HMAC Client)

We provide a synchronous client based on Net::HTTP as well as a asynchronous client based on the EM-HTTP-Request gem. For most users, the synchronous client will suffice.

require 'coinbase/wallet'
client = Coinbase::Wallet::Client.new(api_key: <api key>, api_secret: <api secret>)

The primary intention of the asynchronous client is to integrate nicely with the Coinbase Exchange Gem. If your project interfaces with our Exchange as well, please consider using this. To use this interface, you must include em-http-request gem on your own.

require 'coinbase/wallet'
require 'em-http'

client = Coinbase::Wallet::AsyncClient.new(api_key: <api_key>, api_secret: <api secret>)

OAuth2 Client

We provide an OAuth client if you need access to user accounts other than your own. Currently, the gem does not handle the handshake process, and assumes you have an access token when it's initialized. The OAuth client is synchronous. Please reach out if you would like us to add an asynchronous OAuth client as well.

require 'coinbase/wallet'

# Initializing OAuthClient with both access and refresh token
client = Coinbase::Wallet::OAuthClient.new(access_token: <access token>, refresh_token: <refresh_token>)

# Initializing OAuthClient with only access token
client = Coinbase::Wallet::OAuthClient.new(access_token: <access token>)

The OAuth client provides a few extra methods to refresh and revoke the access token.

client.refresh!
client.revoke!

Protip™️: You can test OAuth2 authentication easily with Developer Access Tokens which can be created under your OAuth2 application settings. These are short lived tokens which authenticate but don't require full OAuth2 handshake to obtain.

Two factor authentication

Send money endpoint requires 2FA token in certain situations (read more here). Specific exception is thrown when this is required:

account = client.primary_account
begin
  account.send(to: '[email protected]', amount: '1', currency: "BTC")
rescue Coinbase::Client::TwoFactorRequiredError
  # Show 2FA dialog to user and collect 2FA token

  # Re-try call with `two_factor_token` param
  account.send(to: '[email protected]', amount: '1', currency: "BTC", two_factor_token: "123456")
end

Requests

We provide one method per API endpoint. Several methods require one or more identifiers to be passed as arguments. Additionally, all parameters can be appended as keyword arguements. If a required parameter is not supplied, the client will raise an error. For instance, the following call will send 100 bitcoin to the account registered with [email protected].

account = client.primary_account
account.send(to: '[email protected]', amount: 100, currency: "USD", description: 'Sending 100 bitcoin')

Pagination

Several endpoints are paginated. By default, the gem will only fetch the first page of data for a given request. You can implement your own pagination scheme, such as pipelining, by setting the starting_after parameter in your response.

client.transactions(account_id) do |data, resp|
  transactions = data
end

more_pages = true
while more_pages
  client.transactions(account_id, starting_after: transactions.last['id']) do |data, resp|
    more_pages = resp.has_more?
    transactions << data
    transactions.flatten!
  end
end

If you want to automatically download the entire dataset, you may pass fetch_all=true as a parameter.

client.transactions(account_id, fetch_all: true) do |data, resp|
  ...
end

Responses

We provide several ways to access return data. Methods will return the data field of the response in hash format.

txs = account.transactions(account_id)
txs.each do |tx|
  p tx['id']
end

You can also handle data inside a block you pass to the method. You must access data this way if you're using the asynchronous client.

account.transactions(account_id) do |txs|
  txs.each { |tx| p tx['id'] }
end

If you need to access the response metadata (headers, pagination info, etc.) you can access the entire response as the second block paramenter.

account.transactions(account_id) do |txs, resp|
  p "STATUS: #{resp.status}"
  p "HEADERS: #{resp.headers}"
  p "BODY: #{resp.body}"
end

Response Object

The default representation of response data is a JSON hash. However, we further abstract the response to allow access to response fields as though they were methods.

account = client.primary_account
p "Account:\t account.name"
p "ID:\t account.id"
p "Balance:\t #{account.balance.amount} #{account.balance.currency}"

All values are returned directly from the API unmodified, except the following exceptions:

  • Money amounts are always converted into BigDecimal objects. You should always use BigDecimal when handing bitcoin amounts for accurate precision.
  • Timestamps are always converted into Time objects.

Most methods require an associated account. Thus, responses for the account endpoints contain methods for accessing all the relevant endpoints. This is convenient, as it doesn't require you to supply the same account id over and over again.

account = client.primary_account
account.send(to: "[email protected]", amount: 100, description: "Sending 100 bitcoin")

Alternatively you can pass the account ID straight to the client:

client.transactions(<account_id>)

Account response objects will automatically update if they detect any changes to the account. The easiest way to refresh an account is to call the refresh! method.

account.refresh!

Warnings

It's prudent to be conscious of warnings. By default, the gem will print all warning to STDERR. If you wish to redirect this stream to somewhere else, such as a log file, then you can simply change the $stderr global variable.

Errors

If the request is not successful, the gem will raise an error. We try to raise a unique error for every possible API response. All errors are subclasses of Coinbase::Wallet::APIError.

Error Status
APIError *
BadRequestError 400
ParamRequiredError 400
InvalidRequestError 400
PersonalDetailsRequiredError 400
AuthenticationError 401
UnverifiedEmailError 401
InvalidTokenError 401
RevokedTokenError 401
ExpiredTokenError 401
TwoFactorRequiredError 402
InvalidScopeError 403
NotFoundError 404
ValidationError 422
RateLimitError 429
InternalServerError 500
ServiceUnavailableError 503

Usage

This is not intended to provide complete documentation of the API. For more detail, please refer to the official documentation.

Market Data

List supported native currencies

client.currencies

List exchange rates

client.exchange_rates

Buy price

client.buy_price
# or
client.buy_price(currency_pair: 'BTC-USD')

Sell price

client.sell_price
# or
client.sell_price(currency_pair: 'ETH-BTC')

Spot price

client.spot_price
# or
client.spot_price(currency_pair: 'BTC-EUR')

Current server time

client.time

Users

Get authorization info

client.auth_info

Lookup user info

client.user(user_id)

Get current user

client.current_user

Update current user

client.update_current_user(name: "New Name")

Accounts

List all accounts

client.accounts

List account details

client.account(account_id)

List primary account details

client.primary_account

Set account as primary

account.make_primary!

Create a new bitcoin account

client.create_account(name: "New Account")

Update an account

account.update!(name: "New Account Name")

Delete an account

account.delete!

Addresses

List receive addresses for account

account.addresses

Get receive address info

account.address(address_id)

List transactiona for address

account.address_transactions(address_id)

Create a new receive address

account.create_address

Transactions

List transactions

account.transactions

Get transaction info

account.transaction(transaction_id)

Send funds

account.send(to: <bitcoin address>, amount: "5.0", currency: "USD", description: "Your first bitcoin!")

Transfer funds to a new account

account.transfer(to: <account ID>, amount: "1", currency: "BTC", description: "Your first bitcoin!")

Request funds

account.request(to: <email>, amount: "8.0", currency: "USD", description: "Burrito")

Resend request

account.resend_request(request_id)

Cancel request

account.cancel_request(request_id)

Fulfill request

account.complete_request(request_id)

Buys

List buys

account.list_buys

Get buy info

account.list_buy(buy_id)

Buy bitcoins

account.buy(amount: "1", currency: "BTC")

Commit a buy

You only need to do this if you pass commit=true when you call the buy method.

buy = account.buy(amount: "1", currency: "BTC", commit: false)
account.commit_buy(buy.id)

Sells

List sells

account.list_sells

Get sell info

account.list_sell(sell_id)

Sell bitcoins

account.sell(amount: "1", currency: "BTC")

Commit a sell

You only need to do this if you pass commit=true when you call the sell method.

sell = account.sell(amount: "1", currency: "BTC", commit: false)
account.commit_sell(sell.id)

Deposit

List deposits

account.list_deposits

Get deposit info

account.list_deposit(deposit_id)

Deposit funds

account.deposit(amount: "10", currency: "USD")

Commit a deposit

You only need to do this if you pass commit=true when you call the deposit method.

deposit = account.deposit(amount: "1", currency: "BTC", commit: false)
account.commit_deposit(deposit.id)

Withdrawals

List withdrawals

account.list_withdrawals

Get withdrawal

account.list_withdrawal(withdrawal_id)

Withdraw funds

account.withdraw(amount: "10", currency: "USD")

Commit a withdrawal

You only need to do this if you pass commit=true when you call the withdrawal method.

withdraw = account.withdraw(amount: "1", currency: "BTC", commit: false)
account.commit_withdrawal(withdrawal.id)

Payment Methods

List payment methods

client.payment_methods

Get payment method

client.payment_method(payment_method_id)

Merchants

Get merchant

client.merchant(merchant_id)

Verify a merchant callback

client.verify_callback(request.raw_post, request.headers['CB-SIGNATURE']) # true/false

Orders

List orders

client.orders

Get order

client.order(order_id)

Create order

client.create_order(amount: "1", currency: "BTC", name: "Order #1234")

Refund order

order = client.orders.first
order.refund!

Checkouts

List checkouts

client.checkouts

Get checkout

client.checkout(checkout_id)

Get checkout's orders

checkout = client.checkout(checkout_id)
checkout.orders

Create order for checkout

checkout = client.checkout(checkout_id)
checkout.create_order

Contributing and testing

Any and all contributions are welcome! The process is simple: fork this repo, make your changes, add tests, run the test suite, and submit a pull request. Tests are run via rspec. To run the tests, clone the repository and then:

# Install the requirements
gem install coinbase

# Run tests
rspec spec

More Repositories

1

terraform-landscape

Improve Terraform's plan output to be easier to read and understand
Ruby
1,570
star
2

coinbase-wallet-sdk

An open protocol that lets users connect their mobile wallets to your DApp
TypeScript
1,423
star
3

coinbase-pro-trading-toolkit

DEPRECATED — The Coinbase Pro trading toolkit
TypeScript
864
star
4

kryptology

Go
846
star
5

coinbase-pro-node

DEPRECATED — The official Node.js library for Coinbase Pro
JavaScript
839
star
6

build-onchain-apps

Accelerate your onchain creativity with the Build Onchain Apps Template. ⛵️
Solidity
701
star
7

odin

Archived: Odin deployer to AWS for 12 Factor applications.
Go
543
star
8

coinbase-python

DEPRECATED — Coinbase Python API
Python
521
star
9

onchainkit

React components and TypeScript utilities to help you build top-tier onchain apps.
TypeScript
481
star
10

solidity-style-guide

471
star
11

assume-role

DEPRECATED — assume-role: a CLI tool making it easy to assume IAM roles through an AWS Bastion account
Shell
423
star
12

geoengineer

DEPRECATED — Infrastructure As Code
Ruby
401
star
13

coinbase-node

DEPRECATED — The official Node.js library for the Coinbase API.
JavaScript
363
star
14

mesh-specifications

Specification files for the Mesh Blockchain Standard
Shell
320
star
15

cbpay-js

Coinbase Pay SDK
TypeScript
317
star
16

coinbase-php

DEPRECATED — PHP wrapper for the Coinbase API
PHP
297
star
17

smart-wallet

Solidity
287
star
18

waas-sdk-react-native

Coinbase Wallet as a Service (WaaS) SDK for React Native. Enables MPC Operations for iOS and Android Devices.
TypeScript
234
star
19

temporal-ruby

Ruby SDK for Temporal
Ruby
218
star
20

step

step is a framework for building, testing and deploying AWS Step Functions and Lambda
Go
208
star
21

wallet-mobile-sdk

An open protocol for mobile web3 apps to interact with wallets
Kotlin
203
star
22

mesh-sdk-go

Mesh Client Go SDK
Go
192
star
23

coinbase-ios-sdk

Integrate bitcoin into your iOS application with Coinbase
Swift
171
star
24

nft-dapp-starter-kit

Starter kit for developers who want to build an NFT minting site
TypeScript
159
star
25

mesh-cli

CLI for the Mesh API
Go
154
star
26

coinbase-java

Coinbase API v1 library for Java
Java
147
star
27

coinbase-commerce-node

Coinbase Commerce Node
JavaScript
142
star
28

waas-client-library-go

Coinbase Wallet as a Service (WaaS) Client Library in Go.
Go
140
star
29

coinbase-commerce-php

Coinbase Commerce PHP
PHP
136
star
30

traffic_jam

DEPRECATED — Ruby library for time-based rate limiting
Ruby
129
star
31

dexter

Forensics acquisition framework designed to be extensible and secure
Go
122
star
32

coinbase-exchange-ruby

DEPRECATED — Official Ruby library for the GDAX API
Ruby
122
star
33

mongobetween

Go
110
star
34

multisig-tool

DEPRECATED — Multisig Vault recovery tool
JavaScript
110
star
35

mesh-bitcoin

Bitcoin Mesh API Implementation
Go
108
star
36

mesh-ethereum

Ethereum Mesh API Implementation
Go
100
star
37

coinbase-advanced-py

The Advanced API Python SDK is a Python package that makes it easy to interact with the Coinbase Advanced API. The SDK handles authentication, HTTP connections, and provides helpful methods for interacting with the API.
Python
98
star
38

coinbase-android-sdk

DEPRECATED — Android SDK for Coinbase
Java
96
star
39

react-coinbase-commerce

Coinbase Commerce React
JavaScript
92
star
40

fenrir

Archived: AWS SAM deployer to manage serverless projects.
Go
91
star
41

pwnbot

You call PwnBot in Slack on someone else's unlocked computer
JavaScript
90
star
42

commerce-onchain-payment-protocol

Solidity
90
star
43

digital-asset-policy-proposal

Digital Asset Policy Proposal: Safeguarding America’s Financial Leadership
84
star
44

coinbase-commerce-python

Coinbase Commerce Python
Python
79
star
45

magic-spend

Solidity
78
star
46

verifications

📜 "Coinbase Verifications" is a set of Coinbase-verified onchain attestations that enable access to apps and other onchain benefits.
Solidity
75
star
47

CBTabViewExample

TypeScript
72
star
48

chainstorage

The File System For a Multi-Blockchain World
Go
71
star
49

coinbase-bitmonet-sdk

DEPRECATED — Library to accept bitcoin payments in your Android App
Java
63
star
50

self-service-iam

DEPRECATED — Self Service AWS IAM Policies for dev at scale
JavaScript
58
star
51

coinbase-wordpress

DEPRECATED — Coinbase plugin/widget for Wordpress
57
star
52

coinbase-commerce-woocommerce

Accept Bitcoin on your WooCommerce-powered website.
PHP
57
star
53

paymaster-bundler-examples

JavaScript
55
star
54

barbar

DEPRECATED — OSX crypto-currency price ticker
Swift
53
star
55

demeter

DEPRECATED — Security Group Management For AWS
Ruby
52
star
56

coinbase-exchange-node

DEPRECATED — Use gdax-node
JavaScript
47
star
57

cadence-ruby

Ruby SDK for Cadence
Ruby
43
star
58

coinbase-woocommerce

DEPRECATED — Accept Bitcoin on your WooCommerce-powered website.
38
star
59

protoc-gen-rbi

Protobuf compiler plugin that generates Sorbet .rbi "Ruby Interface" files.
Go
38
star
60

mesh-ecosystem

Repository of all open source Mesh implementations and SDKs
33
star
61

master_lock

Inter-process locking library using Redis.
Ruby
32
star
62

coinbase-commerce-ruby

Coinbase Commerce Ruby Gem
Ruby
30
star
63

watchdog

DEPRECATED -- Github Bot for Datadog codification
Go
28
star
64

bittip

DEPRECATED — Reddit tip bot
JavaScript
27
star
65

cash-addr

Utility to convert between base58 and CashAddr BCH addresses.
Ruby
26
star
66

maxfuzz

DEPRECATED — Containerized Cloud Fuzzing
C
26
star
67

rules_ruby

Bazel Ruby Rules
Starlark
24
star
68

mesh-geth-sdk

go-ethereum based sdk for Mesh API
Go
24
star
69

onchain-app-template

TypeScript
24
star
70

redisbetween

Go
23
star
71

gtt-ui

DEPRECATED
JavaScript
22
star
72

btcexport

Export process for Bitcoin blockchain data to CSV
Go
22
star
73

bchd-explorer

Vue
21
star
74

baseca

Go
21
star
75

coinbase-sdk-nodejs

TypeScript
21
star
76

coinbase-commerce-whmcs

Coinbase Commerce module for WHMCS
PHP
18
star
77

coinbase-nft-floor-price

Coinbase NFT floor price estimate model
Python
17
star
78

coinbase-magento

DEPRECATED — Accept Bitcoin on your Magento-powered website.
17
star
79

salus

We would like to request that all contributors please clone a *fresh copy* of this repository since the September 21st maintenance.
HTML
17
star
80

coinbase-android-sdk-example

DEPRECATED — Example android app leveraging the coinbase android sdk
Java
15
star
81

staking-client-library-go

Programmatic access to Coinbase's best-in-class staking infrastructure and services. 🔵
Go
15
star
82

coinbase-spree

DEPRECATED — Accept bitcoin payments on your Spree store with Coinbase.
15
star
83

coinbase-cloud-sdk-js

TypeScript
14
star
84

staking-client-library-ts

Programmatic access to Coinbase's best-in-class staking infrastructure and services. 🔵
TypeScript
14
star
85

service_variables

Service level variables backed by Redis - useful for service wide configuration.
Ruby
12
star
86

solidity-workshop

JavaScript
12
star
87

chainsformer

Go
12
star
88

omniauth-coinbase

DEPRECATED — Coinbase OAuth 2 Strategy for Omniauth
Ruby
12
star
89

coinbase-javascript-sdk

DEPRECATED
JavaScript
11
star
90

coinbase-commerce-prestashop

DEPRECATED — Official Coinbase Commerce Prestashop Payment Module
PHP
11
star
91

mkr-vote-proxy

Cold storage-friendly voting for MKR tokens
Solidity
11
star
92

chainnode

Go
10
star
93

step-asg-deployer

Deprecated, renamed and maintained at https://github.com/coinbase/odin
Go
10
star
94

wrapped-tokens-os

TypeScript
10
star
95

eip-token-upgrade

Solidity
10
star
96

client-analytics

TypeScript
9
star
97

code-of-conduct

Code of conduct for open source projects managed by Coinbase
9
star
98

coinbase-magento2

DEPRECATED: Accept Bitcoin on your Magento2-powered website.
8
star
99

coinbase-commerce-opencart

DEPRECATED — Coinbase Commerce Integration For Opencart
PHP
8
star
100

waas-proxy-server

Go
7
star