Development Update: Connext Example Token Tutorial

Angello Pozo
6 min readJan 4, 2018

--

We have been working with Connext since the summer on a few technical integration iterations. Since we at Hellosugoi are working closely together, we created an example tutorial repo that will help anyone expedite their integrations with Connext.

The code is an extension of the TruffleFramework Tutorial Token by truffle-box that uses the open zeppelin solidity smart contracts. The original blog post is linked here.

What is the Connext Vault?

The Connext Vault is a trustless, managed wallet that sits between a merchant (like HelloSugoi), their users, and Connext’s payment services.

Integrating Vaults is required in order to allow users to purchase your tokens directly with credit/debit cards. Vaults protect your users (and you) from fraud and money laundering activities, which allows Connext to help you maintain a significantly reduced compliance requirement than exchanges and money transmitters.

Each Vault contract is linked to a user’s identity, which means that, upon integration, you already get access to the completed identity checks and transaction histories of all of Connext’s other clients’ customers! Vaults will also eventually act as gateways to the rest of Connext’s services, including automated on-chain exchange and “cashing out” into fiat.

Prerequisites

Before we can write any code, we need to collect some information.

  1. Get Connext credentials
  2. Get a Mnemonic, private key, public address
  3. Get Rinkeby Ether,
  4. Have an ${Infura_Key}
  5. Have Truffle globally installed
  6. Clone Repo
  7. Node version >7.6.0

Setup Connext

First, contact Connext (founders@connext[dot]network) and ask to join. Once you are cleared, you will be given login credentials. Use them to log into https://app.connext.network/login and grab your API keys.

API key and API Secret removed from image. They exist!

These keys will be needed to make authenticated bearer API calls to Connext. Without these keys, all API calls will fail.

Getting mnemonic key

Go to https://iancoleman.io/bip39/ and click the Generate button next to “15 words”. This will create a your mnemonic, please store this! Change the “coin” option to “ETH — Ether” to create Ethereum accounts.

Now scroll down and save the public address and private key of the first row only! In the image below that would be ${address}=0xB68… and ${private_key} = 0x864…

By the end of this, you should have ${mnemonic}, ${address}, and ${private_key} values saved somewhere as they will be used later

Install Truffle globally

If you have truffle already, then you are cool. For this tutorial my version of truffle is 4.0.4. To install simply call npm install -g truffle in the terminal.

Infura Account (or your own Rinkeby node)

  1. Sign up on Infura
  2. You will get an email with your ${Infura_Key}

Add address to Metamask & select Rinkeby

  1. Install Metamask chrome extension
  2. Once installed, Click Metamask icon at the top right of the browser
  3. In the MetaMask window click the person on the top right
  4. Select Import Account
  5. Copy the ${private_key} from the previous section
  6. Click import
  7. Click the MetaMask Icon again
  8. On the top left, select the Rinkeby

Get Rinkeby Ether

  1. Go to https://faucet.rinkeby.io/
  2. Create a social media post that includes the public ${address} that was generated earlier.
  3. Paste a link to the social media post and enter into input field
  4. Click the “Give me Ether” butt on and Select the Ether amount

Setup

Once you have done all the prerequisites, you can setup this project and start working with Connext.

  1. In the terminal: git clone <repo>
  2. In the terminal: cd <repo>
  3. In the terminal: npm install

Once everything is installed, you will need to configure truffle.js to work with Rinkeby.

  1. Open truffle.js
  2. Enter your mnemonic (${mnemonic}) on line 2
  3. Enter your ${Infura_Key} on line 3

Now you can deploy the contract to Rinkeby using truffle.

  1. In the terminal: truffle migrate --network rinkeby
  2. Once completed you need to get the address of your token. This can be grabbed from the ./build/contracts/ConnextExampleToken.json file. The value at the key "networks.4.address" is the Rinkeby token address (${token_address})

