Comment on page
Useful tips for building a dApp by using Connex
This article will help you to understand how to use connex to build a dApp and also how it interacts with the user, application, and Sync2.
- 1.Create a testnet wallet
- 1.
- 2.Launch Sync2
- 3.
- 4.
- 2.Claim testnet token
The ticker is a concept that describes chain increment. When there is a new block added to the chain, the ticker will be triggered. This API will create a ticker that has a function that creates a Promise that will resolve when a new block is truly added, please be advised that it never rejects.
📖 Tips
progress: A number [0-1] indicates the syncing progress of the currently connected node
Account visitor is a bunch of APIs to get account details and interact with account methods.
📖 Tips
balance: hex form of VET balance in unit wei energy: hex form of VTHO balance in unit wei hasCode: when it equal to true, it means that its a smart contract
Transaction visitor is a bunch of APIs to get transaction details.
📖 Tips
Transaction receipt
reverted: Several reasons can cause the transaction to revert. It means that the transaction data is passed through to a virtual machine(aka. VM) but not able to process. The most common reasons areinsufficient balance
and smart contractnot able to execute data
. gasPayer: the address which paid the transaction fee. It is an important factor to determine the transaction is whether using fee delegation or not. If the transaction is paid by another address, thetxOrigin
andgasPayer
will be different.. txOrigin: the address which signed the transaction
It allows you to filter transfer and event logs on the blockchain. The filter usually works with
Connex.thor.account
, either creates a filter from an event or packs criteria and then assembles several criteria and sets them to a filter.📖 Tips
criteria: is a set of an array which contain aevent.criteria
ortransfer.criteria
. The items in the criteria array will be combined byOR
operator to filter the events: example: [{"ConA": "A"}, {"ConB": "B", "ConC": "C"}] is 'ConA=AOR
(ConB=BAND
ConC=C)' filterRange: Filtering a specific time frame transfer or event logs by settingblock number
ortimestamp
in second to the filter
• transfer
Filter VET transfer by setting the criteria to
txOrigin
,sender
, and recipient
.In addition, set the filterRange
of filter to determine the transfer flog in the specific period• event
Filter event by setting criteria base on the contract methods(Contract ABI).
In some cases, the application may not need the ability to access the entire blockchain. You can just create
connex.vendor
module instead of connex.thor
module.connex.vendor
is a way that allows dapps to interact with a user such as signing a certificate or transaction.Certificate: connex.vendor.sign
The certificate is a message signing-based mechanism that can easily request the user's
identification
(address) or user to agree to the agreements
.Transaction: connex.vendor.sign
Signing a transaction is the most common interaction between dApp and user.A transaction may contains one more multiple clauses(operation) that requesting the user to confirm(sign) the transaction.
📖 Tips
Transaction can contains multiple clauses and each clause contains three majors content:to
,value
anddata
. Provide a briefcomment
to the transaction or a clause to help the user to understand Provide alink
to reveal transaction-related information, the link will be used for connex to assemble a callback url by replacing the placeholder {txid} by Transaction ID
4. Address avatar
Address avatar is generated by Picasso a general purpose deterministic identity icon library in svg format
5. Sign tx and check receipt
GasPriceCoef can be adjust by the user, thus, the result of the transaction fee is the minimum cost of the transaction.
Prerequisites:
- 1.
- 2.
- we need to calculate the intrinsic gas
- we need to know the vm gasUsed (aka. virtual machine execution cost)
Step 1: Get base gas price
Step 2: Get intrinsic gas
Step 3: Get vm gas used
7. Enforce signer