QRC20 Integration Technical Guide
Last updated
Last updated
This document explains the basics of interacting with an QRC20 contract with the qtumd
CLI command tool.
The full example in PHP: .
We recommend that an exchange use one main address to store tokens for all users. Below MAIN_QRC_ADDRESS
is the main address.
The address of the QRC20 token contract is TOKEN_CONTRACT_ADDRESS
.
gas limit is DEFAULT_GAS_LIMIT
, recommended value is 250000
gas price is DEFAULT_GAS_PRICE
,recommended value is 0.00000040
TOKEN_DECIMALS
is the decimals of the token, which varies per token. Here we set it 8.
We'll use the following utility functions:
- Convert base58 address to hash160 address.
left-pad hex data to 32 bytes with 0.
multiply the nominal token amount by the number of decimal places.
You should remember to enable the indexing service when starting qtumd
, using the flags -logevents -txindex
.
In the CLI examples below, please substitute {}
with actual addresses and values.
$userAddress
is the deposit address
In the JSON output look for executionResult.output
. This is the token balance.
$userAddress
is the withdraw address
$amount
the withdraw amount in unit token
The command returns the txid
of this transaction. You may use it to find information about this transaction (e.g. number of confirmations).
For an exchange, a user may use the same address for both QTUM and other QRC20 tokens.
Use this command to generate a deposit address:
$startingBlock
is where you want to start looking (inclursive)
You can start looking from 0, but for better efficiency, you should remember where to start looking.
The event type filtered is the Transfer
event:
Look through the logs to filter by to
or from
addresses.
Given a transaction id $txid
:
Use the property confirmations
from output.