miguelaeh / cardanocli-js Goto Github PK
View Code? Open in Web Editor NEWWrapping the cardano-cli inside JavaScript
Wrapping the cardano-cli inside JavaScript
Seems like the ewer version of the CLI have different flag names for providing script datum & redeemer and also for providing minting script and redeemer.
For example these are updated arguments in cardano-cli for providing datum and redeemer:
[--tx-in-script-file FILE
[(--tx-in-datum-file FILE | --tx-in-datum-value JSON VALUE)
( --tx-in-redeemer-file FILE
| --tx-in-redeemer-value JSON VALUE
[--tx-in-collateral TX-IN]
--tx-in-script-file FILE The file containing the script to witness the
--tx-in-datum-file FILE The script datum, in the given JSON file. The file
--tx-in-datum-value JSON VALUE
--tx-in-redeemer-file FILE
--tx-in-redeemer-value JSON VALUE
--tx-in-collateral TX-IN TxId#TxIx
In current version of this library we are providing these arguments instead:
--tx-in-script-datum-value
--tx-in-script-redeemer-value
Hello,
Could you publish an up to date version of the NPM on www.npmjs.com?
The version available is really old and does not contain some more recent fixes.
Thanks and keep up the great work!
Is it possible to restore an existing wallet using the seed with any of the methods already in that package?
After launching file I get error:
Missing: --out-file FILE
Usage: cardano-cli transaction build-raw
Code is exact as in example. Wallet have tAda and all other commands works as it should.
I can't understand where is problem.
Hey all,
Currently trying to mint a one-off CNFT using this amazing repo, but seem to run into an issue when attempting the minting process. More specifically, here is the error message I get when running my minting script:
/<MY-PATH>/node_modules/cardanocli-js/helper.js:145
minting.action.forEach((mint, index, arr) => {
^
TypeError: Cannot read property 'forEach' of undefined
at exports.mintToString (/<MY-PATH>/node_modules/cardanocli-js/helper.js:145:18)
at CardanocliJs.transactionBuildRaw (/<MY-PATH>/node_modules/cardanocli-js/index.js:854:39)
at buildTransaction (/<MY-PATH>/src/mint-asset.js:99:25)
at Object.<anonymous> (/<MY-PATH>/src/mint-asset.js:110:13)
See actual minting script below:
const cardano = require("./cardano")
// 1. Get the wallet
const wallet = cardano.wallet("<MY-WALLET-NAME>");
// 2. Define mint script
const mintScript = {
type: "all",
scripts: [
{
slot: 49483967,
type: "before"
},
{
keyHash: cardano.addressKeyHash(wallet.name),
type: "sig"
}
]
}
// 3. Create POLICY_ID
const POLICY_ID = cardano.transactionPolicyid(mintScript)
// 4. Define ASSET_NAME
const ASSET_NAME = "TestCNFT001"
// 5. Create ASSET_ID
const ASSET_ID = POLICY_ID + "." + ASSET_NAME
// 6. Define metadata
const metadata = {
721: {
[POLICY_ID]: {
[ASSET_NAME]: {
name: ASSET_NAME,
image: "ipfs://<IPFS-HASH>",
description: "Test CNFT 001",
type: "image/png",
}
}
}
}
// 7. Define transaction
const tx = {
txIn: wallet.balance().utxo,
txOut: [
{
address: wallet.paymentAddr,
value: { ...wallet.balance().value, [ASSET_ID]: 1 }
}
],
mint: {
actions: [{ type: "mint", quantity: 1, asset: ASSET_ID }],
script: [mintScript]
},
metadata,
witnessCount: 2
}
// 8. Build transaction
const buildTransaction = (tx) => {
const raw = cardano.transactionBuildRaw(tx)
const fee = cardano.transactionCalculateMinFee({
...tx,
txBody: raw
})
tx.txOut[0].value.lovelace -= fee
return cardano.transactionBuildRaw({ ...tx, fee })
}
const raw = buildTransaction(tx)
// 9. Sign transaction
const signTransaction = (wallet, tx) => {
return cardano.transactionSign({
signingKeys: [wallet.payment.skey, wallet.payment.skey],
txBody: tx
})
}
const signed = signTransaction(wallet, raw)
// 10. Submit transaction
const txHash = cardano.transactionSubmit(signed)
console.log(txHash)
Any clues as to why this error is being triggered?
Hi Alessandro,
The exported method tryParseJson()
in helper.js#97
does not return parsed json, but it returns true
if the json was parsed and result is of type object. If this method should only validate the json string, I suggest renaming the method. Otherwise maybe you meant to return result
.
Have a great day :)
I´m getting always the error :
Error: Error while submitting tx: ShelleyTxValidationError ShelleyBasedEraAlonzo (ApplyTxError [UtxowFailure (WrappedShelleyEraFailure (UtxoFailure (ValueNotConservedUTxO (Value 8077275 (fromList [(PolicyID {policyID = ScriptHash
Any idea
Hi! I'm trying to use cardanocli-js to mint a NFT and as I am building the transaction, I get this error:
mikey@mikey:~/cardano-minter$ node src/mint-asset.js
/home/mikey/node_modules/cardanocli-js/helper.js:199
minting.forEach((mint, index, arr) => {
^
TypeError: minting.forEach is not a function
at exports.mintToString (/home/mikey/node_modules/cardanocli-js/helper.js:199:11)
at CardanocliJs.transactionBuildRaw (/home/mikey/node_modules/cardanocli-js/index.js:888:39)
at buildTransaction (/home/mikey/cardano-minter/src/mint-asset.js:66:25)
at Object.<anonymous> (/home/mikey/cardano-minter/src/mint-asset.js:77:13)
at Module._compile (internal/modules/cjs/loader.js:999:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1027:10)
at Module.load (internal/modules/cjs/loader.js:863:32)
at Function.Module._load (internal/modules/cjs/loader.js:708:14)
at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:60:12)
at internal/main/run_main_module.js:17:47
I've tried doing a full reinstall of cardanocli-js, but this problem still occurs.
Hey everyone,
An error is caused when trying to submit a transaction using the code in the examples directory.
Version: [email protected]
The error message:
option --tx-out:
unexpected "N"
expecting white space or multi-asset value expression
After debugging I found out the the balance and keyDeposit aree both undefined at the following code:
const registerWallet = (wallet) => {
let account = wallet.name;
let keyDeposit = cardanocliJs.queryProtocolParameters().keyDeposit;
let stakeCert = cardanocliJs.stakeAddressRegistrationCertificate(account);
let paymentAddress = cardanocliJs.wallet(account).paymentAddr;
let balance = cardanocliJs.wallet(account).balance().value.lovelace;
and if you look at the tx there is a value which should be appended to the payment address:
let tx = {
txIn: cardanocliJs.queryUtxo(paymentAddress),
txOut: [
{ address: paymentAddress, value: { lovelace: balance - keyDeposit } },
],
certs: [{ cert: stakeCert }],
witnessCount: 2,
};
in JS:
undefined - undefined = NaN
at the end the --tx-out is something like this:
--tx-out "addr_test1qz0vzjnra5rq702lv0x4cr8y9f56gcy07yufwfq8gekuaw24k7uzykt655k2gx5438q54xm5yunwsvaevrk9k80uasuqcxwlmv+NaN"
see at NaN appended at the end.
After I fix this and put 0 as a value instead. I get another error :
Missing: (--tx-in TX-IN)
Did I miss something? is this expected ?
I used the following code:
const createWallet = (account) => {
const payment = cardanocliJs.addressKeyGen(account);
const stake = cardanocliJs.stakeAddressKeyGen(account);
cardanocliJs.stakeAddressBuild(account);
cardanocliJs.addressBuild(account, {
paymentVkey: payment.vkey,
stakeVkey: stake.vkey,
});
return cardanocliJs.wallet(account);
};
const registerWallet = (wallet) => {
let account = wallet.name;
let keyDeposit = cardanocliJs.queryProtocolParameters().keyDeposit;
let stakeCert = cardanocliJs.stakeAddressRegistrationCertificate(account);
let paymentAddress = cardanocliJs.wallet(account).paymentAddr;
let balance = cardanocliJs.wallet(account).balance().value.lovelace;
console.log("balance");
console.log(balance);
console.log("keyDeposit");
console.log(keyDeposit);
let tx = {
txIn: cardanocliJs.queryUtxo(paymentAddress),
txOut: [
{ address: paymentAddress, value: { lovelace: balance - keyDeposit } },
],
certs: [{ cert: stakeCert }],
witnessCount: 2,
};
let txBodyRaw = cardanocliJs.transactionBuildRaw(tx);
let fee = cardanocliJs.transactionCalculateMinFee({
...tx,
txBody: txBodyRaw,
});
tx.txOut[0].value.lovelace -= fee;
let txBody = cardanocliJs.transactionBuildRaw({ ...tx, fee });
let txSigned = cardanocliJs.transactionSign({
txBody,
signingKeys: [
cardanocliJs.wallet(account).payment.skey,
cardanocliJs.wallet(account).stake.skey,
],
});
return txSigned;
};
Forgot to add:
cardano-node 1.30.1 - darwin-x86_64 - ghc-8.10
cardano-cli 1.30.1 - darwin-x86_64 - ghc-8.10
Hi, I am using your package for minting, transfer. But i want to make connect of local cardano-cli with my remote cardano-node which is hosted on aws server or in some docker container.
To make this 'fully compatible with cntools', don't name the wallet files with the wallet name inside the /priv/wallet/ directory.
Example: WalletName = testwallet
Folder Structure:
./priv/wallet/testwallet
File Names:
testwallet.payment.addr
testwallet.payment.skey
testwallet.payment.vkey
Those filenames break CNTools so it lists the wallet as selectable, but it doesn't recognize the extra 'walletname.' part of the file.
So you have to rename all 6 files to allow it to function from within CNTools.
That way, you could just copy the wallet folder to an offline node, make the transactions and load them into the node to submit online without need for the signing keys being there. But as it is, CNTools won't recognize the wallets without renaming.
Now that the multiAssetToString
function is changed and actually needs the options
not the value
anymore, then this function should take an options
as param and remove the address from tx-out
The NPM package is missing code. The one example I've found so far is from queryUtxo method but there may be others...
Github:
if (v.includes("TxOutDatumHash") || v.includes("TxOutDatumNone") ) {
NPM:
if (v.includes("TxOutDatumHash")) ) {
Hi, I'm new to Cardano and trying to mint NFTs with it.
While building a transaction, I've got an error.
option --tx-out:
unexpected "u"
expecting white space or multi-asset value expression
After debugging, I found out the syntax of txOutToString
is different from syntax breakdown.
Here is the code of txOutToString
.
exports.txOutToString = (txOutList) => {
let result = "";
txOutList.forEach((txOut) => {
result += `--tx-out "${txOut.address}+${txOut.value.lovelace}`;
Object.keys(txOut.value).forEach((asset) => {
if (asset == "lovelace") return;
result += `+${txOut.value[asset]} ${asset}`;
});
result += `" `;
txOut.datumHash && (result += `--tx-out-datum-hash ${txOut.datumHash}`);
});
return result;
};
As far as I know, the quote mark("
) after --tx-out
should be placed before txOut.value[asset]
. Am I wrong?
Is it possible to send transactions and tokens.
Hi, I am trying to send transaction according to your method via API using Express Js. When i hit for the first time it works. But when i try to hit second time it gives me error of submitting transaction. can you tell how to solve this?
the error is given blow:
Command failed: transaction submit Error: Error while submitting tx: ShelleyTxValidationError ShelleyBasedEraAlonzo (ApplyTxError [UtxowFailure (WrappedShelleyEraFailure (UtxoFailure (ValueNotConservedUTxO (Value 579123393 (fromList [(PolicyID {policyID = ScriptHash "2e7a318a35f3ddb6c53b03f497e8de645571a73df1ebb328463391ef"},fromList [("IpTesting12",1)]),(PolicyID {policyID = ScriptHash "b6c9a8fd9733340ca61b41a083ec87e94f8920cbc679399037dced89"},fromList [("68693231",1),("68693334",1)])])) (Value 580623393 (fromList [(PolicyID {policyID = ScriptHash "2e7a318a35f3ddb6c53b03f497e8de645571a73df1ebb328463391ef"},fromList [("IpTesting12",1)]),(PolicyID {policyID = ScriptHash "b6c9a8fd9733340ca61b41a083ec87e94f8920cbc679399037dced89"},fromList [("68693231",1),("68693334",1)])])))))])
hey i was playing around with cardanocli-js those days, my node is set up so far and PATH etc is set correct. But when i try to run the simple tx script i get following error from my node (v1.33)
"Error: Command failed: cardano-cli transaction build-raw --alonzo-era --tx-in d904c40f4a5f6a6d801ea2077c4680fceec381b849fb205eada7d1e0d7bf369e#0 --tx-out addr_test1qp428wwkdzancas6j84dqkharhaleyx6a5hka963xxn3d0v2wenx7y0uxg654uvzpdhscdmgks65r4jslakwhz9s0f2s0d9xcu+995000000--tx-out addr_test1qq9w5ptzv8kf7lj4y2t4vvkaaqcvvza07ffrvnt86syyxtmu52dyztltrs8gc9n9qzl8ylrsysnfj0znmvwt8n6cxe4swq8luq+5000000 --metadata-json-file /home/martin/testnet/tmp/metadata_82qj15rk4.json --invalid-hereafter 59019239 --invalid-before 0 --fee 0 --out-file /home/martin/testnet/tmp/tx_ugqt0q9jv.raw --protocol-params-file /home/martin/testnet/tmp/protocolParams.json
option --tx-out:
unexpected '-'
expecting digit, asset id, white space, operator or end of input"
to me it seems like there should be a space between the first and the second --tx-out parameter. What am i doing wrong and how can i fix this?
thx
Hi guys,
Is the library still working with node 1.29.0 ?
I saw a couple of addition in cardano-cli and was wondering if the lib is still working (even if it does not include the upgrade)
Thanks
cardanocliJs.addressBuild(account); does not work.
Simple example: https://developers.cardano.org/docs/get-started/cardanocli-js/ on this page does not work ...what to talk of others... Frustrating ...
Hello,
I'm trying to build a function that sends assets to multiple receivers I'm giving this to transactionBuildRaw
function:
{
txIn: [
{
txHash: '3fe862bba31dd0cc58086ac538e7ea419ac5825cbef0c0285b4a02117aa6fcd4',
txId: 0,
value: {
lovelace: 897243237,
'MyPolicyID.ASDOG10': 1,
'MyPolicyID.ASDOG11': 1,
'MyPolicyID.ASDOG12': 1,
'MyPolicyID.ASDOG13': 1,
'MyPolicyID.ASDOG14': 1,
'MyPolicyID.ASDOG15': 1,
'MyPolicyID.ASDOG16': 1,
'MyPolicyID.ASDOG17': 1,
'MyPolicyID.ASDOG18': 1,
'MyPolicyID.ASDOG19': 1,
'MyPolicyID.ASDOG4': 1,
'MyPolicyID.ASDOG5': 1,
'MyPolicyID.ASDOG6': 1,
'MyPolicyID.ASDOG7': 1,
'MyPolicyID.ASDOG8': 1,
'MyPolicyID.ASDOG9': 1
}
}
],
txOut: [
{
address: 'addr_test1qzkazr6',
value: {
lovelace: 895243237,
'MyPolicyID.ASDOG10': 1,
'MyPolicyID.ASDOG11': 1,
'MyPolicyID.ASDOG12': 1,
'MyPolicyID.ASDOG13': 1,
'MyPolicyID.ASDOG14': 1,
'MyPolicyID.ASDOG15': 1,
'MyPolicyID.ASDOG16': 1,
'MyPolicyID.ASDOG17': 1,
'MyPolicyID.ASDOG18': 1,
'MyPolicyID.ASDOG19': 1,
'MyPolicyID.ASDOG6': 1,
'MyPolicyID.ASDOG7': 1,
'MyPolicyID.ASDOG8': 1,
'MyPolicyID.ASDOG9': 1
}
},
{
address: 'addr_test1qrjyget',
value: {
'MyPolicyID.ASDOG4': 1,
lovelace: 2000000
}
},
{
address: 'addr_test1qzrygzy',
value: {
'MyPolicyID.ASDOG5': 1
}
}
]
}
But I'm getting this error:
Error: Command failed: cardano-cli transaction build-raw --tx-in 3fe862bba31dd0cc58086ac538e7ea419ac5825cbef0c0285b4a02117aa6fcd4#0 --tx-out "addr_test1qzkazr6+895243237+1 MyPolicyID.ASDOG10+1 MyPolicyID.ASDOG11+1 MyPolicyID.ASDOG12+1 MyPolicyID.ASDOG13+1 MyPolicyID.ASDOG14+1 MyPolicyID.ASDOG15+1 MyPolicyID.ASDOG16+1 MyPolicyID.ASDOG17+1 MyPolicyID.ASDOG18+1 MyPolicyID.ASDOG19+1 MyPolicyID.ASDOG6+1 MyPolicyID.ASDOG7+1 MyPolicyID.ASDOG8+1 MyPolicyID.ASDOG9" --tx-out "addr_test1qrjyget+2000000+1 MyPolicyID.ASDOG4" --tx-out "addr_test1qzrygzy+undefined+1 MyPolicyID.ASDOG5" --invalid-hereafter 36105473 --invalid-before 0 --fee 0 --out-file /home/asghostki/projects/cardano-minter/tmp/tx_1gln2zpyc.raw option --tx-out: unexpected "u" expecting white space or multi-asset value expression
I redacted the PolicyId and addresses for convenience.
My Policy Script is this that it will be locked after 1 year.
const mintScript = {
type: "all",
scripts: [
{
type: "before",
slot: 71547800 + 31104000,
},
{
type: "sig",
keyHash: "keyHash",
}
],
};
It gives this error when i try to mint:
Error: Error while submitting tx: ShelleyTxValidationError ShelleyBasedEraAlonzo (ApplyTxError [UtxowFailure (WrappedShelleyEraFailure (ScriptWitnessNotValidatingUTXOW (fromList [ScriptHash "1c3b364275705dec7394647f3b046fc8bf36fe43fa8655a116ad71f8"]))),UtxowFailure (WrappedShelleyEraFailure (UtxoFailure (OutsideValidityIntervalUTxO (ValidityInterval {invalidBefore = SJust (SlotNo 71554239), invalidHereafter = SJust (SlotNo 71558911)}) (SlotNo 71548912))))])
hi im trying to mint a nft with this script but cant get to work , i belive is those files index.js and helper .js any one can help?
thanks
option --tx-out:
unexpected "u"
expecting white space or multi-asset value expression
Build a transaction (low-level, inconvenient)
Please note the order of some cmd options is crucial. If used incorrectly may produce undesired tx body. See nested [] notation above for details.
child_process.js:866
throw err;
^
Error: Command failed: cardano-cli transaction build-raw --alonzo-era --tx-in
protocolParams.json
option --tx-out:
unexpected "u"
expecting white space or multi-asset value expression
at checkExecSyncError (child_process.js:790:11)
at execSync (child_process.js:863:15)
at CardanocliJs.transactionBuildRaw (/home/Downloads/nft-mint3/node_modules/cardanocli-js/index.js:904:5)
at buildTransaction (/home/Downloads/nft-mint3/scr/mint-multiple-assets2.js:61:25)
at Object.<anonymous> (/home/Downloads/nft-mint3/scr/mint-multiple-assets2.js:72:13)
at Module._compile (internal/modules/cjs/loader.js:1085:14)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1114:10)
at Module.load (internal/modules/cjs/loader.js:950:32)
at Function.Module._load (internal/modules/cjs/loader.js:790:12)
at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:75:12) {
Hey,
I dont get this started.
I'am running my cardano-node on ubuntu.
with npm run test I get the error "execSync is not a function".
if I remove the typeof window !== "undefined" || stuff before require the script, it start to run but with the new error "throw new Error("httpProvider required")"
I think I do it the wrong way, would be great to get more infos about how I can start with this wrapper.
As there are no binaries in releases, just wonder how to install.
Is docker the only available mode of installation?
Versions ^4.0.0 as downloaded from NPM contain incomplete source code. The queryUtxo
method for example is missing the additional check v.includes("TxOutDatumNone")
during the valueList.forEach
loop resulting in undefined: NAN
being added to the values object.
Republishing the package with the complete source code under a new version (4.0.2) would fix this.
The scripts currently don't work under windows.
Commands like typeof window !== "undefined" || execSync(`mkdir -p ${this.dir}/tmp`);
fail. It would be a nice feature if all platforms would be supported.
Currently it works under WSL but making a debugger work is still more complicated than it could.
I am attempting to Mint a block 0f 12 NFTs. I used the Example mint script as a guide.
const txHash = cardanocliJs.transactionSubmit(signed); Generates this error:
Command failed: transaction submit Error: Error while submitting tx: ShelleyTxValidationError ShelleyBasedEraAlonzo (ApplyTxError [UtxowFailure (WrappedShelleyEraFailure (ScriptWitnessNotValidatingUTXOW (fromList [ScriptHash "0e2240f38eebac8e4139fb959bb882f42112b8cf1446deba79710367"])))])
This may be a bug in cardano-cli. There's an open issue on the cardano Stack Exchange with no responses as of this posting.
https://cardano.stackexchange.com/questions/7322/cardano-cli-submit-error-scriptwitnessnotvalidatingutxow
hello, I am getting the following error when trying to mint an nft on the alonzo testnet
Error: Command failed: cardano-cli transaction submit --testnet-magic 1097911063 --tx-file /home/devperson/cardano/minter/tmp/tx_6fm1ra6a9.signed Command failed: transaction submit Error: Error while submitting tx: ShelleyTxValidationError ShelleyBasedEraAlonzo (ApplyTxError [UtxowFailure (WrappedShelleyEraFailure (UtxoFailure (ValueNotConservedUTxO (Value 989638638 (fromList [])) (Value 989638638 (fromList [(PolicyID {policyID = ScriptHash "01c1e8eafb77ecb39d6e941a413de4a94537ecffe8fa90e494d0821b"},fromList [("TestAsset",1)])])))))])
Unless i have mistook the error, It looks from above that when the transaction is submitted the script has not removed the fee (Value 989638638 is equal to the opening balance on the wallet).
But when I log out transactionBuildRaw it appears to be correct:
does anyone know whether this error can be corrected? I have following the mint example in the repo.
Hello,
Apparently, this library needs an update for the Alonzo update, getting the balance input an undefined: NaN
on the output:
here is the output of cardano-cli shelley query utxo:
I think that it's "TxOutDatumHashNone" that's resulting into the undefined: NaN
This does break also building transaction and so on
The transaction has broken because of the actualization made on the 'value' on the transaction in 1.31.0:
As said in the log:
"Update min utxo calculation cli command #3181
calculate-min-req-utxo requires a transaction output ( TxOut era ) instead of a Value in order to calculate the min required UTxO in the Alonzo era. This is required in the Alonzo era, and the change is made everywhere for consistency."
I will try to fixe it, but i'm a real noob so maybe i could not or take too much time.
thank you
Hi,
To send just-minted NFTs to other wallet, it's essential to check if the submitted transaction for minting the tokens is verified.
Is there any way to find it?
Hi,
has anyone had success with connecting to a remote node using the httpProvider settings?
I've tried node version 1.30.1 and 1.29.0 - both fail to connect via httpProvider. Tried looking into the official node docker itself, it seems like the cardano-node is returning empty server responses. Has this feature been deprecated or is there something else I'm doing wrong?
Thanks for any suggestions!
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.