Policy Script Smart Contract

Is there any way to tell what type of policy script is being used on a particular policy id? I mean how can I differentiate and determine whether a policy script is a simple/native script or it was made using a smart contract.

In general, no: the policy ID is a hash of the simple or Plutus script and you cannot see if it is the hash of one or the other.

In 99% of cases, yes: Just ask cardanoscan.io. A transaction that mints or burns tokens for that policy has to give the policy script. And an explorer like Cardanoscan can monitor that and add it to the data of the policy ID.

If the policy ID has ever been used for minting, will have a “script” button on Cardanoscan, where you can not only see the type of script, but also the concrete script.

Ok thank you very much for that information. I have another question please if you don’t mind, is it possible to capture a payment on the frontend using a multi sig wallet connect/payment feature and then split that payment in to 2 parts and send them as 2 separate transactions. For example I have a button on my website that a user comes along and clicks on the button, selects the option to mint 2 nfts (which cost 10ada each for example) and then sign, is it possible for me to split that payment of 20ada into 2 payments of 10ada and send them as 2 separate payments instead of the one?

It would probably be better to do it all in one transaction, but outputs to multiple different addresses (different creators of multiple NFTs sold/minted in the same transaction, for example) are no problem at all.

Ok no problem thank you, would you be able to tell me what is wrong with my code that I am getting this error:

Command failed: transaction submit Error: Error while submitting tx: ShelleyTxValidationError ShelleyBasedEraBabbage (ApplyTxError [UtxowFailure (UtxoFailure (BabbageOutputTooSmallUTxO [((Addr Testnet (KeyHashObj (KeyHash "c6c7595b80659bb829fd845880726487a4d3919d4392557798bfb4d1")) (StakeRefBase (KeyHashObj (KeyHash "7416197abeedbb6020aa7017aaff752360393eae8296a504cb2d3cb2"))),Value 0 (fromList [(PolicyID {policyID = ScriptHash "beef386c1d293289bf4261640e08d4a8dd16614d8d167cd2bbb09abf"},fromList [(4661746475636b3230,1),(4661746475636b3231,1)])]),NoDatum,SNothing),Coin 1198180)])),UtxowFailure (UtxoFailure (FromAlonzoUtxoFail (ValueNotConservedUTxO (Value 20000000 (fromList [])) (Value 0 (fromList [(PolicyID {policyID = ScriptHash "beef386c1d293289bf4261640e08d4a8dd16614d8d167cd2bbb09abf"},fromList [(4661746475636b3230,1),(4661746475636b3231,1)])]))))),UtxowFailure (UtxoFailure (FromAlonzoUtxoFail (FeeTooSmallUTxO (Coin 171837) (Coin 0))))])

Here is the code I am using:

const buildRealTxTwo = (data: IMetadataTwo, minimum_lovelace: number): void => {
  const [slot_number, policy_id] = [get_slot_number(), get_policy_id() ];

  const {utxo, txid, sender_address, first_hashed_token_name, second_hashed_token_name, first_metadata_pathname, second_metadata_pathname, batched_tokens} = data;

  const first_metadata = fs.readFileSync(`${__dirname}/../_nft/metadata/${first_metadata_pathname}`, {encoding:'utf8', flag:'r'});
  const second_metadata = fs.readFileSync(`${__dirname}/../_nft/metadata/${second_metadata_pathname}`, {encoding:'utf8', flag:'r'});

  let first_metadata_parsed = JSON.parse(first_metadata);
  const second_metadata_parsed = JSON.parse(second_metadata);

  first_metadata_parsed['721']['beef386c1d293289bf4261640e08d4a8dd16614d8d167cd2bbb09abf'] = {...first_metadata_parsed['721']['beef386c1d293289bf4261640e08d4a8dd16614d8d167cd2bbb09abf'], ...second_metadata_parsed['721']['beef386c1d293289bf4261640e08d4a8dd16614d8d167cd2bbb09abf']}

  fs.writeFileSync(`${__dirname}/../tempMetadata.json`, JSON.stringify(first_metadata_parsed));

  cmd.runSync([
    `${CARDANO_CLI} transaction build`,
    CARDANO_NETWORK_TYPE,
    CARDANO_ERA,
    `--tx-in ${utxo}#${txid}`,
    `--tx-out ${sender_address}+${minimum_lovelace}+"1 ${policy_id}.${first_hashed_token_name}"+"1 ${policy_id}.${second_hashed_token_name}"${batched_tokens}`,
    `--change-address ${SEND_CHANGE_TO_ADDRESS}`,
    `--mint="1 ${policy_id}.${first_hashed_token_name}"+1 ${policy_id}.${second_hashed_token_name}"`,
    `--minting-script-file ${_account}/policy/policy.script`,
    `--metadata-json-file ./_nft/metadata/tempMetadata.json`,
    `--invalid-hereafter ${slot_number}`,
    `--witness-override 2`,
    `--out-file ${_account}/tx/matx.raw`
  ].join(" "));
};

The error messages do not fit the code. Are you sure you submitted the latest built by that code and not some old one?

The error messages say:

There is an output with 0 ADA. Can only happen with your code if you call it with minimum_lovelace set to 0.

The transaction is not balanced. Inputs are 20 ADA and no tokens, outputs are 0 ADA and two tokens. This cannot happen with your code at all. cardano-cli transaction build balances the ADA automatically. And the two --mint arguments would definitely lead to the two tokens being on the input side.

