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

An error occurred during build: Insufficient input in transaction. shortage: {policy id: "22f20d5382cec46166b566821f16f79cb03ee1520c71e5f83a4b3f20", asset name: "54657374746f6b656e" coins in inputs: 0, coins in outputs: 1

besiwims opened this issue · comments

core.js?3bda:2444 Uncaught (in promise) Error: [Transaction] An error occurred during build: Insufficient input in transaction. shortage: {policy id: "22f20d5382cec46166b566821f16f79cb03ee1520c71e5f83a4b3f20", asset name: "54657374746f6b656e" coins in inputs: 0, coins in outputs: 1
}.
at L.build (core.js?3bda:2444:1)
at async lockFunds (index.tsx?07ff:36:26)

What did I miss to get this error?

This is what i failed to do.

  1. The unit contruction was wrong
    [
    {
    unit: "144a5f65ed8d4d10570d28d2c6764f8c63261696da6d4baa0d35998f57494d53454255546573746e6574546f6b656e73",
    quantity: "1",
    },
    ],

How does one go about create a unit from a token?

One needs to concatenate the policy id and the hex token name.

For example:'

Policy Id : [144a5f65ed8d4d10570d28d2c6764f8c63261696da6d4baa0d35998f]
Fingerprint : asset14ptyknce53h0vfmm3kerwusxpeagju78lmxfhs
Asset Name : WIMSEBUTestnetTokens (57494d53454255546573746e6574546f6b656e73)

The Asset Name refers to the Token Name and it is in two parts namely : 1) plain text name WIMSEBUTesnetTokens 2) the name is also in hex form name is 57494d53454255546573746e6574546f6b656e73. You may ask a question : How does anyone convert text to hexa (a short form for hexadecimal :- which is a base 16 number system)? You can simple use this online service or others https://string-functions.com/string-hex.aspx

So our unit is Policy Id + Asset Name : hex = "144a5f65ed8d4d10570d28d2c6764f8c63261696da6d4baa0d35998f57494d53454255546573746e6574546f6b656e73"

The workaround, or implementation, I'm using is to first use the provider to get policy information, by id.

It will return 0 or many assets based on how many are in the policy. As long as 1 is returned, you have can pull the unit from that asset and reference it as needed.