MeshJS / mesh

An open-source library to advance Web3 development on Cardano

Home Page:https://meshjs.dev

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Transaction build fail: UTxO Balance Insufficient

bigbenbeer opened this issue · comments

commented

The issue

Whenever I build a minting transaction, the build fails with a UTxO Balance Insufficient error. Irrespective of the wallet size (in Ada) or the number of UTXOs in the wallet.

Code to reproduce

const blockchainProvider = new KoiosProvider("api");

    // Load the wallet
    const wallet = new AppWallet({
      networkId: 1,
      fetcher: blockchainProvider,
      submitter: blockchainProvider,
      key: {
        type: "mnemonic",
        words: Phrase,
      },
    });

    // Get the policy ID
    const walletAddress = wallet.getPaymentAddress();
    const address = usedAddress.to_bech32();
    const forgingScript = ForgeScript.withOneSignature(address);

    // Build the transaction object
    const tx = new Transaction({ initiator: wallet });

    // build transaction
    const assetToMintMetadata: AssetMetadata = {
      ...metadata content ...
    };

    const asset1: Mint = {
      assetName: "TestingNFT",
      assetQuantity: "1",
      metadata: assetToMintMetadata,
      label: "721",
      recipient: {
        address:
          "addr1q9...9c7g3",
      },
    };

      tx.mintAsset(
        forgingScript,
        asset1,
      );

    const unsignedTx = await tx.build();

Stacktrace

yarn run v1.22.19
$ tsc && node ./dist/main.js
error Error: [Transaction] An error occurred during build: UTxO Balance Insufficient.
    at Object.build (file:///somedir/node_modules/@martifylabs/mesh/dist/index.js:1330:13)
    at processTicksAndRejections (node:internal/process/task_queues:96:5)
    at async main (file:///somedir/dist/main.js:47:28)
    at async file:///somedir/dist/main.js:60:1
Done in 2.77s.```
commented

Is there a way I can manually get the UTXOs and specify the input?

Is there a way I can manually get the UTXOs and specify the input?

Yup.

tx.setTxInputs(inputs: UTxO[]);

You can get UTxO from a IFetcher such as BlockfrostProvider, seefetchAddressUtxos in providers.

commented

Is there a way I can manually get the UTXOs and specify the input?

Yup.

tx.setTxInputs(inputs: UTxO[]);

You can get UTxO from a IFetcher such as BlockfrostProvider, seefetchAddressUtxos in providers.

Thanks, I will try it!

Hi!
I'm getting this same error as well.
I'm wondering if this might be because the network ID parameter is incorrectly set by me.

What would be the network ID for the preprod testnet?

I thought it was 1, but the wallet address I get from network id 1 through
wallet.getPaymentAddress();
starts with
addr1....
whereas for network id 0
it starts with
addr_test1...

I am however, getting empty arrays from
await blockchainProvider.fetchAddressUTxOs(walletAddress);
for both

So no utxos there.

Could someone point me in the right direction?

Just checked on
https://mesh.martify.io/apis/browserwallet

0 is Test-net and 1 is main-net.

I sent some funds to the paymentAddress received from
wallet.getPaymentAddress()
And it's working fine now. Thanks