@blocktorch/0xdragon v2.1.0
:dragon_face: Blocktorch Dragon SDK :dragon_face:
Track failing and successful web3 client transactions and get insights about your customers!
Installation
npm install @blocktorch/0xdragon
Usage
SDK initialization
You can get your project ID and api key from the Blocktorch app on the Settings page :rocket:
import { Dragon } from '@blocktorch/0xdragon'
const dragon = new Dragon({
projectId: <your-project-id>,
apiKey: <your-blocktorch-api-key>
})
In the constructor you can also specify additional options:
contractName
(string) - default identifier for what the transactions are interacting with. Default is "unknown"chainId
(number) - chain ID of the applicationhttp
(object):maxRetries
(number) - number of times failed SDK requests are retrieddelay
(number) - number of times failed SDK requests are retriedexponentialBackoff
(boolean) - Whether to allow exponential backoff or not
init(options?)
Initialize the tracking of a single transaction
const id = dragon.init()
You can override options per transaction.
contract
(string) - identifier for what the transaction is interacting withchainId
(number) - id of the blockchain
success(id, transaction)
Track the transaction as a success. Should be done after the transaction is accepted on chain.
await dragon.success(id, transaction)
error(id, error)
Track the transaction as an error
await dragon.error(id, error)
wrap(fn, options?)
If you are using ethers@5 or any other compatible libraries you can use a helper function to wrap your whole transaction and it will detect success or failure itself. It will wait until the transaction receipt is received to mark it as a success.
await dragon.wrap(
contract.doSmth({ value: ethers.utils.parseEther("0.1") })
)
You can also specify the following options:
contract
(string) - identifier for what the transaction is interacting withchainId
(number) - id of the blockchain
:dragon_face::dragon_face::dragon_face::dragon_face::dragon_face: