Skip to content

Instantly share code, notes, and snippets.

@ryandotsmith
Last active Oct 22, 2015
Embed
What would you like to do?
Chain's Asset Wallet - Creating, Issuing, and Transferring Assets

Tutorial - Creating, Issuing, and Transferring Assets

Overview

In this tutorial, we will do the following:

  1. Create an App Wallet
  2. Add the App Wallet Details to the Chain SDK
  3. Create a new Asset in the App Wallet called "Gold Stars"
  4. Create Buckets in the App Wallet for the Treasury and two users - Devon and Ryan
  5. Issue 10 Gold Stars into the Treasury
  6. Transfer 1 Gold Star to Devon and 2 Gold Stars to Ryan from the Treasury

1. Create an App Wallet

To create an App Wallet, we visit the Chain Dashboard and click the "Create Development Wallet" button.

<img src="https://s3.amazonaws.com/f.cl.ly/items/1w3d381L1p1h0H3U3U0F/Screen%20Shot%202015-07-10%20at%203.39.44%20PM.png"\>

We choose a 2-of-2 multi-signature configuration with 1 Chain Co-signer Key and choose to generate our Key.

<img src="https://s3.amazonaws.com/f.cl.ly/items/2z0E3y1S0c2M1f3h1e3b/Screen%20Shot%202015-07-10%20at%203.39.29%20PM.png"\>

We then save the Wallet details for use on our webserver when issuing and trasnferring assets.

<img src="https://s3.amazonaws.com/f.cl.ly/items/47330809332G311e3r16/Screen%20Shot%202015-07-10%20at%203.45.32%20PM.png"\>

2. Add the App Wallet Details to the Chain SDK

require 'chain-wallets'

c = ChainWallets::Client.new(
  token_id: '7af82266416257dada0980dcb641fbd5',
  token_secret: '30ab0430c4f2ed6445a63c96441191d9'
)
c.keystore.add(ChainWallets::XPrvKey.new('xprv...'))

3. Create a new Asset in the App Wallet called "Gold Stars".

We visit the Dashboard and click on our newly created App Wallet labeled "Gold Stars".

<img src="https://s3.amazonaws.com/f.cl.ly/items/0e3r3N3j021G3c3Q1A1p/Screen%20Shot%202015-07-10%20at%203.57.53%20PM.png"\>

We then click the "Assets" tab in the top right and click the "Create Asset" button.

<img src="https://s3.amazonaws.com/f.cl.ly/items/2A1Z1T0Q0q0l0W16031i/Screen%20Shot%202015-07-10%20at%203.58.00%20PM.png"\>

We create a new immutable asset, defining only the name in the asset definition and providing no definition URL.

<img src="https://s3.amazonaws.com/f.cl.ly/items/3s3R1c3C130m1j2R0V1Y/Screen%20Shot%202015-07-10%20at%204.01.51%20PM.png"\>

We save the newly created Asset ID for use in the SDK when issuing and transferring units of the Asset.

<img src="https://s3.amazonaws.com/f.cl.ly/items/0l1Z093R1s3N2g0S0t0u/Screen%20Shot%202015-07-10%20at%204.02.20%20PM.png"\>

4. Create a Bucket in the App Wallet for the system Treasury.

We then click the "Buckets" tab in the top right of the Wallet view and click the "Create Bucket" button.

<img src="https://s3.amazonaws.com/f.cl.ly/items/0W3v1M3A241J0G0T1P0O/Screen%20Shot%202015-07-10%20at%204.07.23%20PM.png"\>

When save the newly created Bucket ID as the Treasury for use in the SDK when issuing and transferring units of our "Gold Stars" Asset.

<img src="https://s3.amazonaws.com/f.cl.ly/items/043P2A0s0M1K0J2c0Q1k/Screen%20Shot%202015-07-10%20at%204.08.12%20PM.png"\>

When repeat this process for Devon and Ryan's Buckets and save the Bucket IDs.

<img src="https://s3.amazonaws.com/f.cl.ly/items/1d2p1b280V3o1J1h2a1G/Screen%20Shot%202015-07-10%20at%204.11.57%20PM.png"\>

5. Issue 10 Gold Stars into the Treasury

c.issue_asset('AawTzyEy8dnbKYicVeAb1GCq6f8yWeE9Rt',[{
  bucket_id: '0c676fd5-6eb9-42cd-b234-524160fff514', #Treasury bucket id
  amount: 100
}])

6. Transfer 1 Gold Star to Devon and 2 Gold Stars to Ryan from the Treasury

c.transfer_asset(
  inputs: [{
    asset_id: 'AawTzyEy8dnbKYicVeAb1GCq6f8yWeE9Rt',
    bucket_id: '0c676fd5-6eb9-42cd-b234-524160fff514', #Treasury bucket id
    amount: 3,
    min_confirmations: 0
  }],
  outputs: [
    {
      asset_id: 'AawTzyEy8dnbKYicVeAb1GCq6f8yWeE9Rt',
      bucket_id: '9d2ff7e1-acbc-4c26-b72d-a129108135d3', #Ryan's bucket id
      amount: 2
    },
    {
      asset_id: 'AawTzyEy8dnbKYicVeAb1GCq6f8yWeE9Rt',
      bucket_id: '449f7759-ef7b-42e1-9b0f-3f27b4fe2e40', #Devon's bucket id
      amount: 1
    }
  ]
)
@grygielny
Copy link

grygielny commented Oct 22, 2015

Hi Ryan, thanks for documenting this. Can you provide more detail on step 2--adding to Chain SDK.

And where you add 5 and 6. I'm trying to test this out, but I'm not sure how to execute this via a webserver. Are there any specifics for the server that you use or what type of files you have to embed them in?

Trying to do some testing...simulation to see how this works.

Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment