Issue a Fungible Token
Creating your own fungible token on Convex is a one-liner — there is no new smart contract to write. Convex ships a standard convex.fungible library that builds fully-featured CAD029 tokens.
Create a token
Deploy a token with an initial supply. The whole supply starts in your account:
(def TOKEN (deploy [(@convex.fungible/build-token {:supply 1000000})]))
=> #1234
TOKEN is the address of your new token actor. That's it — you have issued a token.
Check a balance
(@convex.fungible/balance TOKEN *address*)
=> 1000000
Transfer tokens
Use the generic convex.asset library to move any asset. The amount is paired with the token as [TOKEN amount]:
;; send 1000 units to account #202
(@convex.asset/transfer #202 [TOKEN 1000])
Now check both balances:
[(@convex.fungible/balance TOKEN *address*) (@convex.fungible/balance TOKEN #202)]
=> [999000 1000]
Total supply and decimals
(@convex.fungible/total-supply TOKEN)
=> 1000000
build-token also accepts :decimals (and :initial-holder). For a token with 2 decimal places:
(def TOKEN (deploy [(@convex.fungible/build-token {:supply 1000000 :decimals 2})]))
See Also
- CAD029: Fungible Token Standard
- Managing Coins — the same ideas for the native Convex Coin
- Building an Actor — write your own custom actor