Skip to main content

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. First, list the token types you have created so far, as you need their IDs to mint tokens of these types. Run the following command from the alphabill-wallet/build directory:

    ./abwallet wallet token list-types \
    --rpc-url https://tokens-partition.testnet.alphabill.org
    Example response:
    ID=124F7464FDD7210C3471B0390F6E5EF4DBDE4F6E4BFA957781DE1AFB1CA3BA4A, symbol=CHILD2_FT (fungible)
    ID=C1FDCF5A23666E117156979B68E46C7AD1C52DC4DFB5FE2008161418F2EBEC06, symbol=CHILD_FT (fungible)
    ID=8518FC9357540BE4E04BE1334A166B223FC57305FAD9FF979B04247DD0CF11E9, symbol=PARENT_FT (fungible)
    ID=982B06B35FF5965B47F0CF28F7FAC835BD8250AC2F0E8C16999C57D2BDD9F98A, symbol=SIMPLE_FT (fungible)
    ID=56A5A46B1DD23E7684E735B056D5AF52B490AC68B7E4A14407923895E26C57ED, symbol=PARENT_NFT (nft)
    ID=41E4FA487E37E524C13F69985B4F786E053B6BA7D92EFBC20502FAC4461D65E2, symbol=CHILD_NFT (nft)
  2. 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, values <true|false|ptpkh> (default "ptpkh")
    -h, --help help for fungible
    -k, --key uint which key to use for sending the transaction (default 1)
    --mint-input strings input to satisfy the type's minting clause (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, ecs
    --log-level string logging level, one of: DEBUG, INFO, WARN, ERROR
    --logger-config string logger config file URL. Considered absolute if starts with '/'. Otherwise relative from $AB_HOME. (default "logger-config.yaml")
    --metrics string metrics exporter, disabled when not set. One of: stdout, prometheus
    -p, --password password (interactive from prompt)
    --pn string password (non-interactive from args)
    -r, --rpc-url string rpc node url (default "localhost:28866")
    --tracing string traces exporter, disabled when not set. One of: stdout, otlptracehttp, otlptracegrpc, zipkin
    -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: SIMPLE_FT, PARENT_FT, CHILD_FT, and CHILD2_FT. These token types use the default mint clause, ptpkh, from your wallet's default public key.

  3. Start minting some fungible tokens of the CHILD_FT type. Since the mint clauses are inherited, child-type tokens inherit the default ptpkh mint clause from their parent type, which in this case is PARENT_FT. 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 CHILD_FT_TYPE_ID \
    --rpc-url https://tokens-partition.testnet.alphabill.org
    Example response:
    Sent request for new fungible token with id=4461DB73F5B10308DD4710C4EA4433EE9747E4F166C836FF237A93F74CFC144321
    Paid 0.000'000'03 fees for transaction(s).
  4. After the command succeeds, sync the wallet to see the result:

    ./abwallet wallet token list --key 1 \
    --rpc-url https://tokens-partition.testnet.alphabill.org
    Example response:
    Tokens owned by account #1
    ID='4461DB73F5B10308DD4710C4EA4433EE9747E4F166C836FF237A93F74CFC144321', symbol='CHILD_FT', amount='100.000'000'00', token-type='C1FDCF5A23666E117156979B68E46C7AD1C52DC4DFB5FE2008161418F2EBEC06' (fungible)

    You have successfully minted 100 tokens of the fungible child type 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, values <true|false|ptpkh> (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, values <true|false|ptpkh> (default "true")
    -h, --help help for non-fungible
    -k, --key uint which key to use for sending the transaction (default 1)
    --mint-input strings input to satisfy the type's minting clause (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, ecs
    --log-level string logging level, one of: DEBUG, INFO, WARN, ERROR
    --logger-config string logger config file URL. Considered absolute if starts with '/'. Otherwise relative from $AB_HOME. (default "logger-config.yaml")
    --metrics string metrics exporter, disabled when not set. One of: stdout, prometheus
    -p, --password password (interactive from prompt)
    --pn string password (non-interactive from args)
    -r, --rpc-url string rpc node url (default "localhost:28866")
    --tracing string traces exporter, disabled when not set. One of: stdout, otlptracehttp, otlptracegrpc, zipkin
    -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: mint clauses for both the parent and child types you need to satisfy.
    • --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 child NFT type to mint an NFT. Replace the --type, --token-uri, --name and --data fields with your actual values and run the following command:

    ./abwallet wallet token new non-fungible \
    --mint-input ptpkh:2,ptpkh:1 \
    --type CHILD_NFT_TYPE_ID \
    --data-update-clause ptpkh \
    --token-uri NFT_URI \
    --name NFT_NAME \
    --data CUSTOM_HEX_STRING \
    --rpc-url https://tokens-partition.testnet.alphabill.org
    Example response:
    Sent request for new non-fungible token with id=D573E55A6EFED5A9E8B6B374D9E814CB596C489D9C08DD24BA550FC741F58C3B
    Paid 0.000'000'03 fees for transaction(s).
    important

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

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

    ./abwallet wallet token list --key 1 \
    --rpc-url https://tokens-partition.testnet.alphabill.org
    Example response:
    Tokens owned by account #1
    ID='4461DB73F5B10308DD4710C4EA4433EE9747E4F166C836FF237A93F74CFC144321', symbol='CHILD_FT', amount='100.000'000'00', token-type='C1FDCF5A23666E117156979B68E46C7AD1C52DC4DFB5FE2008161418F2EBEC06' (fungible)
    ID='D573E55A6EFED5A9E8B6B374D9E814CB596C489D9C08DD24BA550FC741F58C3B', symbol='CHILD_NFT', name='MY_NFT', token-type='41E4FA487E37E524C13F69985B4F786E053B6BA7D92EFBC20502FAC4461D65E2' (nft)