Fee is missing completely. This also cannot happen with your code, since transaction build calculates and adds the fee automatically.

Altogether, it really does not look like the transaction throwing those errors was built from this code.

Also: Calling out from Javascript to cardano-cli is really not what I would recommend! It will always only work on a machine with a running cardano-node and you said previously that you do not plan to run one.

And there are libraries to build transactions completely in Javascript. There’s no need to call out to the shell.

Yes I am definitely using that code but I just realised I didn’t link the tempMetadata.json file corrctly, but after linking it correctly I am still getting the following error

Command failed: transaction submit Error: Error while submitting tx: ShelleyTxValidationError ShelleyBasedEraBabbage (ApplyTxError [UtxowFailure (UtxoFailure (BabbageOutputTooSmallUTxO [((Addr Testnet (KeyHashObj (KeyHash "c6c7595b80659bb829fd845880726487a4d3919d4392557798bfb4d1")) (StakeRefBase (KeyHashObj (KeyHash "7416197abeedbb6020aa7017aaff752360393eae8296a504cb2d3cb2"))),Value 0 (fromList [(PolicyID {policyID = ScriptHash "beef386c1d293289bf4261640e08d4a8dd16614d8d167cd2bbb09abf"},fromList [(4661746475636b3230,1),(4661746475636b3231,1)])]),NoDatum,SNothing),Coin 1198180)])),UtxowFailure (UtxoFailure (FromAlonzoUtxoFail (ValueNotConservedUTxO (Value 20000000 (fromList [])) (Value 0 (fromList [(PolicyID {policyID = ScriptHash "beef386c1d293289bf4261640e08d4a8dd16614d8d167cd2bbb09abf"},fromList [(4661746475636b3230,1),(4661746475636b3231,1)])]))))),UtxowFailure (UtxoFailure (FromAlonzoUtxoFail (FeeTooSmallUTxO (Coin 171837) (Coin 0))))])

Here’s what the raw query looks like without all the variables

cardano-cli transaction build
  --testnet-magic 1,
  --babbage-era,
  --tx-in bcd27f392f09f27c9ab5876feb557497085016c7b2c983c7aca9e0ba156753f5#0,
  --tx-out addr_test1qrrvwk2mspjehwpflkz93qrjvjr6f5u3n4pey4thnzlmf5t5zcvh40hdhdszp2nsz7407afrvqunat5zj6jsfjed8jeqrvtj5n+1173685+"1 beef386c1d293289bf4261640e08d4a8dd16614d8d167cd2bbb09abf.4661746475636b3230"+"1 beef386c1d293289bf4261640e08d4a8dd16614d8d167cd2bbb09abf.4661746475636b3231",
  --change-address addr_test1qzp3swy8at73yh8myqp0jal2p9na7dae30wvv4gq0972auq4gcgwxzupnzp90lych2a3lp2dlv7njyqntuyy07vn6m0q0mr7rm,
  --mint="1 beef386c1d293289bf4261640e08d4a8dd16614d8d167cd2bbb09abf.4661746475636b3230"+1 beef386c1d293289bf4261640e08d4a8dd16614d8d167cd2bbb09abf.4661746475636b3231",
  --minting-script-file ./_account/policy/policy.script,
  --metadata-json-file ./tempMetadata.json,
  --invalid-hereafter 20137745,
  --witness-override 2,
  --out-file ./_account/tx/matx.raw

That is exactly the same error message as before and I already explained all three errors in there.

I am quite sure that you are submitting a different file and not the one you are building with that code.

Right I was advised to move some code around and that the reason that I was getting the error was because I tried to attach my metadata file in the transaction build query instead of the transaction build raw, but I’ve done that but now I am getting this error:

Command failed: transaction submit Error: Error while submitting tx: ShelleyTxValidationError ShelleyBasedEraBabbage (ApplyTxError [UtxowFailure (UtxoFailure (BabbageOutputTooSmallUTxO [((Addr Testnet (KeyHashObj (KeyHash "c6c7595b80659bb829fd845880726487a4d3919d4392557798bfb4d1")) (StakeRefBase (KeyHashObj (KeyHash "7416197abeedbb6020aa7017aaff752360393eae8296a504cb2d3cb2"))),Value 0 (fromList [(PolicyID {policyID = ScriptHash "beef386c1d293289bf4261640e08d4a8dd16614d8d167cd2bbb09abf"},fromList [(4661746475636b3230,1),(4661746475636b3231,1)])]),NoDatum,SNothing),Coin 1198180)])),UtxowFailure (UtxoFailure (FromAlonzoUtxoFail (ValueNotConservedUTxO (Value 20000000 (fromList [])) (Value 0 (fromList [(PolicyID {policyID = ScriptHash "beef386c1d293289bf4261640e08d4a8dd16614d8d167cd2bbb09abf"},fromList [(4661746475636b3230,1),(4661746475636b3231,1)])]))))),UtxowFailure (UtxoFailure (FromAlonzoUtxoFail (FeeTooSmallUTxO (Coin 171837) (Coin 0))))])

You can also attach metadata to build. You don’t have to use build-raw.

And the code you showed me uses build.

Those are still the same three errors you have since 12 hours that were explained in:

And they still cannot happen if you use the transaction build command that you show and sign and submit that and only that.