Before we continue, you need to send information to Connext via email (founders@connext[.]network). The values below are only for demonstration puproses, you can put whatever you want.

  1. Merchant address (${address} from mnemonic)
  2. List of token contract addresses (${token_address} )
  3. list of destination addresses (${token_address} )
  4. Address to receive chargebacks (${address} )

Send whatever address that best fits your DApp structure. For example, you have have a separate address for chargebacks, or contract to manage used tokens.

Finally, you can start the server and start moving tokens around!

  1. In the terminal: npm run dev
  2. Open the browser and go to localhost:3000

Tutorial

Once you have everything setup, will be able to send your tokens to any address. To work with Connext, you need to create a Vault for your user. A ${vault_address} is created for every unique email, so you can check if the user has a Vault by calling the find customer endpoint. If they do, and its likely that they do not, you will need to use the Create Customer endpoint to create a Vault. Please note, Connext creates the Vault on Rinkeby upon request. This means, however long it takes Rinkeby to accept the transaction is how long the request will hold.

Save the ${vaultAddress} as you will be sending tokens to the Vault for the user. Go back to the token website at localhost:3000 to move tokens around.

Enter that value into the webpage and an amount of token to send in Wei. Metamask will pop up and click accept transaction. Once the transaction is completed, you will get an alert for the website. Check that the balance is correct by calling the Get Token Balance endpoint. Example response from Connext.

Balance in this image for illustration purposes only

If you followed the example from the previous section, you would see 6000000000000000000 (6 token in ether units). You can also check by going to the following endpoints on Etherscan. Replace values with the ones that you created.

1. Info for ${deploy_address}: https://rinkeby.etherscan.io/address/<deploy_address>

2. All token balances for ${token_address}: https://rinkeby.etherscan.io/token/<token_address>#balances

3. Token Balance for ${deploy_address}: https://rinkeby.etherscan.io/token/<token_address>?a=<deploy_address>

4. Token Balance for ${vault_address}: https://rinkeby.etherscan.io/token/<token_address>?a=<vault_address>

As a saftey check:

  1. ${token_address} should have 9994 tokens
  2. ${vault_address} should 6 token or 6000000000000000000 in Wei

You can transfer them back by calling the Transact Vault function on the ${vault_address} solidity contract. The script in ./scripts/transactVault.js will allow you to move the tokens. Again, this is not an http api call, its a transaction sent to the Ethereum network.

In the project, you can configure the transactVault.js file with the values for your project.

  1. from: address that deployed contracts (${address})
  2. vaultAddress: Vault for the specified user (${vault_address})
  3. tokenContractAddress: Address of your token (${token_address})
  4. recipientAddress: Address who will get tokens (${token_address})
  5. amount: The amount of token to move in ether units. For example 0.5 ether (500000000000000000 in Wei)

Once those are populated, entertruffle exec ./scripts/transactVault.js --network rinkeby into the terminal and you will receive a transaction (${transfer_tx}). From here you can enter the ${transfer_tx} into Etherscan.

  1. Token Address: https://rinkeby.etherscan.io/tx/<transfer_tx>

Once that transaction is completed you can recheck the Etherscan endpoints from before and see that the values are updated.

As a saftey check:

  1. ${token_address} should have 9994.5 tokens
  2. ${vault_address} should 5.5 token or 500000000000000000 in Wei

Conclusion

You should be able to successfully move tokens around using the Connext Token Vault. They are constantly working on updates so if you find a bug, or issue send them an email (founders@connext[.]network) or join their slack channel. We are ecstatic to be working with Connext and are looking forward to the future!

To keep up with the latest HelloSugoi news as it’s happening, we invite you join our mailing list, message us on Discord, follow us on Twitter @HelloSugoi, and visit our website hellosugoi.com.

--

--

Angello Pozo

Co-Founder of HelloSugoi. Hacking away on Ethereum (blockchain) DApps. Follow me on https://twitter.com/angellopozo