1
0
mirror of https://github.com/bigchaindb/site.git synced 2024-11-22 01:36:55 +01:00

Update flow and text

This commit is contained in:
Ricardo Garcia 2017-11-23 14:26:33 +01:00 committed by GitHub
parent 7598ed1e79
commit 794fa55068
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -26,7 +26,7 @@ Note however, that we do not support ERC20 and no one has launched tokens on Big
# Usage of divisible assets to create tokens
BigchainDB supports divisible assets. A divisible asset is an asset that has a fixed number of sub-assets linked to it. These fixed sub-assets that are linked to it, represent your tokens. When creating a divisible asset in BigchainDB, the number of the sub-assets (tokens) that you want to create needs to be specified. That represents your fixed total supply of tokens.
BigchainDB supports divisible assets. A divisible asset is an asset that has a fixed number of sub-assets linked to it. This means that the create transaction for this asset has multiple outputs. The linked fixed sub-assets represent your tokens. When creating a divisible asset in BigchainDB, the number of the sub-assets (tokens) that you want to create needs to be specified. That represents your fixed total supply of tokens.
The code below illustrates how to create a divisible asset with 10 000 tokens associated to it.
@ -58,12 +58,14 @@ function tokenLaunch() {
}
```
Now, we have minted 10 000 tokens. For that there is an extra parameter to the `makeOutput()` function. Pay attention to give the function a string instead of a plain number. With the `tokenCreator` keypair we indicate who the owner of the tokens will be. Once the transaction is accepted by BigchainDB we update the value of the tokens left in the possession of the creator.
Now, we have minted 10000 tokens. For that there is an extra parameter to the `makeOutput()` function. Pay attention to give the function a string instead of a plain number. With the `tokenCreator` keypair we indicate who the owner of the tokens will be. Once the transaction is accepted by BigchainDB we update the value of the tokens left in the possesion of the creator. Right now, all the tokens created are associated with the public key of the creator (`tokenCreater.publicKey`).
Once the tokens are created we can start to spread it over our users.
Once the tokens are created, we can now start distributing them to the owners.
# Transfer tokens
Tokens can be transferred to an unlimited number of participants. In our example, we are now going to make a transfer transaction to transfer 200 tokens to a new user called John. For that, we first need to create a new user and then do the transfer. The code below shows that.
```js
const amountToSend = 200
@ -97,5 +99,8 @@ function transferTokens() {
})
}
```
You have now transferred 200 tokens to the user John. With `listOutputs` using `false` as the second argument you retrieved all the outputs that were not spent yet. Then, you queried for that transaction and made a transfer to John with it. Note however, that there is also a transaction back to `tokenCreator.publicKey`. That is related to BigchainDB's transaction model. It is designed in a way that all of the inputs have to be spent in a transaction. That means that if we send part of the `tokensLeft` (200 tokens) to John, we have to send the rest (9800 tokens) back to the `tokenCreator` to preserve that amount.
With `listOutputs` using `false` as the second argument we can retrieve all the outputs that were not spent yet. Then we query for that transaction and we make a transfer with it. As the transaction model of BigchainDB is designed, all of the inputs have to be spent in a transaction. That means that if we send part of the `tokensLeft` to some user, we have to send the rest to the `tokenCreator` to preserve that amount.
Note that in our example, the supply of your tokens was fixed and cannot be changed anymore after creation. So, you would need to clearly define for yourself, how many tokens you will need. However, BigchainDB does offer the option of refillable, devisible assets that allow for more dynamic token supply. You can learn more about that [here](https://github.com/bigchaindb/bigchaindb/issues/1741).
That's it! Now you know, how divisible assets in BigchainDB can be used as a building block for token launches. Of course, in practice a token distribution event is much more complex and requires other important building blocks like smart contracts etc. But this tutorial showed you how to get started.