How to set a specific amount for native token when calling CIP30 api.getUtxos() method in Nami, CCvault, Flint and other CIP30-compliant wallets?

In the CIP30 spec, we are supposed to be able to get a subset of the user’s UTXOs if we specify an “amount” when calling the method getUtxos():

api.getUtxos(amount: cbor\ = undefined, paginate: Paginate = undefined): Promise\

And this “amount” parameter, is supposed to allow a Value type which further contains MultiAsset types.

But calling this method like so:

let ScriptHash = csl.ScriptHash.from_bytes( Buffer.from(policyId, "hex") );

let Assets = csl.Assets.new();
Assets.insert(
    csl.AssetName.new( Buffer.from(assetName, "hex") ),
    csl.BigNum.from_str(amount)
);

let MultiAsset = csl.MultiAsset.new();
MultiAsset.insert(ScriptHash, Assets);

let reqdValue = csl.Value.new_from_assets(MultiAsset);
let inputUtxos = await wallet.activeApi.getUtxos(reqdValue); // CIP30 method call

… always gives me the following errors.

In CCVault/Eternl:

Error: invalid input: amount: TypeError: byteaString.startsWith is not a function

In Nami:

Inputs do not conform to this spec or are otherwise invalid.

In Flint:

An error occurred during execution of this API call.

What am I doing wrong here? What is the correct way of passing a Value parameter to getUtxos()?

You need to get the latest stable release of the wallets to test with.

This is a bug. You get this error when the variable is not actually a string. If it’s your code should be an easy fix. If it’s the wallet code get the latest version and test again. If it still happens check their issues page and +1 the existing bug or open a new one with stack and example code to replicate like you did here.

I see… thank you for this info!