Sign in now

Quick Start for Smart Contracts

Last updated: February 27, 2019

Before you begin

This page provides a step-by-step tutorial to deploy a sample app with Xooa’s blockchain platform-as-a-service (PaaS/BaaS). Xooa provides a permanent cloud end-point for the smart contract, enabling cloud-to-cloud integration, while retaining blockchain’s peer-to-peer capabilities.

You do not need to write code before you can start writing code:

  • If you don’t already have one, create a GitHub account on https://github.com

  • Log in to the Xooa console with your GitHub account (recommended) at https://xooa.com/blockchain

     

    Tip

    If you log in with Google, you’ll need your GitHub ID when you want to go beyond our samples. That’s why we think signing in with GitHub is just easier.

Getting serious?

If you are using Xooa for the first time and just want to go through the process of creating a blockchain, then you need only log in to Xooa. That’s it. Nothing more to do. Read no further.

If you are wanting to develop your own smart contract, then there are a couple of things you need to do first: you need to have a GitHub repository with your smart contract and you need to tell Xooa where the smart contract is in the repository.

The easiest way to do that is to fork Xooa’s repository, which contains the necessary files:

https://github.com/Xooa/samples

But if you already have an existing blockchain project, you will need to add a xooa.yaml file (see our sample) to the root of your repository for it to be deployable. The file needs to contain the correct location and language of your smart contract (chaincode).

Deploy the smart contract app

  1. In the Xooa console, go to Smart Contracts>Deploy New.

  2. Locate your smart contract:

    1. Select public, private, or xooa github as appropriate (if you want to try the sample, select Xooa)
    2. If you need to, search for your repository
    3. Click Select, and then click Next.

    deploy

  3. From Smart Contract, select the smart contract you want to deploy, and then click Deploy. This deploys the contract to Xooa and creates an identity that can access the ledger.

     

    Relax

    Yeah, you are almost done. Xooa is doing the blockchain heavy lifting. You will be redirected to the app’s dashboard when the process completes. Be sure to copy that API token.

Create an identity

  1. Go to the Identities tab, and then click Add New

  2. Enter an identity name and from API Access Permission, select Read+Write.

  3. Click Create. You’ll get a message that the identity has been enrolled and the API token generated.

  4. Before you dismiss the message, click Copy, The token is now in the clipboard.

  5. Store the token somewhere safe. You will need it to authorize every API request.

     

    Xooa does not store the key. If you lose the key, you will have to generate a new one, invalidating any existing API clients.

Write to the blockchain ledger

You have created your smart contract app and now you want to invoke a smart contract function. Here, we’ll demonstrate the set function on the Get-Set smart contract. This function allows us to write data to the ledger. We can invoke functions directly from the API documentation, but you will need API token you copied earlier.

  1. In your Get-Set app, go to the Details tab, and then click Explore API’s. The API Explorer, including the API documentation, opens.

  2. In the top left there is an input field for the API token, paste the token you copied earlier here.

  3. From the navigation, go to Smart Contract > Invoke Smart Contract Function.

  4. In the fcn field, enter set. The function set on the Get-Set smart contract will write to the ledger.

  5. In the body field, enter the data you want to store in the ledger in the format:

    [ "<key>", "<value>" ]

  6. Click TRY.

     

    Congrats!

    If your HTTP response code was 200, you have saved data in a blockchain ledger by using Xooa. Check instructions in the message or the API documentation for other return codes.

Read from the blockchain ledger

  1. To view transactions, go to Ledger > Transactions.
  2. Click the transaction ID to get additional details about the transaction