• This repository has been archived on 20/Apr/2022
  • Stars
    star
    171
  • Rank 222,266 (Top 5 %)
  • Language
    Swift
  • License
    Apache License 2.0
  • Created over 10 years ago
  • Updated almost 3 years ago

Reviews

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

Repository Details

Integrate bitcoin into your iOS application with Coinbase

Coinbase iOS SDK

This library is deprecated.

Thank you all for your contributions.

Platform Language Carthage compatible CocoaPods compatible License

Table of Contents

Installation

CocoaPods

CocoaPods is a dependency manager for Cocoa projects. You can install it with the following command:

$ gem install cocoapods

To integrate Coinbase SDK into your Xcode project using CocoaPods, specify it in your Podfile:

pod 'coinbase-official', '~> 4.0'

Then, run the following command:

$ pod install

If you want to use the RxSwift extensions for Coinbase SDK add:

pod 'coinbase-official/RxSwift', '~> 4.0'

Carthage

Carthage is a decentralized dependency manager that builds your dependencies and provides you with binary frameworks.

You can install Carthage with Homebrew using the following command:

$ brew update
$ brew install carthage

To integrate Coinbase SDK into your Xcode project using Carthage, specify it in your Cartfile:

github "coinbase/coinbase-ios-sdk"

Run carthage update to build the framework and drag the built CoinbaseSDK.framework into your Xcode project. If you want to use the RxSwift extensions for Coinbase SDK add RxCoinbaseSDK.framework into your project as well.

Swift Package Manager

The Swift Package Manager is a tool for automating the distribution of Swift code and is integrated into the swift compiler.

Once you have your Swift package set up, adding Coinbase SDK as a dependency is as easy as adding it to the dependencies value of your Package.swift.

dependencies: [
        .package(url: "https://github.com/coinbase/coinbase-ios-sdk")
    ]

And in the target where you want to use it:

targets: [
    .target(
        name: "<project_name>",
        dependencies: ["CoinbaseSDK"])
]

If you want to use the RxSwift extensions for Coinbase SDK add to target's dependencies: "RxCoinbaseSDK".

Important

Swift Package Manager currently does not support resources. Coinbase SDK requires additional resource files to work properly (Trusted SSL Certificates). If you want to use Swift Package Manager you should provide those resources manually.

You can find the required resources in Coinbase iOS SDK GitHub repository under Source/Supporting Files/PinnedCertificates path. Collect those files and add them to your project.

  • Using Xcode:

    You should additionally configure CoinbaseSDK target. In tab Build Phases add new phase by selecting New Copy File Phase. Drag and Drop required resources to this phase.

  • Using console:

    To provide the required resources you should copy them to a location with built files.

    Example: If required files are located in directory Resources and you building for x86_64-apple-macosx10.10 platform in debug mode then resources can be copied with the command:

    cp Resources/* ./.build/x86_64-apple-macosx10.10/debug

Basic usage

In source file where you want to use CoinbaseSDK add:

import CoinbaseSDK

If you want to use the RxSwift extensions for CoinbaseSDK using not CocoaPods, please import RxCoinbaseSDK by adding the following line:

import RxCoinbaseSDK

To use CoinbaseSDK you need to have an instance of Coinbase class. You can create a new Coinbase instance:

let coinbase = Coinbase()

Or you can use convenience static instance:

Coinbase.default

Authentication

To work with resources which require authentication you should provide a valid access token to Coinbase instance.

Access token can be provided either directly by setting its value to coinbase's property:

coinbase.accessToken = accessToken

or by passing it to the initializer:

let coinbase = Coinbase(accessToken: accessToken)

If you do not provide an access token to the instance of Coinbase you can successfully work with only the next resources:

  1. CurrenciesResource
  2. ExchangeRatesResource
  3. PricesResource
  4. TimeResource

Getting access token

To get an access token the Coinbase iOS SDK uses OAuth2 authentication.

You should call configure method on oauth property of Coinbase instance to set all required properties before calling any authorization method:

coinbase.oauth.configure(clientID: <client_id>,
                         clientSecret: <client_secret>,
                         redirectURI: <redirect_uri>)

Then you can initiate OAuth flow by calling beginAuthorization

try coinbase.oauth.beginAuthorization(scope: [Scope.Wallet.Accounts.read, ...])

It will redirect user into Safari browser where they can authorize your application.

In AppDelegate you should handle redirection back by calling coinbase.oauth.completeAuthorization method inside application(_:open:options:)

func application(_ app: UIApplication, open url: URL, options: [UIApplicationOpenURLOptionsKey : Any] = [:]) -> Bool {
        let handleCoinbaseOAuth = coinbase.oauth.completeAuthorization(url) { result in
            // setup coinbase, e.g. coinbase.accessToken = result.value?.accessToken
        }
        return handleCoinbaseOAuth
    }

To get a detailed guide on how to use OAuth2 with CoinbaseSDK read Getting Acess Token.

Note

Coinbase instace for completeAuthorization call should be the same as you used to call beginAuthorization method.

Important

Access token lifetime is pretty short and after the expiration, it should be refreshed with the refresh token.

You can perform refresh manually or allow auto-refresh by calling setRefreshStrategy with TokenRefreshStrategy.refresh on Coinbase instance.

Reed more about TokenRefreshStrategy in Token refreshing.

RxSwift

CoinbaseSDK provides wrappers that allow you to use it with RxSwift. To get more information about how to use it read page.

Examples

To see more details on how to work with CoinbaseSDK you can check sample app or read some Coinbase Examples.

Sample app

To be able to use Coinbase SDK iOS Example app you should setup OAuth2 application keys. You can get the required keys after creating Coinbase OAuth2 Application.

  • Log in to your Coinbase account and create a new OAuth2 application (or get an existing one).
  • In application details page you can get clientId, clientSecret and redirectUri.
  • Open Coinbase workspace then inside iOS Example project fill empty values for OAuth2ApplicationKeys in Source/Constants.swift file.
  • Register custom scheme used in your redirectURI. In Info.plist file add:
<key>CFBundleURLTypes</key>
<array>
    <dict>
        <key>CFBundleURLName</key>
        <string>Coinbase OAuth Scheme</string>
        <key>CFBundleURLSchemes</key>
        <array>
            <string>[redirect_uri_scheme]</string>
        </array>
    </dict>
</array>

Note:

Make sure that you used the same URI scheme in redirectURI constant and your Info.plist file.

For example, if your [redirect_uri_scheme] is com.example.app, then your redirect URI can be: com.example.app://callback

Testing

To be able to run tests, you should download dependencies. To do so, run:

carthage bootstrap --platform iOS

If you do not have Carthage installed, check the installation instructions.

After that, you can open Coinbase.xcworkspace and select CoinbaseSDK target and hit ⌘+U to start testing.

License

Coinbase is available under the Apache License 2.0. See LICENSE file for more info.

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

coinbase-ruby

DEPRECATED β€” Ruby wrapper for the Coinbase API
Ruby
241
star
19

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
20

temporal-ruby

Ruby SDK for Temporal
Ruby
218
star
21

step

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

wallet-mobile-sdk

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

mesh-sdk-go

Mesh Client Go SDK
Go
192
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