Skip to main content
Version: main branch

Mint Tokens

In Alphabill, every user token is associated with a type, meaning that it's an instance of that type, and has any characteristics that are dictated by its type, such as inherited predicates/clauses. After you have created your own token types, you can start minting tokens based on those types.

Mint Fungible Tokens

  1. Open the help output to see the available options for minting fungible tokens:

    ./abwallet wallet token new fungible -h
    mint new fungible token

    Usage:
    abwallet wallet token new fungible [flags]

    Flags:
    --amount string amount, must be bigger than 0 and is interpreted according to token type precision (decimals)
    --bearer-clause string predicate that defines the ownership of this fungible token. Valid values are either one of the predicate template name [ true | false | ptpkh | ptpkh:n | ptpkh:0x<hex-string> ] or @<filename> to load predicate from given file. (default "ptpkh")
    -h, --help help for fungible
    -k, --key uint which key to use for sending the transaction (default 1)
    --mint-input string input to satisfy the type's minting clause. Valid values are:
    [ true | false | empty ] - these will esentially mean "no argument"
    [ ptpkh | ptpkh:n ] - creates argument for the ptpkh predicate template using either default account key or account n key respectively
    @<filename> - load argument from file, the file content will be used as-is.
    (default "ptpkh")
    --type hex type unit identifier

    Global Flags:
    --config string config file URL (default is $AB_HOME/config.props)
    --home string set the AB_HOME for this invocation (default is /home/user/.alphabill)
    --log-file string log file path or one of the special values: stdout, stderr, discard
    --log-format string log format, one of: text, json, console
    --log-level string logging level, one of: DEBUG, INFO, WARN, ERROR
    --max-fee string maximum fee per transaction (in tema) (default "10")
    -p, --password password (interactive from prompt)
    --pn string password (non-interactive from args)
    --proof-output string save transaction proof to the file (if the file already exists it will be overwritten). This flag implicitly sets "wait-for-confirmation" to "true"
    -r, --rpc-url string rpc node url (default "localhost:28866")
    -w, --wait-for-confirmation string waits for transaction confirmation on the blockchain, otherwise just broadcasts the transaction (default "true")
    -l, --wallet-location string wallet home directory (default $AB_HOME/wallet)

    The output shows some mandatory properties you must define to mint new fungible tokens:

    • --amount: amount of fungible tokens to be created. This number is given as a decimal and must not have more decimal places than the token type allows. For example, if the token type specifies two decimal places, you can't mint 100.123 worth of tokens.
    • --mint-input: input to satisfy the mint clause, which proves that you are allowed to issue tokens of this type.
    • --type: unit identifier, or ID, of the token type that you are minting.

    For fungible tokens, you should have created four types: FT_TYPE, FT_PARENT_TYPE, FT_SUBTYPE, and FT_SUBTYPE2. These token types use the default mint clause, ptpkh, from your wallet's default public key.

  2. Start minting some fungible tokens of the FT_SUBTYPE type. Since the mint clauses are inherited, subtype tokens inherit the default ptpkh mint clause from their parent type, which in this case is FT_PARENT_TYPE. This means that two mint inputs must be satisfied.

    ./abwallet wallet token new fungible \
    --amount 100 \
    --mint-input ptpkh:1 \
    --mint-input ptpkh:1 \
    --type FT_SUBTYPE_ID
    Example response:
    Sent request for new fungible token with id=117A1F1712F2E07AC7157FE03A8C22D87661F5DC3158B3070052ED96EA20853803
    Paid 0.000'000'02 fees for transaction(s).
  3. After the command succeeds, sync the wallet to see the result:

    ./abwallet wallet token list --key 1
    Example response:
    Tokens owned by account #1
    ID='117A1F1712F2E07AC7157FE03A8C22D87661F5DC3158B3070052ED96EA20853803', symbol='FT_SUBTYPE', amount='100.000'000'00', token-type='0C7215CB12A2F76AF93315DCC1780BE7FD0F390CE84E5C91FA2BB5B91AFED05D01', locked='' (fungible)

    You have successfully minted 100 tokens of the fungible subtype to your wallet's default account.

Mint Non-Fungible Tokens

