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

feat: get utxo from script based on params

jinglescode opened this issue · comments

propose to have a reusable function getUtxoFromSciprt() where it fetches the UTXOs needed to redeem value of a transaction. This function should be general enough such that it can support any smart contract especially those in aiken lib.

reference:

async function _getAssetUtxo({scriptAddress, asset, datum}) {
  const blockfrostProvider = new BlockfrostProvider(
    '<blockfrostApiKey>',
  );
  const utxos = await blockfrostProvider.fetchAddressUTxOs(
    scriptAddress,
    asset
  );
  const dataHash = resolveDataHash(datum);
  let utxo = utxos.find((utxo: any) => {
    return utxo.output.dataHash == dataHash;
  });
  return utxo;
};

For example for AIken Vesting contract:

image