7 votes
Accepted

Where is the on-chain code actually stored?

As stated by Samuel, the code that a validator runs to check whether a transaction is valid is sent and stored in the transaction body as an input. So all scripts, be they Plutus or Native scripts, ...
  • 1,530
5 votes

Committing a database to the ledger without storing it on the ledger?

You can use Merkle tree's for this! This is an inverted tree like data structure that uses hashes to create a root hash that is uniquely defined by its leafs, the leafs are the nodes in the lowest ...
  • 1,530
4 votes
Accepted

Is function "isPayToScriptOut" unsafe?

Your deductions are partially correct. isPayToScriptOut looks at the credentials of an address (1) and return true if it is a script address, false if it is a public key credential. It thus does not ...
  • 1,530
3 votes
Accepted

Is really any token metadata stored on chain? Or is it the mint TX metadata?

Yes there is NFT metadata stored on-chain and yes they are stored initially on the mint tx although you can update it later (basically overriding it in a new tx). If the NFT metadata follow the CIP25 ...
3 votes

On-chain and Off-chain code

Yes, that's correct. On-chain is exactly what it says. It's logic that happens on every validator syncing the chain. The unique thing with plutus is the on-chain and off-chain code can live together ...
2 votes
Accepted

Is there a way for a validator to get the current time?

The usual way to handle time in Plutus is using Slot ranges. This means that the script does not query the time. Instead it checks that the validation happens in a given slot interval that corresponds ...
  • 83
2 votes
Accepted

Confusion regarding findOwnInput function with on-chain code

Calling findOwnInput in a validator returns the value contained in the Script-UTxO that is currently being validated. In your example above it is the one with 2 Ada in it. Your example above is, ...
  • 1,356
2 votes

How to parse TokenName to Integer

I had trouble with the same thing, just going the opposite direction, Slot -> TokenName (Slot is just an Integer under the hood). After a bunch of pain I ended up just coding my own parsing logic: -...
2 votes

How to get a base 16 hex BuiltinString from getTxId

I was able to resolve this issue by converting (encoding) the BuiltinByteString from getTxId into a hex format. From there I was able to inpsect the hex digits. Below is an onchain encodeHex ...
  • 233
2 votes

Can Queries To the Chain be made From Plutus Smart Contracts?

The way I understood things from last Q&A session with Lars, no, you can't. You can only see the current transaction, not the history of an address.
2 votes
Accepted

How can I configure and send a transaction to the Cardano chain using python

Checkout PyCardano. It is able to serialize python objects to datum and redeemers. Maybe this test example can help: https://github.com/cffls/pycardano/blob/main/integration-test/test/test_all.py#L217 ...
  • 333
1 vote
Accepted

Providing a list of mappings from datum hashes to values while creating a transaction

There are at least two reasons for that field to be a list: A transaction may spend UTxO's from multiple script addresses, The datum value for a transaction output can optionally be provided. Using ...
  • 66
1 vote
Accepted

How to Get the Script Address of A Smart Contract?

There's multiple ways to do it. For example using cardano-addresses or Pycardano library Pycardano: script_cbor_hex = '...' script = cbor2.loads(bytes.fromhex(script_cbor_hex)) script_hash = ...
  • 133
1 vote

How to compare BuiltinByteStrings onchain?

This is how I've done the integer conversion in the past. Might need some minor updating: {-# INLINEABLE intToString #-} intToString :: Integer -> Builtins.String intToString i = Prelude.foldr ...
1 vote
Accepted

How can a validator script be used to mint native tokens, in addition to perform other checks?

You need a separate minting policy to mint the tokens. we want a smart contract (validator script) I tend to think of smart contracts as including a set of validators and policies, not just one ...
1 vote
Accepted

Can UTxO sit at a minting policy (currency symbol), like at a validator script address?

As you said, minting policies is part of a transaction and and is not part of a script address UTxO, so it doesn't make sense saying "UTxO sitting at a minting policy", since the minting ...
  • 833
1 vote
Accepted

How to optimize Plutus smart contracts?

I am building a dApp myself and I am running into similar issues related to hitting the current mainnet's maxTxExUnits upper boundaries of exUnitsMem and exUnitsSteps. In regards to question 4: You ...
1 vote
Accepted

How to know which module to import?

Some of these are reexported versions of others. This means some of them are not necessary. Also PlutusTx.Prelude should be included in all projects as it maps types into PlutusTx which complies with ...
1 vote
Accepted

How do you deploy ready made AI on chain

I have done that as well for Kucoin Binance etc python is great for backend data analisis... Well.. BlockChain are just transactions... you should be able to do a BlockChain a transaction from your ...
1 vote

How do you deploy ready made AI on chain

I am not very knowledgeable when it comes to AI, but I'm pretty sure right now it's impossible to have one on-chain for two reasons. First, it would be too computationally heavy, so the current CPU ...
  • 833
1 vote

How to PreSign a transaction

Scripts on the ledger are passive, they do not act unless a party sends a transaction that propagates the state of the script. If I understand correctly, you want a vesting scheme, this is possible. ...
  • 1,530
1 vote

Does Plutus support floating-point arithmetic for on-chain code?

My opinion would be that: Floating point operations are typically resource-consuming and expensive to compute. I mean, even 1 ADA had to be made a million Lovelace in order for the possibility to have ...
  • 713
1 vote
Accepted

How to validate the correctness of another parameterized script address on-chain

You are asking a couple different questions here. This loads in cabal repl without problems. But when executing the EmulatorTrace, it yields the following error: *** Exception: Error: Unsupported ...
1 vote
Accepted

How to get information about UTxOs which created locking transaction on the on-chain?

In TxOut you have a field txOutAddress that you can use for this: data TxOut = TxOut { txOutAddress :: Address, txOutValue :: Value, txOutDatumHash :: Maybe DatumHash } Use it to extract ...
  • 1,356
1 vote

How does one check a pool's delegation history?

If you do not want to setup cardano-db-sync, try blockfrost.io with the /epochs/{number}/blocks/{pool_id} endpoint.
1 vote
Accepted

How does one check a pool's delegation history?

If you need any kind of specific on chain information that isn't found on third party explorers like Cardanoscan, you'd have to use db-sync yourself. (It's what all the explorers use) To quote ...
  • 3,254
1 vote
Accepted

How does custom Plutus data type map to cardano-cli --tx-in-datum-file content?

Here is an example of a haskell executable that will convert any of your custom data types to the right JSON format : https://github.com/OnChainLabs/Martify/blob/main/app/datum-json.hs In this file we ...
1 vote

Retrieve only digit from TokenName and use onchain

given the request on way would be the following: getIdFromTokenName :: TokenName -> Integer getIdFromTokenName tn = getIdFromStr 0 $ (BS8.unpack . unTokenName) tn -- BS8.unpack :: ByteString -> ...
  • 636
1 vote

Is there a way for a validator to get the current time?

How about parameterizing the validator with Slot or POSIXTime and passing the current time from the contract to the validator script using Contract.currentTime or Contract.currentSlot? That way, the ...
  • 713
1 vote

How to parse TokenName to Integer

This is slow but works. {-# LANGUAGE OverloadedStrings #-} module StackExchange where import Prelude import PlutusTx.Builtins.Class import PlutusTx.Builtins.Internal import Data.ByteString hiding (...
  • 1,527

Only top scored, non community-wiki answers of a minimum length are eligible