round-rb: A Ruby client for the Gem API
The round client is designed to interact with Gem's API to make building blockchain apps drop dead simple. All the complexity of the bitcoin protocol and crypto has been abstracted away so you can focus on building your product. Here are a few of the many great things the API and clients provide:
- Multi-signature wallets with Gem as a cosigner
- Webhook notifications automatically subscribed for you
- Integrated 2FA solution with arbitrary endpoints to build into your app
- Simplified balance inqueries
- Easy address management
- Hardware Security Modules for co-signing key
- Rules engine for transactions
- SDKs for many popular languages
Support information
- Support email: support@gem.co
- Issues: Use github issues
- Support Slack room:
- Detailed API Docs: Gem API Docs
Installing round-rb:
Prerequisites:
- Ruby 2.1.5
Getting Started Tutorial
Table of Contents
- Introduction
- 1. Run the client
- 2. Configure your application and API token
- 3. Create your User and Wallet
- 4. Authenticate your User
- 5. Access the wallet and Default Account
- 6. Generate an Address and Add Funds
- 7. Make a Payment
- Advanced Topics
Introduction
This tutorial will have you run through setting up your application and creating your own wallet as a user of your application. By the end of the tutorial, you will have created your User, wallet, account, an address as well as fund it and then make a payment using the bitcoin testnet network.
This tutorial assumes that you have completed the developer signup and that you have successfully installed the client
1. Run the Client
In this step you will learn how to instantiate the API client for the given networks.
-
start your favorite interactive shell and import the round library
$ irb > require 'round'
-
Create the client object.
client = Round.client ```
2. Configure your application and API Token
In this step your application and you will retrieve the API Token for the application and set your applications redirect url. The url is used to push the user back to your app after they complete an out of band challenge.
-
In the console copy your
api_token
by clicking on show -
Go back to your shell session and set a variable for
api_token
api_token = 'q234t09ergoasgr-9_qt4098qjergjia-asdf2490'
3. Create your User and Wallet
In this step you will create your own personal Gem user and wallet authorized on your application. This is an end-user account, which will have a 2-of-3 multisig bitcoin wallet.
-
Authenticate your client
client.authenticate_identify(api_token: api_token)
-
Create your user and wallet:
# Store the device token for future authentication device_token = client.users.create( first_name: 'YOUR FIRST NAME', last_name: 'YOUR LAST NAME', email: 'YOUR EMAIL ADDRESS', passphrase: 'aReallyStrongPassphrase', device_name: 'SOME DEVICE NAME', redirect_uri: 'http://something.com/user-device-approved') )
-
Your application should store the device_token permanently as this will be required to authenticate from your app as this user.
-
You (acting as a user) will receive an email from Gem asking you to confirm your account and finish setup. Please follow the instructions. At the end of the User sign up flow, you'll be redirected to the redirect_uri provided in users.create (if you provided one).
4. Authenticate your User
In this step you will learn how to authenticate to the Gem API on a User's device to get a fully functional User object with which to perform wallet actions.
-
Call the authenticate_device method from the client object
full_user = client.authenticate_device( api_token: api_token, device_token: device_token, email: email )
5. Access the wallet and Default Account
-
Get the wallet and then default account
my_account = full_user.wallet.accounts['default']
6. Generate an Address and Add Funds
In this section you'll learn how to create an address to fund with testnet coins aka funny money.
-
Create an address
address = my_account.addresses.create puts address.string
puts address.path ```
- Copy the address string and go to a faucet to fund it:
Payments have to be confirmed by the network and on Testnet that can be slow. To monitor for confirmations: input the address into the following url https://live.blockcypher.com/btc-testnet/address/<YOUR ADDRESS>
. The current standard number of confirmations for a transaction to be considered safe is 6.
You will be able to make a payment on a single confirmation. While you wait for that to happen, feel free to read more details about: Wallets and Accounts
7. Make a Payment
In this section you’ll learn how to create a payment a multi-signature payment in an HD wallet. Once your address gets one more more confirmations we’ll be able to send a payment out of the wallet. To make a payment, you'll unlock a wallet, generate a list of payees and then call the pay method.
-
Unlock the wallet:
my_account.wallet.unlock(<YOUR PASSWORD>)
-
Make a payment
transaction = my_account.pay([{address: 'mxzdT4ShBudVtZbMqPMh9NVM3CS56Fp11s', amount: 25000}], 1, 'http://some-redirect-uri.com/')
puts transaction.mfa_uri # redirect your user to this URI to complete payment! ```
The pay call takes a list of payee objects. A payee is a hash of {address: ADDRESS, amount: amount}
where address is the bitcoin address and amount is the number of satoshis. utxo_confirmations
default to 6 and represents the number of confirmations an unspent output needs to have in order to be selected for the transaction.
The last argument is the redirect uri for Gem to send the user back to your application after the user submits their MFA challenge.
CONGRATS - now build something cool.