Maestro Provider
Use MaestroProvider from @meshsdk/core to fetch Cardano UTxOs, assets and protocol parameters, evaluate scripts and submit transactions through Maestro.
MaestroProvider connects Mesh to the Maestro Cardano API with a network name and an API key. It ships in @meshsdk/core (re-exported from @meshsdk/provider) and implements the fetcher, submitter, evaluator and listener interfaces, so you can pass it anywhere Mesh asks for a provider.
When to use Maestro:
- You already have a Maestro API key, or want a hosted API instead of running your own node
- You want transaction submission through Maestro's transaction manager, with an optional turbo submit endpoint
- You need script evaluation and UTxO queries from the same hosted service
How do I connect to Maestro?
import { MaestroProvider } from "@meshsdk/core";
const provider = new MaestroProvider({
network: "Preprod",
apiKey: "<YOUR_API_KEY>",
});
// Fetch UTxOs for an address
const utxos = await provider.fetchAddressUTxOs(
"addr_test1qpvx0sacufuypa2k4sngk7q40zc5c4npl337uusdh64kv0uafhxhu32dys6pvn6wlw8dav6cmp4pmtv7cc3yel9uu0nq93swx9"
);Create an API key for the network you target in your Maestro account. See the Maestro documentation for plans and key management.
What options does MaestroProvider take?
| Option | Type | Required | Description |
|---|---|---|---|
network | "Mainnet" | "Preprod" | "Preview" | Yes | Network to query. Requests go to https://<network>.gomaestro-api.org/v1 |
apiKey | string | Yes | Your Maestro API key, sent as the api-key header |
turboSubmit | boolean | No | Submit through txmanager/turbosubmit instead of txmanager. Defaults to false |
The API key belongs to one network. A Preprod key does not work against Mainnet.
API Reference
fetchAccountInfo
Retrieve staking information for a stake address.
const accountInfo = await provider.fetchAccountInfo(
"stake_test1uzw5mnt7g4xjgdqkfa80hrk7kdvds6sa4k0vvgjvlj7w8eskffj2n"
);fetchAddressAssets
Retrieve the native assets held at an address, as a map of asset unit to quantity.
const assets = await provider.fetchAddressAssets(
"addr_test1qpvx0sacufuypa2k4sngk7q40zc5c4npl337uusdh64kv0uafhxhu32dys6pvn6wlw8dav6cmp4pmtv7cc3yel9uu0nq93swx9"
);fetchAddressUTxOs
Retrieve all UTxOs controlled by an address. Optionally filter by a specific asset.
// All UTxOs
const utxos = await provider.fetchAddressUTxOs(
"addr_test1qpvx0sacufuypa2k4sngk7q40zc5c4npl337uusdh64kv0uafhxhu32dys6pvn6wlw8dav6cmp4pmtv7cc3yel9uu0nq93swx9"
);
// UTxOs containing a specific asset
const filteredUtxos = await provider.fetchAddressUTxOs(
"addr_test1qpvx0sacufuypa2k4sngk7q40zc5c4npl337uusdh64kv0uafhxhu32dys6pvn6wlw8dav6cmp4pmtv7cc3yel9uu0nq93swx9",
"d9312da562da182b02322fd8acb536f37eb9d29fba7c49dc172555274d657368546f6b656e"
);| Parameter | Type | Required | Description |
|---|---|---|---|
address | string | Yes | Bech32 address to query |
asset | string | No | Asset unit (policy ID + asset name hex) to filter by |
fetchAssetAddresses
Find all addresses holding a specific asset.
const addresses = await provider.fetchAssetAddresses(
"d9312da562da182b02322fd8acb536f37eb9d29fba7c49dc172555274d657368546f6b656e"
);fetchAssetMetadata
Retrieve on-chain metadata for a specific asset.
const metadata = await provider.fetchAssetMetadata(
"d9312da562da182b02322fd8acb536f37eb9d29fba7c49dc172555274d657368546f6b656e"
);fetchBlockInfo
Retrieve information about a specific block by its hash.
const blockInfo = await provider.fetchBlockInfo(
"79f60880b097ec7dabb81f75f0b52fedf5e922d4f779a11c0c432dcf22c56089"
);fetchCollectionAssets
Retrieve assets minted under a policy ID. Pass the returned next cursor to get the following page.
const { assets, next } = await provider.fetchCollectionAssets(
"d9312da562da182b02322fd8acb536f37eb9d29fba7c49dc17255527"
);| Parameter | Type | Required | Description |
|---|---|---|---|
policyId | string | Yes | Policy ID of the collection |
cursor | string | No | Cursor returned as next by the previous call |
fetchHandleAddress and fetchHandle
Resolve an ADA Handle to its address, or fetch the handle's metadata. Maestro supports handles on Mainnet only; on Preprod and Preview both methods throw.
const address = await provider.fetchHandleAddress("meshsdk");
const handleData = await provider.fetchHandle("meshsdk");fetchProtocolParameters
Retrieve the protocol parameters of the latest epoch. Maestro does not return parameters for a past epoch: passing an epoch argument throws.
const params = await provider.fetchProtocolParameters();fetchTxInfo
Retrieve details of a confirmed transaction.
const txInfo = await provider.fetchTxInfo(
"f4ec9833a3bf95403d395f699bc564938f3419537e7fb5084425d3838a4b6159"
);fetchUTxOs
Retrieve the outputs of a transaction, optionally filtering by output index.
// All outputs
const utxos = await provider.fetchUTxOs(
"dfd2a2616e6154a092807b1ceebb9ddcadc0f22cf5c8e0e6b0757815083ccb70"
);
// Specific output
const singleUtxo = await provider.fetchUTxOs(
"dfd2a2616e6154a092807b1ceebb9ddcadc0f22cf5c8e0e6b0757815083ccb70",
0
);evaluateTx
Evaluate execution units for a transaction containing Plutus scripts.
import { MaestroProvider, TxBuilder } from "@meshsdk/core";
const provider = new MaestroProvider({ network: "Preprod", apiKey: "<YOUR_API_KEY>" });
const builder = new TxBuilder({ network: "preprod", provider });
const built = await builder.build(
[
// ... your parts, such as spend.plutus(...)
],
{ payer: wallet },
);
const evaluation = await provider.evaluateTx(built.tx);The result is a list of redeemer budgets with index, tag and budget: { mem, steps }, the same shape every Mesh evaluator returns.
submitTx
Submit a signed transaction to the network. Returns the transaction hash.
const txHash = await provider.submitTx(signedTx);onTxConfirmed
Poll every 5 seconds until the transaction is in a block with at least one confirmation, then call callback. limit (default 100) caps the number of failed lookups.
provider.onTxConfirmed(txHash, () => {
console.log("Transaction confirmed!");
});get and post
Make custom requests to any Maestro endpoint, relative to https://<network>.gomaestro-api.org/v1.
const data = await provider.get("transactions/f4ec9833a3bf95403d395f699bc564938f3419537e7fb5084425d3838a4b6159");Which methods does Maestro not support?
These methods exist on MaestroProvider but throw Method not implemented in @meshsdk/[email protected], the version @meshsdk/[email protected] depends on:
fetchAddressTxsfetchGovernanceProposal
Use Blockfrost or Koios for these queries.
Complete Example
To build, sign and submit a transaction, pass the provider to a wallet and to TxBuilder. See Headless wallet for a wallet created with a MaestroProvider, and Transaction basics for building the transaction.
Troubleshooting
401 or 403 error
The API key is missing, invalid, or belongs to a different network. Check that network matches the network of the key.
"Does not support fetching addresses by handle on non-mainnet networks."
fetchHandle and fetchHandleAddress only work with network: "Mainnet".
"Maestro only supports fetching Protocol parameters of the latest completed epoch."
Call fetchProtocolParameters() without an epoch.
References
- Maestro documentation - Maestro API reference and account setup
- Cardano Developer Portal - Official Cardano development resources
Related
- All Providers - Compare Maestro with other providers
- Transaction Builder - Build transactions using provider data
- Testnet setup - Get test ADA and keys for Preprod and Preview