dynamicstrategies / cardano-wallet-connector

Cardano DApps Wallet Connector - example code
MIT License
131 stars 88 forks source link

How to calculate redeemer index when have a lot input #8

Open nmaddp1995 opened 2 years ago

nmaddp1995 commented 2 years ago

Hi. in case I pass many input (utxo of buyer, utxo put onsale) How can I get redeemer index to pass in

const redeemer = CardanoWasm.Redeemer.new(
      CardanoWasm.RedeemerTag.new_spend(),
      // CardanoWasm.BigNum.zero(),
      CardanoWasm.BigNum.from_str('0'),
      redeemerData,
      CardanoWasm.ExUnits.new(
        CardanoWasm.BigNum.from_str(BUY_CARDANO_MEM.toString()),
        CardanoWasm.BigNum.from_str(BUY_CARDANO_CPU.toString()),
      ),
    );
dynamicstrategies commented 2 years ago

Hi,

You can try something like this, which is what I have to get the Datum in the right format to conform to the temple: {"fields":[{"bytes":"....."},{"bytes":"...."}],"constructor":0}

The index from your question would be const constr = BigNum.from_str("0"); in the example below

const pdDtm = PlutusData.new_bytes(Buffer.from(this.state.datumStr, 'utf8'))
const pdPkh = PlutusData.new_bytes(pkhBytes)

const plutusList = PlutusList.new()
plutusList.add(pdDtm)
plutusList.add(pdPkh)

const constr = BigNum.from_str("0");
const constrPlutusData = ConstrPlutusData.new(constr, plutusList)

const pdAgg = PlutusData.new_constr_plutus_data(constrPlutusData)
const dataHash = hash_plutus_data(pdAgg)