-
Notifications
You must be signed in to change notification settings - Fork 137
Closed
Milestone
Description
Hy everyone.
I try to implement the Nami Wallet on one of my website and so I use this library to generate transaction.
I have a performance issue with the function add_change_if_needed(), it took 50sc to be execute on google chrome.
The transaction is very simple :send X ADA to one address.
I'm using the 9.1.0 version full JS.
Here some code:
async function pay(addr, adaAmount){
const cardano = window.cardano
const protocolParameters = await getProtocolParameters()
const lovelace = (parseFloat(adaAmount) * 1000000).toString()
var ByteAddress = await window.cardano.getUsedAddresses();
const paymentAddr = await S.Address.from_bytes(fromHex(ByteAddress[0])).to_bech32();
const rawUtxo = await cardano.getUtxos()
const utxos = rawUtxo.map(u => S.TransactionUnspentOutput.from_bytes(fromHex(u)))
const outputs = S.TransactionOutputs.new()
outputs.add(
S.TransactionOutput.new(
S.Address.from_bech32(addr),
S.Value.new(
S.BigNum.from_str(lovelace)
)
)
)
const output = S.TransactionOutput.new(
S.Address.from_bech32(addr),
S.Value.new(
S.BigNum.from_str(lovelace)
)
)
CoinSelection.setProtocolParameters(
protocolParameters.minUtxo.to_str(),
protocolParameters.linearFee.coefficient().to_str(),
protocolParameters.linearFee.constant().to_str(),
protocolParameters.maxTxSize.toString()
);
const selection = await CoinSelection.randomImprove(
utxos,
outputs,
20,
//protocolParameters.minUtxo.to_str()
);
const inputs = selection.input;
const txBuilder = S.TransactionBuilder.new(
protocolParameters.linearFee,
protocolParameters.minUtxo,
protocolParameters.poolDeposit,
protocolParameters.keyDeposit,
protocolParameters.maxValSize,
protocolParameters.maxTxSize
);
for (let i = 0; i < inputs.length; i++) {
const utxo = inputs[i];
txBuilder.add_input(
utxo.output().address(),
utxo.input(),
utxo.output().amount()
);
}
txBuilder.add_output(output);
txBuilder.set_ttl(410021);
txBuilder.add_change_if_needed(
S.Address.from_bech32(paymentAddr)
);
There is no error and the transaction is send and can be signed.
If someone can help me thanks
Metadata
Metadata
Assignees
Labels
No labels