Minting non-fungible tokens (NFTs) is similar to minting fungible tokens, except that NFTs have an updatable data field.

  1. Open the help output to see what options are available for minting NFTs:

    ./abwallet wallet token new non-fungible -h
    mint new non-fungible token

    Usage:
    abwallet wallet token new non-fungible [flags]

    Flags:
    --bearer-clause string predicate that defines the ownership of this non-fungible token. Valid values are either one of the predicate template name [ true | false | ptpkh | ptpkh:n | ptpkh:0x<hex-string> ] or @<filename> to load predicate from given file. (default "ptpkh")
    --data hex custom data (hex). Alternatively flag "data-file" can be used to add data.
    --data-file string data file (max 64Kb) path. Alternatively flag "data" can be used to add data.
    --data-update-clause string data update predicate. Valid values are either one of the predicate template name [ true | false | ptpkh | ptpkh:n | ptpkh:0x<hex-string> ] or @<filename> to load predicate from given file. (default "true")
    -h, --help help for non-fungible
    -k, --key uint which key to use for sending the transaction (default 1)
    --mint-input string input to satisfy the type's minting clause. Valid values are:
    [ true | false | empty ] - these will esentially mean "no argument"
    [ ptpkh | ptpkh:n ] - creates argument for the ptpkh predicate template using either default account key or account n key respectively
    @<filename> - load argument from file, the file content will be used as-is.
    (default "ptpkh")
    --name string name of the token (optional)
    --token-uri string URI to associated resource, ie. jpg file on IPFS
    --type hex type unit identifier

    Global Flags:
    --config string config file URL (default is $AB_HOME/config.props)
    --home string set the AB_HOME for this invocation (default is /home/user/.alphabill)
    --log-file string log file path or one of the special values: stdout, stderr, discard
    --log-format string log format, one of: text, json, console
    --log-level string logging level, one of: DEBUG, INFO, WARN, ERROR
    --max-fee string maximum fee per transaction (in tema) (default "10")
    -p, --password password (interactive from prompt)
    --pn string password (non-interactive from args)
    --proof-output string save transaction proof to the file (if the file already exists it will be overwritten). This flag implicitly sets "wait-for-confirmation" to "true"
    -r, --rpc-url string rpc node url (default "localhost:28866")
    -w, --wait-for-confirmation string waits for transaction confirmation on the blockchain, otherwise just broadcasts the transaction (default "true")
    -l, --wallet-location string wallet home directory (default $AB_HOME/wallet)

    Let's take a look at some of the NFT properties:

    • --data: allows attaching arbitrary binary data to an NFT.
    • --data-update-clause: controls what keys can update the data field.
    • --mint-input: input to satisfy the mint clause, which proves that you are allowed to issue tokens of this type.
    • --token-uri: non-updatable field and usually contains a reference to a picture or some other data that represents what the token is.
    • --type: indicates the type you are creating.
  2. Use the NFT subtype to mint an NFT. Replace the --data, --name, --token-uri, and --type fields with your actual values and run the following command:

    ./abwallet wallet token new non-fungible \
    --data CUSTOM_HEX_STRING \
    --data-update-clause ptpkh \
    --mint-input ptpkh:1 \
    --mint-input ptpkh:2 \
    --name NFT_NAME \
    --token-uri NFT_URI \
    --type NFT_SUBTYPE_ID
    Example response:
    Sent request for new non-fungible token with id=0B78A411D497A66A96CCF8DAAE91B769DB4C9B46D7ADB61E6D00814EE26ABF9904
    Paid 0.000'000'02 fees for transaction(s).
    important

    As mentioned previously, the order on the --mint-input line is important. The NFT parent type has a mint input of ptpkh:1, while the NFT subtype has ptpkh:2.

  3. Finally, check the newly minted NFT in your wallet:

    ./abwallet wallet token list --key 1
    Example response:
    Tokens owned by account #1
    ID='117A1F1712F2E07AC7157FE03A8C22D87661F5DC3158B3070052ED96EA20853803', symbol='FT_SUBTYPE', amount='100.000'000'00', token-type='0C7215CB12A2F76AF93315DCC1780BE7FD0F390CE84E5C91FA2BB5B91AFED05D01', locked='' (fungible)
    ID='0B78A411D497A66A96CCF8DAAE91B769DB4C9B46D7ADB61E6D00814EE26ABF9904', symbol='NFT_SUBTYPE', name='MY_NFT', token-type='66EE618CE91B8D78DFA7AEED9B7C9FCBA990D92E9FB5C21B20ADEE3FD297FFEB02', locked='' (nft)