cardano-serialization-lib
cardano-serialization-lib copied to clipboard
UTXO Balance Insufficient error when using RandomImproveMultiAsset
We have integrated with Cardano web wallet in our DApp built using ReactJS.
While attempting to transfer tokens we get the error "UTXO Balance Insufficient". We are passing in all the UTXOs of the user wallet to the transaction body. In our case, the user has around ~81 ADA and 100 tokens in the wallet, so the user has sufficient funds to make a transfer operation. But when we do a transfer we get the UTXO Balance Insufficient Error
Here is the code from our DApp
`
const txBuilder = await initTransactionBuilder();
const changeAddress = await getChangeAddress();
const shelleyOutputAddress = Address.from_bech32(transferWalletAddress);
const shelleyChangeAddress = Address.from_bech32(changeAddress);
let txOutputBuilder = TransactionOutputBuilder.new();
txOutputBuilder = await txOutputBuilder.with_address(shelleyOutputAddress);
txOutputBuilder = await txOutputBuilder.next();
const multiAsset = MultiAsset.new();
const assets = Assets.new();
assets.insert(
AssetName.new(Buffer.from(assetNameHex, 'hex')), // Asset Name
BigNum.from_str(assetQuantity) // How much to send
);
multiAsset.insert(
ScriptHash.from_bytes(Buffer.from(assetPolicyIdHex, 'hex')), // PolicyID
assets
);
txOutputBuilder = txOutputBuilder.with_asset_and_min_required_coin(multiAsset, BigNum.from_str(protocolParams.coinsPerUtxoWord));
const txOutput = txOutputBuilder.build();
await txBuilder.add_output(txOutput);
// Find the available UTXOs in the wallet and
// use them as Inputs
const txUnspentOutputs = await getTxUnspentOutputs();
txBuilder.add_inputs_from(txUnspentOutputs, 3);
// calculate the min fee required and send any change to an address
txBuilder.add_change_if_needed(shelleyChangeAddress);
// once the transaction is ready, we build it to get the tx body without witnesses
const txBody = await txBuilder.build();
` In the add_inputs_from method we are using the strategy RandomImproveMultiAsset Our expectation is that this will pick the best UTXO (combination of UTXOs) to service the request, however we occassionally get the error UTxO Balance Insufficient What could be going wrong?