MaestroFetcherSubmitterListenerEvaluator
Accessing and processing information stored on the blockchain
Maestro is the complete Web3 stack for Cardano which provides among others:-
- ⛓️ Enterprise-grade onchain data access.
- ⚡️ Transaction monitoring system with submission retires, rollback notifications and accelerated tranaction finality.
- 💰 High-fidelity smart contract data feeds from top Cardano DeFi protocols.
- 📝 Fully managed smart contract APIs and ready-to-go UI plugins.
Get started:
const MaestroProvider = new MaestroProvider({ network: 'Preprod', apiKey: '<Your-API-Key>', // Get yours by visiting https://docs.gomaestro.org/docs/Getting-started/Sign-up-login. turboSubmit: false // Read about paid turbo transaction submission feature at https://docs.gomaestro.org/docs/Dapp%20Platform/Turbo%20Transaction. });
Choose network for this demo:
fetchAccountInfoFetcher
Fetch account infomation
await maestroProvider.fetchAccountInfo( 'stake_test1uzx0ksy9f4qnj2mzfdncqyjy84sszh64w43853nug5pedjgytgke9', )
fetchAddressUtxosFetcher
Fetch UTXOs in the provided address
. Optionally, you can filter UTXOs containing a particular asset by providing asset
, where it is the concatenation of policy ID and asset.
await maestroProvider.fetchAddressUTxOs( 'addr_test1vpvx0sacufuypa2k4sngk7q40zc5c4npl337uusdh64kv0c7e4cxr', 'd9312da562da182b02322fd8acb536f37eb9d29fba7c49dc172555274d657368546f6b656e', )
fetchAssetAddressesFetcher
Fetch a list of a addresses containing a specific asset
where it is the concatenation of policy ID and asset.
await maestroProvider.fetchAssetAddresses( 'd9312da562da182b02322fd8acb536f37eb9d29fba7c49dc172555274d657368546f6b656e', )
fetchAssetMetadataFetcher
Fetch the asset metadata by providing asset's unit
, which is the concatenation of policy ID and asset name in hex.
await maestroProvider.fetchAssetMetadata( 'd9312da562da182b02322fd8acb536f37eb9d29fba7c49dc172555274d657368546f6b656e', )
fetchBlockInfoFetcher
Fetch block infomation. You can get the hash from fetchTxInfo()
.
await maestroProvider.fetchBlockInfo( '79f60880b097ec7dabb81f75f0b52fedf5e922d4f779a11c0c432dcf22c56089', )
fetchCollectionAssetsFetcher
Fetch a list of assets belonging to a collection by providing its Policy ID.
await maestroProvider.fetchCollectionAssets( 'd9312da562da182b02322fd8acb536f37eb9d29fba7c49dc17255527', , )
The API will return a list of assets
and a cursor next
. If the cursor is not null, you can use it to fetch the next page of results. Here is an example of the response.
{ "assets": [ { "unit": "d9312da562da182b02322fd8acb536f37eb9d29fba7c49dc172555274d657368546f6b656e", "quantity": "1" }, ], "next": null }
fetchHandleAddressFetcher
ADA Handle allows users to use a human-readable "Handle" to associate an address.
Each Handle is a unique NFT, minted and issued on the Cardano blockchain. These NFTs act as unique identifiers for the UTXO that they reside in.
Working together with maestroProvider
, we can resolve the handle's address with this API.
await maestroProvider.fetchHandleAddress( 'jingles', )
Note: if you get an error here, you could be on the wrong network. Change the provider's network at the top of the page.
fetchProtocolParametersFetcher
Fetch the latest protocol parameters. Optionally, you can provide an epoch number to fetch the protocol parameters of that epoch.
await maestroProvider.fetchProtocolParameters()
fetchTxInfoFetcher
Fetch transaction infomation. Only confirmed transaction can be retrieved.
await maestroProvider.fetchTxInfo( 'f4ec9833a3bf95403d395f699bc564938f3419537e7fb5084425d3838a4b6159', )
evaluateTxEvaluator
evaluateTx()
accepts an unsigned transaction (unsignedTx
) and it evaluates the resources required to execute the transaction. Note that, this is only valid for transaction interacting with redeemer (smart contract). By knowing the budget required, you can use this to adjust the redeemer's budget so you don't spend more than you need to execute transactions for this smart contract.
const unsignedTx = await tx.build(); const evaluateTx = await maestroProvider.evaluateTx(unsignedTx);
Example responses from unlocking assets from the always succeed smart contract.
[ { "index": 0, "tag": "SPEND", "budget": { "mem": 1700, "steps": 368100 } } ]
With the mem
and steps
, you can refine the budget for the redeemer. For example:
const redeemer = { data: { alternative: 0, fields: [...] }, budget: { mem: 1700, steps: 368100, }, };
Unlock an asset from the always succeed to check how much it takes to execute this transaction.
submitTxSubmitter
Submit a serialized transaction to the network.
await maestroProvider.submitTx(signedTx)
onTxConfirmedListener
Allow you to listen to a transaction confirmation. Upon confirmation, the callback will be called.
const tx = new Transaction({ initiator: wallet }); tx.sendLovelace('addr_test1vpvx0sacufuypa2k4sngk7q40zc5c4npl337uusdh64kv0c7e4cxr', '5000000'); const unsignedTx = await tx.build(); const signedTx = await wallet.signTx(unsignedTx); const txHash = await wallet.submitTx(signedTx); maestroProvider.onTxConfirmed(txHash, () => { console.log('Transaction confirmed'); });