nami icon indicating copy to clipboard operation
nami copied to clipboard

Getting UTXO balance insufficient error for token transfer

Open Karthi96 opened this issue 3 years ago • 2 comments
trafficstars

Hi,

we have integrated the Nami wallet into our DApp and we are using ReactJS as a programming language. The use case we are trying to do is transfer the tokens from the user wallet to the other user.

For token transfer, we are getting all the UTXOs of the user wallet and passing them all to the transaction body. In our case, the user has around ~81 ADA and 100 tokens in the wallet, so that means he has sufficient funds to make a transfer operation. But when we do a transfer we are getting the error as UTXO Balance Insufficient Error but when we do a direct transfer from nami wallet, it is getting success.

so the problem is why we are not able to submit the transaction when we submit using nami? As per your documentation, you are saying to pass all the UTXOs to the transaction body, then why are we getting this error?

How do we resolve this or are we missing anything here?

Attaching the UTXos of the user wallet addr_test1qr0jvqh3yv7r5z7mpnnyd4pjsquxvdltcdgxgc6ws535ntqu08537zvx8rvclq63hg7d2amtzk57m9qg8vngjhcd9nwsvg5nzl before transfer and after transferring for reference.

Screenshot from 2022-06-15 17-49-31

Transaction Hash - https://testnet.cardanoscan.io/transaction/617a2d70de12ead82e73c3c5170b68e1cf02a4eeab5eaf8cb49bdc9b84e7126c

Here is the code what we are using in 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
      // us 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();

Karthi96 avatar Jun 17 '22 04:06 Karthi96

But just wondering how Nami deals with it? Can we see the snippet for transferring the tokens using nami ?

Karthi96 avatar Jul 01 '22 01:07 Karthi96

Problem: Randomly User Receive error - Not enough ADA leftover to include non-ADA assets in a change address As this error is occurring randomly. Unable to predict or reproduce scenarios for this bug.

UTXO Strategy used in our DAPP :

  1. LargestFirst - Performs CIP2's Largest First ada-only selection. Will error if outputs contain non-ADA assets.
  2. RandomImprove - Performs CIP2's Random Improve ada-only selection. Will error if outputs contain non-ADA assets.
  3. LargestFirstMultiAsset - Same as LargestFirst, but before adding ADA, will insert by largest-first for each asset type.
  4. RandomImproveMultiAsset - Same as RandomImprove, but before adding ADA, will insert by random-improve for each asset type. Currently, We are using RandomImproveMultiAsset Strategy.

Testing Scenarios :

Tested with two wallets. New Wallet, Initially User sees error ‘Not enough ADA leftover to include non-ADA assets in a change address’. After some internal transaction and increase ada to 3+. Users are able to proceed with conversion. Old Wallet, User Observed error - ‘Not enough ADA leftover to include non-ADA assets in a change address’ again today. But, ADA Balance in the wallet is 900+.

Nami Wallet Scenario 1: Old Wallet. User able to Convert Tokens. Address - addr_test1qzre6yldxwvlakh25mn70yedgjdh434eatrslk8u8z8l2wsv8rasd6p9awayxpfsyfzrg4k0e4ww uce2wv32l85zjd3q7423uq ADA Bal - 9000+ AGIX Bal - 70+ https://testnet.cardanoscan.io/transaction/6af6f918bfdbc213a77b6d1ff6bce26c744b92c37724767 c287796e4299faa3b

Scenario 2: New Wallet. ADA Bal - 3.15 AGIX Bal - 10 Address - addr_test1qpjdkptn6rqtmkqn4d76r40724zr5tutd9a7w8f9umutd34fspw5n9y0jqyhhs6fwg5lrru5fru82 d6wcz9jddu45hrqstsye3 User unable to Convert Tokens. User see error - Not enough ADA leftover to include non-ADA assets in a change address

Scenario 3: New Wallet. ADA Bal - 3.15 AGIX Bal - 10 Addr_test1qqwf9gjra56c5sjne20fnzeggcp6d3nrar7jm23cn0mwjhmwmsjvw5vmnu0wh8n705 qae43w5wxg4kt7de68hz4e54rqeh6ccd User unable to Convert Tokens. User see error - Not enough ADA leftover to include non-ADA assets in a change address

Scenario 4: New Wallet. ADA Bal - 13.15 AGIX Bal - 10 Addr_test1qqwf9gjra56c5sjne20fnzeggcp6d3nrar7jm23cn0mwjhmwmsjvw5vmnu0wh8n705 qae43w5wxg4kt7de68hz4e54rqeh6ccd User unable to Convert Tokens. User see error - Not enough ADA leftover to include non-ADA assets in a change address

Scenaio 5: User tried to Convert a Token using an Old Wallet. But, Now, User unable to transfer tokens. So, User did a workaround. User Transferred token to another wallet, then initiated Token Conversion. Wallet - Address → addr_test1qzre6yldxwvlakh25mn70yedgjdh434eatrslk8u8z8l2wsv8rasd6p9awayxpfsyfzrg4k0e4ww uce2wv32l85zjd3q7423uq https://testnet.cardanoscan.io/transaction/d9caaa7908650106427427aa3b94d9a4add5b00174433 935114ef2ab0fcb8b1e

raghu-snet avatar Nov 09 '22 02:11 raghu-snet

@raghu-snet don't. @BenEthdev is a scammer, I've reported him.

GGAlanSmithee avatar Nov 09 '22 16:11 GGAlanSmithee