-
Notifications
You must be signed in to change notification settings - Fork 61
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: add setTxRefInputs method #150
Conversation
@jmagan is attempting to deploy a commit to the MeshJS Team on Vercel. A member of the Team first needs to authorize it. |
Hello @jmagan , |
hi!, The NonOutputSupplimentaryDatums is normally related to supply datum data to an UTxO with an inline datum. Could you please provide the transaction making script? |
yes sure, i had linked it in the issue: https://docs.google.com/document/d/1nF_S4Dy4tweYi3qbvAUibdHiObHMaSYNRcQmxyXl5sM/edit |
That information doesn't help me to find the problem. Are you including somehow again the Datum from the ref UTxO in the transaction? |
All I'm doing is using the reference UTxO in setTxRefInputs and redeeming a UTxO from the contract. The datum in the reference UTxO is irrelevant in this transaction. Could this code snippet be of any use? const tx = new Transaction({ initiator: walletData });
tx.setTxRefInputs(referenceUtxo)
tx.redeemValue({
value: depositUtxo,
script: simpleScript,
datum: depositUtxo,
redeemer: simpleRedeemer
})
tx.setCollateral(collateral)
tx.sendLovelace({ address: referenceAddr }, "4000000");
const unsignedMeshTx = await tx.build();
const signedTx = await walletData.signTx(unsignedMeshTx, true)
const txHash = await walletData.submitTx(signedTx);
return txHash; |
I tried to reproduce the error but it wasn't possible. I used this code and the script failed to validate. import Head from "next/head";
import { CardanoWallet, useWallet } from "@meshsdk/react";
import { KoiosProvider, Transaction } from "@meshsdk/core";
import { useEffect, useState } from "react";
export default function Home() {
const { wallet: walletData } = useWallet();
const [utxo, setUtxo] = useState(null);
const [referenceUtxo, setReferenceUtxo] = useState(null);
const simpleScript = {
version: "V2",
code: "5908f35908f0010000332323232332232323232323232323233223232323232323232323222223232533532325335533533355300a120013233500e223335003220020020013500122001123300122533500210011021020200150011333573466e1cc8cccd54c02c48004c8cd403c88ccd404000c004008d4034005402888cdc0000a400400290002800a400403e03c203c203e266ae7124111496e76616c6964205265666572656e63650001e13333553009120015008223535002220012222335018333573466e1cd403488c8c8c00401cc8004d540ac88cd400520002235002225335333573466e3c0080240b40b04c01c0044c01800cc8004d540a888cd400520002235002225335333573466e3c00801c0b00ac40044c01800d200202402300535350012200222222222222200b50133333573466e1cd55cea80124000466442466002006004646464646464646464646464646666ae68cdc39aab9d500c480008cccccccccccc88888888888848cccccccccccc00403403002c02802402001c01801401000c008cd406c070d5d0a80619a80d80e1aba1500b33501b01d35742a014666aa03eeb94078d5d0a804999aa80fbae501e35742a01066a03604c6ae85401cccd5407c09dd69aba150063232323333573466e1cd55cea801240004664424660020060046464646666ae68cdc39aab9d5002480008cc8848cc00400c008cd40c5d69aba150023032357426ae8940088c98c80d8cd5ce01b81b01a09aab9e5001137540026ae854008c8c8c8cccd5cd19b8735573aa004900011991091980080180119a818bad35742a00460646ae84d5d1280111931901b19ab9c037036034135573ca00226ea8004d5d09aba2500223263203233573806606406026aae7940044dd50009aba1500533501b75c6ae854010ccd5407c08c8004d5d0a801999aa80fbae200135742a004604a6ae84d5d1280111931901719ab9c02f02e02c135744a00226ae8940044d5d1280089aba25001135744a00226ae8940044d5d1280089aba25001135744a00226ae8940044d55cf280089baa00135742a004602a6ae84d5d1280111931901019ab9c02102001e101f13263201f3357389201035054350001f135573ca00226ea80044cd4010888c00cc0080048004c8004d5406488448894cd40044d401800c884ccd4024014c010008ccd54c01c4800401401000448d40048800448d40048800848848cc00400c00848c88c008dd6000990009aa80b111999aab9f0012500a233500930043574200460066ae880080588c8c8cccd5cd19b8735573aa004900011991091980080180118061aba150023005357426ae8940088c98c8058cd5ce00b80b00a09aab9e5001137540024646464646666ae68cdc39aab9d5004480008cccc888848cccc00401401000c008c8c8c8cccd5cd19b8735573aa0049000119910919800801801180a9aba1500233500f014357426ae8940088c98c806ccd5ce00e00d80c89aab9e5001137540026ae854010ccd54021d728039aba150033232323333573466e1d4005200423212223002004357426aae79400c8cccd5cd19b875002480088c84888c004010dd71aba135573ca00846666ae68cdc3a801a400042444006464c6403a66ae7007807406c0680644d55cea80089baa00135742a00466a016eb8d5d09aba2500223263201733573803002e02a26ae8940044d5d1280089aab9e500113754002266aa002eb9d6889119118011bab00132001355013223233335573e0044a010466a00e66442466002006004600c6aae754008c014d55cf280118021aba200301413574200222440042442446600200800624464646666ae68cdc3a800a40004642446004006600a6ae84d55cf280191999ab9a3370ea0049001109100091931900919ab9c01301201000f135573aa00226ea80048c8c8cccd5cd19b875001480188c848888c010014c01cd5d09aab9e500323333573466e1d400920042321222230020053009357426aae7940108cccd5cd19b875003480088c848888c004014c01cd5d09aab9e500523333573466e1d40112000232122223003005375c6ae84d55cf280311931900919ab9c01301201000f00e00d135573aa00226ea80048c8c8cccd5cd19b8735573aa004900011991091980080180118029aba15002375a6ae84d5d1280111931900719ab9c00f00e00c135573ca00226ea80048c8cccd5cd19b8735573aa002900011bae357426aae7940088c98c8030cd5ce00680600509baa001232323232323333573466e1d4005200c21222222200323333573466e1d4009200a21222222200423333573466e1d400d2008233221222222233001009008375c6ae854014dd69aba135744a00a46666ae68cdc3a8022400c4664424444444660040120106eb8d5d0a8039bae357426ae89401c8cccd5cd19b875005480108cc8848888888cc018024020c030d5d0a8049bae357426ae8940248cccd5cd19b875006480088c848888888c01c020c034d5d09aab9e500b23333573466e1d401d2000232122222223005008300e357426aae7940308c98c8054cd5ce00b00a80980900880800780700689aab9d5004135573ca00626aae7940084d55cf280089baa0012323232323333573466e1d400520022333222122333001005004003375a6ae854010dd69aba15003375a6ae84d5d1280191999ab9a3370ea0049000119091180100198041aba135573ca00c464c6401c66ae7003c03803002c4d55cea80189aba25001135573ca00226ea80048c8c8cccd5cd19b875001480088c8488c00400cdd71aba135573ca00646666ae68cdc3a8012400046424460040066eb8d5d09aab9e500423263200b33573801801601201026aae7540044dd500089119191999ab9a3370ea00290021091100091999ab9a3370ea00490011190911180180218031aba135573ca00846666ae68cdc3a801a400042444004464c6401866ae700340300280240204d55cea80089baa0012323333573466e1d40052002200523333573466e1d40092000200523263200833573801201000c00a26aae74dd5000891001091000a4c24002921035054310011232300100122330033002002001335122335500248811c34e6054e3e74ecf4a9b6eb4e34a865f6b0b5fee85e6a9bfba0d2d0250048810341424300112212330010030021120011",
};
useEffect(() => {
const go = async () => {
const koiosProvider = new KoiosProvider(
"https://preview.koios.rest/api/v0/"
);
const utxos = await koiosProvider.fetchAddressUTxOs(
"addr_test1wrv8xdx5kakqnj2whs936fc7fste23epn76em6gqftxl9kqjpx62c"
);
console.log(utxos);
setUtxo(utxos[0]);
const referenceUTxOs = await koiosProvider.fetchAddressUTxOs(
"addr_test1qr0k5uczwvzdt6g6c2e9l92r24f528dfnmu9qq6lssrc3z56l3lczn30u56k4vlf948etel5d63zj20yg6wymu2gp4gsyum3sz"
);
const referenceUTxO = referenceUTxOs.find(
(u) =>
u.input.txHash ===
"45e4b496d192ef91112193e20db8c8d28df414cf4e9f5e6268b4e730b81b0f66"
);
console.log("Reference UTxO", referenceUTxO);
setReferenceUtxo(referenceUTxO);
};
go();
}, []);
const sendTx = async () => {
const referenceUtxo = utxo;
const depositUtxo = utxo;
const tx = new Transaction({ initiator: walletData });
tx.setTxRefInputs([referenceUtxo]);
tx.redeemValue({
value: depositUtxo,
script: simpleScript,
datum: depositUtxo,
redeemer: { alternative: 0, fields: [] },
});
tx.setCollateral(await walletData.getCollateral());
const myAddress = (await walletData.getUnusedAddresses())[0];
console.log("My Address", myAddress);
tx.setRequiredSigners([myAddress]);
tx.setChangeAddress(myAddress);
tx.sendLovelace({ address: myAddress }, "4000000");
const unsignedMeshTx = await tx.build();
const signedTx = await walletData.signTx(unsignedMeshTx, true);
const txHash = await walletData.submitTx(signedTx);
console.log("Tx Hash", txHash);
};
return (
<div className="container">
<main className="main">
<h1 className="title">
<a href="https://meshjs.dev/">Mesh</a> Next.js
</h1>
{JSON.stringify(utxo)}
<div className="demo">
<CardanoWallet />
</div>
<button style={{ marginTop: "300px" }} onClick={sendTx}>
Send Tx
</button>
</main>
</div>
);
} |
I see you used the deposit utxo as reference input. Here, i have reproduced the error in this code. i set the datum to [ ] in import Head from "next/head";
import { CardanoWallet, useWallet } from "@meshsdk/react";
import { KoiosProvider, Transaction } from "@meshsdk/core";
import { useEffect, useState } from "react";
import * as CSL from "@emurgo/cardano-serialization-lib-asmjs"
export default function Home() {
const { wallet: walletData } = useWallet();
const [utxo, setUtxo] = useState(null);
const [referenceUtxo, setReferenceUtxo] = useState(null);
const simpleScript = {
version: "V2",
code: "5908f35908f0010000332323232332232323232323232323233223232323232323232323222223232533532325335533533355300a120013233500e223335003220020020013500122001123300122533500210011021020200150011333573466e1cc8cccd54c02c48004c8cd403c88ccd404000c004008d4034005402888cdc0000a400400290002800a400403e03c203c203e266ae7124111496e76616c6964205265666572656e63650001e13333553009120015008223535002220012222335018333573466e1cd403488c8c8c00401cc8004d540ac88cd400520002235002225335333573466e3c0080240b40b04c01c0044c01800cc8004d540a888cd400520002235002225335333573466e3c00801c0b00ac40044c01800d200202402300535350012200222222222222200b50133333573466e1cd55cea80124000466442466002006004646464646464646464646464646666ae68cdc39aab9d500c480008cccccccccccc88888888888848cccccccccccc00403403002c02802402001c01801401000c008cd406c070d5d0a80619a80d80e1aba1500b33501b01d35742a014666aa03eeb94078d5d0a804999aa80fbae501e35742a01066a03604c6ae85401cccd5407c09dd69aba150063232323333573466e1cd55cea801240004664424660020060046464646666ae68cdc39aab9d5002480008cc8848cc00400c008cd40c5d69aba150023032357426ae8940088c98c80d8cd5ce01b81b01a09aab9e5001137540026ae854008c8c8c8cccd5cd19b8735573aa004900011991091980080180119a818bad35742a00460646ae84d5d1280111931901b19ab9c037036034135573ca00226ea8004d5d09aba2500223263203233573806606406026aae7940044dd50009aba1500533501b75c6ae854010ccd5407c08c8004d5d0a801999aa80fbae200135742a004604a6ae84d5d1280111931901719ab9c02f02e02c135744a00226ae8940044d5d1280089aba25001135744a00226ae8940044d5d1280089aba25001135744a00226ae8940044d55cf280089baa00135742a004602a6ae84d5d1280111931901019ab9c02102001e101f13263201f3357389201035054350001f135573ca00226ea80044cd4010888c00cc0080048004c8004d5406488448894cd40044d401800c884ccd4024014c010008ccd54c01c4800401401000448d40048800448d40048800848848cc00400c00848c88c008dd6000990009aa80b111999aab9f0012500a233500930043574200460066ae880080588c8c8cccd5cd19b8735573aa004900011991091980080180118061aba150023005357426ae8940088c98c8058cd5ce00b80b00a09aab9e5001137540024646464646666ae68cdc39aab9d5004480008cccc888848cccc00401401000c008c8c8c8cccd5cd19b8735573aa0049000119910919800801801180a9aba1500233500f014357426ae8940088c98c806ccd5ce00e00d80c89aab9e5001137540026ae854010ccd54021d728039aba150033232323333573466e1d4005200423212223002004357426aae79400c8cccd5cd19b875002480088c84888c004010dd71aba135573ca00846666ae68cdc3a801a400042444006464c6403a66ae7007807406c0680644d55cea80089baa00135742a00466a016eb8d5d09aba2500223263201733573803002e02a26ae8940044d5d1280089aab9e500113754002266aa002eb9d6889119118011bab00132001355013223233335573e0044a010466a00e66442466002006004600c6aae754008c014d55cf280118021aba200301413574200222440042442446600200800624464646666ae68cdc3a800a40004642446004006600a6ae84d55cf280191999ab9a3370ea0049001109100091931900919ab9c01301201000f135573aa00226ea80048c8c8cccd5cd19b875001480188c848888c010014c01cd5d09aab9e500323333573466e1d400920042321222230020053009357426aae7940108cccd5cd19b875003480088c848888c004014c01cd5d09aab9e500523333573466e1d40112000232122223003005375c6ae84d55cf280311931900919ab9c01301201000f00e00d135573aa00226ea80048c8c8cccd5cd19b8735573aa004900011991091980080180118029aba15002375a6ae84d5d1280111931900719ab9c00f00e00c135573ca00226ea80048c8cccd5cd19b8735573aa002900011bae357426aae7940088c98c8030cd5ce00680600509baa001232323232323333573466e1d4005200c21222222200323333573466e1d4009200a21222222200423333573466e1d400d2008233221222222233001009008375c6ae854014dd69aba135744a00a46666ae68cdc3a8022400c4664424444444660040120106eb8d5d0a8039bae357426ae89401c8cccd5cd19b875005480108cc8848888888cc018024020c030d5d0a8049bae357426ae8940248cccd5cd19b875006480088c848888888c01c020c034d5d09aab9e500b23333573466e1d401d2000232122222223005008300e357426aae7940308c98c8054cd5ce00b00a80980900880800780700689aab9d5004135573ca00626aae7940084d55cf280089baa0012323232323333573466e1d400520022333222122333001005004003375a6ae854010dd69aba15003375a6ae84d5d1280191999ab9a3370ea0049000119091180100198041aba135573ca00c464c6401c66ae7003c03803002c4d55cea80189aba25001135573ca00226ea80048c8c8cccd5cd19b875001480088c8488c00400cdd71aba135573ca00646666ae68cdc3a8012400046424460040066eb8d5d09aab9e500423263200b33573801801601201026aae7540044dd500089119191999ab9a3370ea00290021091100091999ab9a3370ea00490011190911180180218031aba135573ca00846666ae68cdc3a801a400042444004464c6401866ae700340300280240204d55cea80089baa0012323333573466e1d40052002200523333573466e1d40092000200523263200833573801201000c00a26aae74dd5000891001091000a4c24002921035054310011232300100122330033002002001335122335500248811c34e6054e3e74ecf4a9b6eb4e34a865f6b0b5fee85e6a9bfba0d2d0250048810341424300112212330010030021120011",
};
useEffect(() => {
const go = async () => {
const koiosProvider = new KoiosProvider(
"https://preview.koios.rest/api/v0/"
);
const utxos = await koiosProvider.fetchAddressUTxOs(
"addr_test1wrv8xdx5kakqnj2whs936fc7fste23epn76em6gqftxl9kqjpx62c"
);
console.log(utxos);
setUtxo(utxos[0]);
const referenceUTxOs = await koiosProvider.fetchAddressUTxOs(
"addr_test1qr0k5uczwvzdt6g6c2e9l92r24f528dfnmu9qq6lssrc3z56l3lczn30u56k4vlf948etel5d63zj20yg6wymu2gp4gsyum3sz"
);
const referenceUTxO = referenceUTxOs.find(
(u) =>
u.input.txHash ===
"45e4b496d192ef91112193e20db8c8d28df414cf4e9f5e6268b4e730b81b0f66"
);
console.log("Reference UTxO", referenceUTxO);
setReferenceUtxo(referenceUTxO);
};
go();
}, []);
const sendTx = async () => {
const refUtxo = referenceUtxo;
const depositUtxo = utxo;
const tx = new Transaction({ initiator: walletData });
tx.setTxRefInputs([refUtxo]);
tx.redeemValue({
value: depositUtxo,
script: simpleScript,
datum: [],
redeemer: { alternative: 0, fields: [] },
});
tx.setCollateral(await walletData.getCollateral());
const myAddress = (await walletData.getUsedAddresses())[0];
console.log("My Address", myAddress);
tx.setRequiredSigners([myAddress]);
tx.setChangeAddress(myAddress);
tx.sendLovelace({ address: myAddress }, "4000000");
const unsignedMeshTx = await tx.build();
console.log(CSL.Transaction.from_hex(unsignedMeshTx).to_js_value());
const signedTx = await walletData.signTx(unsignedMeshTx, true);
const txHash = await walletData.submitTx(signedTx);
console.log("Tx Hash", txHash);
};
return (
<div className="container">
<main className="main">
<h1 className="title">
<a href="https://meshjs.dev/">Mesh</a> Next.js
</h1>
{JSON.stringify(utxo)}
<div className="demo">
<CardanoWallet />
</div>
<button style={{ marginTop: "300px" }} onClick={sendTx}>
Send Tx
</button>
</main>
</div>
);
} This is a link to the desired transaction in preview network that is working: |
I didn't use the desposit utxo as reference input. I used the one you wrote down in the document. The deposit UTxO comes from the script address and I pick the first one. |
I executed the transaction and I consumed the UTxO from the script. Could you put another UTxO like that one again in the script address? |
Ohhh Thanks! I didn't realized that mistake. Yes, I consumed from KuberIDE but I'm curious because the code should replicate the transaction from Kube. I'll try with the new UTxOs. |
Yes i have added 3 utxos with 40 Ada each on the script address. You can consume them using mesh by picking out the first one. But here are the UTxOs for your convenience : |
I've found some misfunction in the Mesh library but I need more time to analyse it. The problem is that somehow the script UTxO is taken as a reference input. I think it's a problem with the distintion of the inline datum but the script utxo musn't be a reference input. |
@reeshavacharya I've created an issue in the Cardano Serialization Library to clarify this issue. @abdelkrimdev @jinglescode This is the issue DatumSource struct makes the script input to be reference input . Depending on the answer, it might be possible that some changes in the |
Actually, it's necessary to change the redeemValue method: @Checkpoint()
redeemValue(options: {
value: UTxO, script: PlutusScript | UTxO,
datum?: Data | UTxO, redeemer?: Action,
}): Transaction {
const redeemer: Action = {
tag: 'SPEND',
budget: DEFAULT_REDEEMER_BUDGET,
index: this._txInputsBuilder.inputs().len(),
data: {
alternative: 0,
fields: [],
},
...options.redeemer,
};
const utxo = toTxUnspentOutput(options.value);
let witness: csl.PlutusWitness;
if (options.datum) {
witness = csl.PlutusWitness.new_with_ref(
buildPlutusScriptSource(options.script),
buildDatumSource(options.datum),
toRedeemer(redeemer),
);
} else {
witness = csl.PlutusWitness.new_with_ref_without_datum(
buildPlutusScriptSource(options.script),
toRedeemer(redeemer),
);
}
this._txInputsBuilder.add_plutus_script_input(
witness, utxo.input(), utxo.output().amount(),
);
return this;
} I make a PR for this issue. I think the documentation should change with this change. UPDATE: PR is ready: #162 @reeshavacharya I got the transaction working but it was with the change of the PR. |
Thank you for investigating the matter and providing a resolution. I encountered an additional challenge when processing a larger transaction. It appears that Mesh does not dynamically compute execution units for redeemers during transaction creation. In another instance involving a multi-signature transaction, the predetermined ex_units proved insufficient, which required a manual calculation of the execution units and the corresponding new script_data_hash. Subsequently, I generated a new transaction body using these calculations, successfully addressing the issue. I believe an automated mechanism for calculating execution units would be a valuable enhancement for Mesh. However, for now, I am happy that the problem is resolved. Thank you once more for your assistance. Best Regards. |
You are welcome and thank you for your kind words. For the evaluation problem, try with the Ogmios provider: https://meshjs.dev/providers/ogmios. Another trick is to set the execution and memory units at a safety high value but this isn't too optimal. Aditionally, you can set the execution units in the redeemer: const reddemer = {
...
budget: {
cpu: 1234,
mem: 1234,
}
} |
Great! Thank you again. |
Hi!,
This is a quite simple addition. I added the method
setTxRefInputs
in order to add reference inputs to the transaction. I tried to implement the tests but I didn't find where to do it. We can use this PR to communicate me further actions.