text:
DBSync: Querying ma_tx_out
I queried ma_tx_out and used the fingerprint of an asset to get its ident so I could get the tx_out_id to get the most recent tx_out for a given asset - but that asset is only in that tx_out because the UTXO has that asset in it, and was used as a part of a transaction that has nothing to do with that asset itself being transferred to another wallet, or contract etc.
How can I filter starting from ma_tx_out  so I am only looking at the latest tx that involves THAT asset directly rather than indirectly?
Scenario A: Asset X is sent from Wallet Z to another wallet
(this is one I want to retain as the tx involves Asset X directly)
Scenario B: Wallet Z transfers some ADA to another wallet, and Asset X is found in one of the UTXO's involved in the transaction.
(this one I don't want to retain, as Asset X is only involved in the tx indirectly)

Do you mean that in latest tx_out that you currently find for an asset, it didn't actually change hands but was transferred back to the same address as it came from?

Correct. It is on the same address in the outputs as it is on the inputs. I have resolved my "issue" by examining both inputs & outputs.

It you join the tx (and the ma_tx_out table should reference tx) table with the block table then block.block_no increases by 1 each block. The you just need to filter by all block.block_no bigger than the one you want.

In this one for example:
https://cardanoscan.io/transaction/38e7ca5d1419bd8ce5e10b1723a223f6ab8fe3b4f4738d23988f26daa5d8c705?tab=utxo
How can we tell that the "Summary" of this tx is a simple transfer of ADA, and that even though there are other assets on the UTXO's involved, those assets themselves have nothing to do with the actual tx being performed, except indirectly?
The "Summary" on this one is "91 ADA moved from here to there" - but the assets on the UTXO's involved appear to be a part of the tx when I query from the perspective of ma_tx_out

The ADA transfer and the other asset transfers are all part of the same transaction. I would not call that an "indirect" association. ADA tx_out values can be associated with multi asset tx out entries because they the ma_tx_out table will have a tx_out_id field that points back to the tx_out table.

Agreed. However, look at this one, the summary shows it is a simple transfer of 91 ADA:
https://cardanoscan.io/transaction/38e7ca5d1419bd8ce5e10b1723a223f6ab8fe3b4f4738d23988f26daa5d8c705?tab=summary
"Summary" shows a transfer of 91 ADA. "UTXOs" has one which has several assets on it and 2 ADA.
When I query ma_tx_out for latest using the fingerprint of any of those assets, I get that tx, even though the tx is about a transfer of 91 ADA as opposed to having anything to do with the transfer of any of those assets on that utxo. In my case, I'd like to ignore that tx, but not sure how.

Put another way, for this one:
https://cardanoscan.io/transaction/38e7ca5d1419bd8ce5e10b1723a223f6ab8fe3b4f4738d23988f26daa5d8c705?tab=summary
How does Cardanoscan know to have the transfer of the 91 ADA in the "Summary" tab? How does it determine from the tx that a transfer of 91 ADA is all that tx effectively did?

I don't know how cardanoscan does it, but if I was asked to replicate it, I would a build a query that for a transaction queries both the tx_out table and the ma_tx_out table. For a tx that only transfers ADA, the returned ma_tx_out output would be empty.


text:
How to query latest transaction for a policy where an asset of that policy changed address/ownership
How can I return the latest transaction where any asset of a given policy changed address/ownership?
Here is a query which returns me the most recent transaction which included an asset of a given policy in it's utxo's:
select encode(tx.hash::bytea, 'hex') as hash
from ma_tx_out as matxo
join multi_asset as ma on matxo.ident = ma.id
join tx_out as txo on matxo.tx_out_id = txo.id
join tx as tx on txo.tx_id = tx.id
left join tx_in on tx_in.tx_out_id = txo.tx_id and tx_in.tx_out_index = txo.index
where tx_in.id is null and ma.policy = '\x{policy_id}'
order by txo.id desc limit 1;

What I would like is similar but also very much not the same, and every way I try to do it turns into a VERY long running query, so I am reaching out here for help.
I want only transactions where any asset of the given policy changed address - i.e. changed ownership, moved to another wallet, was sent to a script address, etc.
So I am trying by differentiating on address of asset in an input utxo being on a different address in an output utxo but I think I may be misunderstanding how things are represented in the schema.

Here is a query that will detect whether a spacebudz nft has changed ownership. It uses a stake address if one exists and otherwise uses the address.
It runs in ~2 min for me when the time is set to 10 days ago.
with
tx_id_limit as (
  select tx.id as tx_id
  from block
    join tx on tx.block_id = block.id
  where time > '2024-03-10 00:00:00+00'
  order by tx_id asc
  limit 1
)

, stxo as (
  select  stxo.tx_out_id
     ,    stxo.tx_in_id
     ,    case
            when stake_address.view is not null then stake_address.view
            else stxo.address
          end as address
     ,    stxo.fingerprint
  from (
    select  tx_out.tx_id as tx_out_id
        ,   tx_in.tx_in_id as tx_in_id
        ,   tx_out.address
        ,   tx_out.stake_address_id
        ,   multi_asset.fingerprint
    from tx_out
    join tx_in on tx_in.tx_out_id = tx_out.tx_id and tx_in.tx_out_index = tx_out.index
    join ma_tx_out on ma_tx_out.tx_out_id = tx_out.id
    join multi_asset on multi_asset.id = ma_tx_out.ident
    where tx_out.tx_id > (select tx_id from tx_id_limit)
      and multi_asset.policy = '\x4523c5e21d409b81c95b45b0aea275b8ea1406e6cafea5583b9f8a5f'
      and tx_in.id is not null
  ) as stxo
  left join stake_address on stake_address.id = stake_address_id
)

select  stxo_1.fingerprint
    ,   stxo_1.address as from_address
    ,   stxo_2.address as to_address
    ,   encode(tx.hash, 'hex') as tx_hash
from stxo as stxo_1
join stxo as stxo_2 on stxo_2.tx_out_id = stxo_1.tx_in_id
join tx on tx.id = stxo_1.tx_in_id
where stxo_1.fingerprint = stxo_2.fingerprint
  and stxo_1.address <> stxo_2.address

This will probably not work as intended for fungible assets. For that you have to treat the input and output addresses as sets (since there can be multiple addresses for a single asset) and then check that the input set and output set are different.

Very cool - I am going to try it out now! Thank you.
First question: I keep the last tx.id processed, and use that as my constraint, but you have used time. Is there a specific reason you chose to use time from the block table?

Nah I just use time so I have a better sense of how far back in the chain I'm going. tx_id would be more efficient here but is less ergonomic imo

This is a non-trivial task. You can't quickly fetch the latest tx that meets this criteria. Postgres will first need to compute whether the criteria has been met across all txs for that asset. Then it will order them and return the latest one.
You have a few options:

You can improve performance by selecting a timeframe (subset of latest txs). You then have to balance the risk returning of no results with the speed of the query ie the longer the timeframe the slower the query.
You can write a postgres function that will iterate a day at time in reverse order until it finds a matching tx. This may still be quite slow especially if you are trying to load results for a web page.
You can create a materialized view that maps assets to txs if they meet this criteria ie a table with columns asset_id, tx_id, time. This is probably your only option if you are doing this for a user-facing app. You then backfill the table with your relevant data and need a way to update the table with the new data coming in.

Agreed, and in fact I do have a tx id I use for limiting the scope in time:
and tx_id > {X}
this does reduce the amount of work required, agreed!
The thing I need help with most though is what is it in the schema/data that would definitively identify a given transaction as one where any asset of the given policy has changed ownership.

Thanks btw @adjuric.
For your #1:
I do constrain by time, typically only querying for records of the last hour, constrained by using: and tx.id > X
It is not for a web UI per-se, it is for extracting the transactions I am interested in, and then storing/updating data in a separate DB.
The part I need help on is determining for certain how to identify that a tx is one where an asset of the given policy changed ownership.
There is the asset being on an input UTXO on one address, and then on another as an output ...

source: Stack Exchange

license: Creative Commons - Attribution Share-Alike - https://creativecommons.org/licenses/by-sa/4.0/

sort: votes


text:
How to identify that a tx is one where an asset of a given policy changed ownership
By querying db-sync using postgresql queries, how can I identify that a tx is one where an asset of the given policy changed ownership?
Is checking if any asset of the policy is on one address as an input utxo, but on a different address as an output utxo a valid way? If so, is it the only way?

all_licenses: Creative Commons - Attribution Share-Alike - https://creativecommons.org/licenses/by-sa/4.0/


text:
How to query for active pool stake for an epoch from cardano-db-sync
I’m attempting to get the active stake value from cardano-db-sync for a pool at a specific epoch so I know how much stake it had for the next snapshot.
I’m currently using the following query
SELECT SUM(amount) FROM epoch_stake

WHERE epoch_stake.epoch_no = $1 AND pool_id = $2

This query seems to work, but my result is quite a bit off when compared to what cardanoscan.io shows as the active stake for the same pool.

Active stake is an instantaneous stake distribution at the current block (and can change with each new block) whereas the epoch_stake table gives the stake distribution for a single epoch.


text:
Starting to learn development on Cardano blockchain platform
I am Wim.
I want to develop dapps on the Cardano blockchain platform.
I have a little bit of programming experience in Java.
So i think i will start from scratch to learn Cardano and the development in its platform.
What is the best place to start to learn the whole chain (Cardano ecosystem to development of dapps with Cardano?
Is there an IDE for installing on a Windows PC that have all the features and the Haskall platform  to start learning?
So where do i start the learning path?
Thanks

Does this help you? https://cardano.stackexchange.com/a/4446/1231

In terms of IDE I think VS Code is used a lot https://code.visualstudio.com For example in the Starter Project see https://github.com/input-output-hk/plutus-starter You will soon learn that Haskell and pure functional programming is the approach with Cardano and Plutus so I recommend that you spend some time every day on Haskell.
Here is intro to Haskell for Plutus and again Visual Studio code is used.
https://www.youtube.com/watch?v=5b-YG558ft8
the developer portal also recommends http://learnyouahaskell.com

Start with the Cardano Developer Portal
It has enough hyperlinks to keep you occupied for a while :)


text:
The baseaddress I get based on the mnemonic doesn't have the utxo I want (cardano-client-lib)
I am currently learning about wallet sending and now I have a question.
One mnemonic corresponds to many addresses, and one address has many utxo
wallet: address1(baseaddr), address2(asset1)
What I restore by mnemonic is address1, but I want to send asset1
https://github.com/bloxbean/cardano-client-lib/issues/106

The address is an encoding of a hash of a public key. Different address means different public key, means different private key. A transaction such as Transaction 9f56ebbf115dc4a5d0370117b164800a74033b9e84b4fd0cefdd65cdbf5e7582 - Cardanoscan, which takes inputs from different addresses has to be signed by multiple private keys for all of the input addresses.
Wallet apps do that automatically. They can derive the private keys by the process described, e.g., in Address Derivation – Cardano Wallet.
It doesn’t matter if the addresses are staked or not (“enterprise”) for this.
If that can be done with this (quite strange) Java API, I don’t know. It seems their transaction builder assumes that there is only one “sender” for each transaction.
In that issue, you mention that the proposed solution with selecting another index in the Account constructor did not work.
Did you choose the index for the address, where the asset resides? It’s the last component of the m/1852’/… derivation path shown to you by Eternl.
According to this, I solve it.
DerivationPath build = DerivationPath.builder()
.purpose(new Segment(1852, true))
.coinType(new Segment(1815, true))
.account(new Segment(0, true))
.role(new Segment(1, false))
.index(new Segment(2, false))
.build();
Not only need to modify (index), but also need to modify (role)
address: m/1852’/1815’/0’/1/2


text:
DAO Smart Contract on Cardano
Are there any resources available specific to creating a DAO on Cardano? I am interested in seeing any examples of DAOs on Cardano or technical articles on this topic. Thanks

There is an interesting proposal in Fund 8 that you may find useful.
https://cardano.ideascale.com/c/idea/397172/comments
or here on Ada Pulse https://adapulse.io/agora-a-plutus-governance-module/


text:
start-cluster - Command failed: genesis create - */genesis.alonzo.spec.json: openBinaryFile: does not exist (No such file or directory)
After cloning latest cardano-node and running nix-shell successfully I get an error running start-cluster and different error if I run with sudo:
Do I need to download the latest genesis jason file? or set WORKBENCH_BACKEND?

[nix-shell:~/plutus/cardano-node]$ start-cluster
workbench:  cabal-inside-nix-shell mode enabled, calling cardano-* via cabal run (instead of using Nix store)
 10 days ago 65422ff37 HEAD -> master, origin/nightly, origin/master, origin/HEAD Merge #3816
workbench:  prebuilding executables (because of useCabalRun)
workbench:    prebuilding cardano-node
/nix/store/m2ckif2l1xf3x9y91wgczlah2snvbicw-cabal-install-exe-cabal-3.6.2.0/bin/cabal --project-file=/Users/deano/plutus/cardano-node/.nix-shell-cabal.project -v0 build -- exe:cardano-node
workbench:    prebuilding cardano-cli
/nix/store/m2ckif2l1xf3x9y91wgczlah2snvbicw-cabal-install-exe-cabal-3.6.2.0/bin/cabal --project-file=/Users/deano/plutus/cardano-node/.nix-shell-cabal.project -v0 build -- exe:cardano-cli
workbench:    prebuilding cardano-topology
/nix/store/m2ckif2l1xf3x9y91wgczlah2snvbicw-cabal-install-exe-cabal-3.6.2.0/bin/cabal --project-file=/Users/deano/plutus/cardano-node/.nix-shell-cabal.project -v0 build -- exe:cardano-topology

workbench:  run | allocate | profile:  pre-supplied
workbench:  run | allocate | topology:  computed
/nix/store/m2ckif2l1xf3x9y91wgczlah2snvbicw-cabal-install-exe-cabal-3.6.2.0/bin/cabal --project-file=/Users/deano/plutus/cardano-node/.nix-shell-cabal.project -v0 run exe:cardano-topology -- --topology-output /Users/deano/plutus/cardano-node/run/2022-05-02-17.18.plain.default-alzo/topology/topology-nixops.json --dot-output /Users/deano/plutus/cardano-node/run/2022-05-02-17.18.plain.default-alzo/topology/topology.dot uni-circle --size 6 --loc LO
workbench:  run | allocate | genesis:  computed
realpath: /Users/deano/.cache/cardano-workbench/genesis/k6-d1-0.006kD-0kU-e74709a: No such file or directory
workbench:  genesis:  cache entry at /Users/deano/.cache/cardano-workbench/genesis/k6-d1-0.006kD-0kU-e74709a is incompatible:  layout version 'unknown' does not match current: March-14-2022
workbench:  genesis: preparing cache entry k6-d1-0.006kD-0kU-e74709a:  miss (/Users/deano/.cache/cardano-workbench/genesis/k6-d1-0.006kD-0kU-e74709a)
workbench:  genesis: generating due to cache-miss:  k6-d1-0.006kD-0kU-e74709a @/Users/deano/.cache/cardano-workbench/genesis/k6-d1-0.006kD-0kU-e74709a
/nix/store/m2ckif2l1xf3x9y91wgczlah2snvbicw-cabal-install-exe-cabal-3.6.2.0/bin/cabal --project-file=/Users/deano/plutus/cardano-node/.nix-shell-cabal.project -v0 run exe:cardano-cli -- genesis create --genesis-dir /Users/deano/.cache/cardano-workbench/genesis/k6-d1-0.006kD-0kU-e74709a/ --supply 6010000000000000 --testnet-magic 42 --gen-genesis-keys 0 --gen-utxo-keys 1
Command failed: genesis create  Error: /Users/deano/.cache/cardano-workbench/genesis/k6-d1-0.006kD-0kU-e74709a/genesis.alonzo.spec.json: /Users/deano/.cache/cardano-workbench/genesis/k6-d1-0.006kD-0kU-e74709a/genesis.alonzo.spec.json: openBinaryFile: does not exist (No such file or directory)

[nix-shell:~/plutus/cardano-node]$ sudo start-cluster
Password:
/nix/store/c6jc5fbkvr45p6wpdj5k7d3ldim1lymw-workbench-0.1/bin/backend.sh: line 58: WORKBENCH_BACKEND: unbound variable
/nix/store/c6jc5fbkvr45p6wpdj5k7d3ldim1lymw-workbench-0.1/bin/backend.sh: line 60: WORKBENCH_BACKEND: unbound variable
'''

and here is result of cardano-node install:

```
exprType TYPE: Text
exprType TYPE: Text
exprType TYPE: Text
exprType TYPE: Text
exprType TYPE: Text
workbench:    prebuilding cardano-cli
/nix/store/m2ckif2l1xf3x9y91wgczlah2snvbicw-cabal-install-exe-cabal-3.6.2.0/bin/cabal --project-file=/Users/deano/plutus/cardano-node/.nix-shell-cabal.project -v0 build -- exe:cardano-cli
exprType TYPE: AssetName
exprType TYPE: AssetName
workbench:    prebuilding cardano-topology
/nix/store/m2ckif2l1xf3x9y91wgczlah2snvbicw-cabal-install-exe-cabal-3.6.2.0/bin/cabal --project-file=/Users/deano/plutus/cardano-node/.nix-shell-cabal.project -v0 build -- exe:cardano-topology

  Commands:
    * nix flake lock --update-input <iohkNix|haskellNix> - update nix build input
    * cardano-cli - used for key generation and other operations tasks
    * wb - cluster workbench
    * start-cluster - start a local development cluster
    * stop-cluster - stop a local development cluster
    * restart-cluster - restart the last cluster run (in 'run/current')
                        (WARNING: logs & node DB will be wiped clean)
'''

cardano-cli etc are working

I have used the local cluster from cardano-node many times and on several different installs (1.34.1 & 1.33.1) and did not encouter the issue you are having.   No need to run start-cluster from sudo, so you can rule this out.
It sounds like there may be an issue with an invalid nix cache somewhere, so maybe you should try to clear/delete your nix store and start fresh?
https://nixos.wiki/wiki/Cleaning_the_nix_store


text:
Where does Nami store private keys?
I would like to access my private key from Nami wallet. Where are they supposed to be stored?

Here is the GitHub for Nami, as it is open source.
Looks like it uses chrome local storage. I believe chromes local data is located in %AppData%\Google\Chrome\User Data\Default\Local Storage atleast for windows users.

In which file ? It's filled with predominantly log files for me

You'd have to check your extension ID (you can check that in Dev Tools), and go to <Browser AppData Path>/User Data/Default/Local Extension Settings/<extension ID>.
In there you'd see a LDB file (viewing it in ASCII viewer will still show you the encrypted private key, that can only be decrypted using your spending password).
But in general, you're better off using mnemonics instead of trying to use decrypted private keys

Last time I had only my mnemonic key and when the coin was no longer supported by the wallet i had to find a private key to get access which I did not write down because I thought mnemonic was enough. I was never able to retrieve those coins after that even though i had the mnemonic and spoke to the tech team. That was with the Guarda Wallet. I think you need both private key and mnemonic as a backup. And this option should be in the wallet interface like every other wallet has. should not have to fish around for it.


text:
Is it possible to consume a script UTxO in the same block?
Let's say I lock some ADA at a script address. Someone who knows the redeemer value can unlock this ADA. Is it possible to include a redeeming tx in the same block as the tx which locks the ADA at the script address? Provided that the script tx was first in the mempool? Or is it necessary to wait at least for 1 confirmation before the ADA can be unlocked from the script address?

If the first output is in the mempool, you can use it in a subsequent transaction without the node throwing an error. However, there is no assurance that both transactions will be part of the same block.

When would be such case that both the transactions wouldn't be included in the same block? For example under heavy blockchain load?

I'm not sure of the exact scenario, I believe it works like first come first serve basis, so    all trxs in mempool may not fit in one block


text:
Where to locate the path to node.socket in order to set CARDANO_NODE_SOCKET_PATH env variable?
I would like to check the sync progress of the cardano node from within a cardano-node-ogmios docker container that I installed. When I open the docker CLI and I run the command cardano-cli query tip --mainnet I get that $CARDANO_NODE_SOCKET_PATH environment variable is not defined. I've tried locating /db/node.socket path, but I cannot seem to find it. Any clue as to where it may be located?

Just a side note, you can run cardano-tip outside of container, no need to login to container. I use it something like that from the host: docker exec -ti test-producer /usr/local/bin/cardano-cli query tip --testnet-magic 1097911063

A note for other people, when starting your node the --socket-path option will contain the path to the socket.
CARDANO_NODE_SOCKET_PATH should match this value.
cardano-node run \
   --topology path/to/mainnet-topology.json \
   --database-path path/to/db \
   --socket-path path/to/db/node.socket \
   --host-addr x.x.x.x \
   --port 3001 \
   --config path/to/mainnet-config.json

After checking the Ogmios documentation again I finally found it in /ipc/node.socket. (Post can be deleted or remain in case for future reference)

Including the snippet of the documentation would improve your answer and remember you can mark your own answer as accepted.

Just create db folder inside your cardano-node, and pointing your script to that folder, the node.socket will be created once after you node is sync 100%


text:
Plutus playground not starting with Interpreter error after running :set in GHCI
plutus-playground-server: user error (Error evaluating simulation: InterpreterError (CompilationErrors [CompilationError {filename = "\n/private/tmp/web-ghc-work-1626f2e537d27294/Main.hs", row = 2, column = 1, text = [" error:","    Could not load module \8216Playground.Contract\8217","    It is a member of the hidden package \8216playground-common-0.1.0.0\8217.","    You can run \8216:set -package playground-common\8217 to expose it.","    (Note: this unloads all the modules in the current scope.)","    It is a member of the hidden package \8216playground-common-0.1.0.0\8217.","    You can run \8216:set -package playground-common\8217 to expose it.","    (Note: this unloads all the modules in the current scope.)","    Use -v (or `:set -v` in ghci) to see a list of the files searched for.","  |","2 | import Playground.Contract","  | ^^^^^^^^^^^^^^^^^^^^^^^^^^"]},CompilationError {filename = "/private/tmp/web-ghc-work-1626f2e537d27294/Main.hs", row = 3, column = 1, text = [" error:","    Could not load module \8216Plutus.Contract\8217","    It is a member of the hidden package \8216plutus-contract-0.1.0.0\8217.","    You can run \8216:set -package plutus-contract\8217 to expose it.","    (Note: this unloads all the modules in the current scope.)","    It is a member of the hidden package \8216plutus-contract-0.1.0.0\8217.","    You can run \8216:set -package plutus-contract\8217 to expose it.","    (Note: this unloads all the modules in the current scope.)","    Use -v (or `:set -v` in ghci) to see a list of the files searched for.","  |","3 | import Plutus.Contract","  | ^^^^^^^^^^^^^^^^^^^^^^"]},CompilationError {filename = "/private/tmp/web-ghc-work-1626f2e537d27294/Main.hs", row = 4, column = 1, text = [" error:","    Could not load module \8216PlutusTx.Prelude\8217","    It is a member of the hidden package \8216plutus-tx-0.1.0.0\8217.","    You can run \8216:set -package plutus-tx\8217 to expose it.","    (Note: this unloads all the modules in the current scope.)","    It is a member of the hidden package \8216plutus-tx-0.1.0.0\8217.","    You can run \8216:set -package plutus-tx\8217 to expose it.","    (Note: this unloads all the modules in the current scope.)","    Use -v (or `:set -v` in ghci) to see a list of the files searched for.","  |","4 | import PlutusTx.Prelude","  | ^^^^^^^^^^^^^^^^^^^^^^^"]}]))

I am getting an Interpreter error when trying to start the playground. It happened after I ran :set -package plutus-ledger in ghci. How can I reverse this?

Fixed it by deleting path ~/.ghc/X86_.../environments/default. It was loading this profile by default in ghci


text:
Python equivalent to Ogmios?
Has somebody written a library equivalent to Ogmios, that has the same functionalities, including a chain sync protocol, but entirely written in Python?

I just put this library together as I needed to access Ogmios from a Python application. It is still a work in progress, but it is working.
https://pypi.org/project/pyogmios/

I accepted your answer and gave a look at the repo. Very impressive that you built this. Will there be more documentation available over time? For example, how to store UTxO/asset data in SQL(ite) databases/dealing with chain rollbacks?

Thanks for accepting the answer. I am currently rewriting it to work with the latest version of Ogmios (v6.0.*). I can include some example code on handling the cases you mentioned, but the implementation details may differ as I am using MongoDB for the database.

https://pypi.org/project/pycardano/
I think this is as close as it gets with Python so far...


text:
When multiple users try to spend the same output at the same time, who will get priority?
Let's assume we have some NFT minting drop with more than 1000s of participating buyers who try to spend the same output, all at the same time. How does the chain decide who gets to spend the output? Is it first-in (the buyer who submitted the tx first), completely random, or something else?

The first transaction who makes it into the mempool will be the one spending the output.
And in case there is congestion on the blockchain and multiple transactions make it into different mempools (on different nodes), the one who is adopted in a block first will be the one spending the UTxO.

@George-APEXStakePool So as long as each person submits around the same time of a new block being minted, it's basically random which out of all the txs in the mempool will be included on-chain?

Not quite random, the first transaction that enters the mempool of the block producer chosen to create the next slot will win, Its not quite random, but it will effectively look like its random.

Stake Pool Operators can figure out which future slot in the current epoch they are due to mint, but if you are not an SPO you will not be able to figure out which SP is next to mint a block.

@George-APEXStakePool I think you should answer the question with what you said in this comment, for future references.

The first transaction who makes it into the mempool will be the one spending the output. And in case there is congestion on the blockchain and multiple transactions make it into different mempools (on different nodes), the one who is adopted in a block first will be the one spending the UTxO.


text:
Create transaction serialization-lib > version 10
I'm using cardano-serialization-lib ^9.1.2 to create transaction.
I'm using method that are now deprecated in version 10, so is there an example of transaction with serialization-lib latest version used on nodejs?

You can check the changelog here for some examples and explanations: https://github.com/Emurgo/cardano-serialization-lib/releases/tag/10.0.0
A rough example could look something like this:
function createExampleTx() {

  const protocolParams = await blockfrost.fetchParameters();

  // Create TransactionBuilderConfig (see func below)
  const txBuilderConfig = getTxBuilderConfig(protocolParams);

  // Create TransactionBuilder
  const txBuilder = TransactionBuilder.new(txBuilderConfig);

  txBuilder.set_ttl(protocolParams.slot + 10000);

  // Create and add outputs
  const txOut = TransactionOutputBuilder.new()
    .with_address(RECEIVER)
    .next()
    .with_coin(BigNum.from_str("5000000"))
    .build();

  txBuilder.add_output(txOut);

  // Create and add Inputs
  const utxos = await getUtxos(SENDER);
  txBuilder.add_inputs_from(utxos, CoinSelectionStrategyCIP2.LargestFirst);

  // Add change and fees
  txBuilder.add_change_if_needed(SENDER);

  // Build transaction
  const txBody = txBuilder.build();

  const unsignedTx = Transaction.new(
    txBody,
    TransactionWitnessSet.new()
  );

  // ...
}

function getTxBuilderConfig(protocolParams: ProtocolParameters): TransactionBuilderConfig {

  return TransactionBuilderConfigBuilder.new()
    .fee_algo(LinearFee.new(
      BigNum.from_str(protocolParams.linearFee.minFeeA),
      BigNum.from_str(protocolParams.linearFee.minFeeB)
    ))
    .pool_deposit(BigNum.from_str(protocolParams.poolDeposit))
    .key_deposit(BigNum.from_str(protocolParams.keyDeposit))
    .max_tx_size(protocolParams.maxTxSize)
    .max_value_size(parseInt(protocolParams.maxValSize!))
    .coins_per_utxo_word(BigNum.from_str(protocolParams.coinsPerUtxoWord!))
    .build()

}


text:
Get transaction unspent output value
I have payment signing key and staking signing key of my wallet. How can I get transaction unspent outputs with cardano-cli/cardano-serialization-lib/pycardano.
I expect to get string like this 82825820eef507b798abbb8a1360efbd113f51eda22e2fbaae3cc32c78724c8644c164a40082583900756e62ff9667b187209b6fe1b577061491cf6f93a81e1f91741e2e3accb864ae67087f69bbd9ab74f71781d13ae40aab86e1de30ca7e21171a1dcd6500.
Thank you.

You don't need your payment signing key nor your staking signing key to get the list of UTxOs of any address, as this is public information. Though, you will need your spending private key to use a UTxO as input for a transaction.
With that said, you can get the list of UTxOs using function utxos from pycardano. Check the code here: https://github.com/cffls/pycardano/blob/22ab109fcfd75f4ba23d0aea620c09d92e1201c1/pycardano/backend/blockfrost.py#L111
What this function will do is to get the list of UTxOs using this Blockfrost API under the hood.

Thank you for reply, but this method returns this {'index': 1,  'transaction_id': TransactionId(hex='2a4c7fb343a525d6bd044dce725882eed41a1f20cad9fdc21855dbb250eec761')},  'output': {'address': addr1q8r32a0d8a6lp6ycrd02g9j5xljnzqvx2mkntpg4lzd6zkcyvp55w2vasj3favjz3uqcccef4vhet3z29596j2lf6shscxdf4y,  'amount': 20099765,  'datum_hash': None}, and I expect exactly another value like in my topic.

I am trying to automate the nft purchase process on jpeg.store. Purchase trx build request contains this value "collateral":["82825820733717b579bfdace...8eafb97d2e60b0951a004c4b40"]. But I have no idea how to get it.

If I deserialize it from CBOR I will recive follow data [[h'0E5569B3E2A645A849E5DB422A86F4705E947A294DFB0E7D04D88A5162482428', 1], [h'01709C2F10828D291925C6887375E90289B001C1521DEB3D3AA2F779E6C0E49B65E74CDDEAADA2C3A37CDC01416A6269ADAF84D82F49DA3BD9', 14320544]]

I don't know what is that value you are expecting really. Can you explain a little more where did you get that value from?

I want to automate the purchase process on jpg.store and to build the transaction I need to send this data to the server. https://imgur.com/a/E5Nbr4R


text:
How to loop through multiple pages of blockfrost api in Javascript
I'm trying to count the assets at a blockfrost api endpoint. It only shows 100 items on a page though. How do you loop through all the pages and extract the asset count? Thanks for any help.
const Http = new XMLHttpRequest(),
        method = "GET",
        url = 'https://cardano-mainnet.blockfrost.io/api/v0/accounts/stake1';

    const PAGE_SIZE = 100 /* 100 is the max Blockfrost page size */
    const stake_address = 'stake1';

    Http.open(method, url, true);
    Http.setRequestHeader('project_id', 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx');
    Http.send();
    Http.onreadystatechange = (e) => {
        if (e.currentTarget.readyState == 4 && e.currentTarget.status == 200 && e.currentTarget.responseText != '') {
async function count_assets() {
let total = 0;
try {
                let total = 0;
                let assets = [];

do {
    assets = Http.responseText;
    total += assets.length;
    page++;
    } while (assets.length == page);
} catch (err) {
    console.log('error', err);
}
return total;
}

count_assets(stake_address).then(assets => {
console.log(stake_address, 'assets:', assets);
});
            }}

You probably want to use the "Assets associated with the account addresses" endpoint. You can add query params to the request as per specification.
E.g. to get 100 items on page 3: /accounts/{stake_address}/addresses/assets?count=100&page=3
Now simply create a loop that increments the page query param until you don't get 100 items in the response.


text:
Getting errors when using cardano-wallet-js --> Can't resolve 'fs'
I've been going through the cardano docs at https://developers.cardano.org/docs/get-started/cardano-wallet-js to test the interface.  I installed the package using npm without issue and am starting with including the package in my project using:

const { WalletServer } = require('cardano-wallet-js');

When I save i get the following error:
Compiled with problems:X

ERROR in ./node_modules/@emurgo/cardano-serialization-lib-nodejs/cardano_serialization_lib.js 16189:14-40
Module not found: Error: Can't resolve 'fs' in 'C:\Users\Greg\Documents\crypto-app-test\node_modules@emurgo\cardano-serialization-lib-nodejs'

I originally had a number of errors which were fixed by installing various packages.  I tried doing the same with the fs package but that did not resolve the issue.
I am on a windows 10 virtual machine using the following:
vs code v1.76.1
node js v16.14.2
react v18.1.0
cardano-wallet-js v1.4.0
cardano-serialization-lib-nodejs v10.0.4
i took a look at the fs package and it seems to be abandoned or deprecated and has the following info in the readme:

Security holding package
This package name is not currently in use, but was formerly occupied
by another package. To avoid malicious use, npm is hanging on to the
package name, but loosely, and we'll probably give it to you if you
want it.
You may adopt this package by contacting support@npmjs.com and
requesting the name.

I do have a running wallet server running on another machine but haven't gotten to the point of trying to connect to it through this js package.  Anyone know what's going on here?


text:
cardanocli-js and cardano-wallet-js vs cardano-wallet rest api and cardano-graphql how do they differ?
I've been going through the cardano docs at https://developers.cardano.org/docs/get-started/ and have come across discussions around the cardano-wallet rest api and cardano-graphql implementation.  I also saw that there are implement js implementations for cardanocli and cardano-wallet.
I'm currently playing with the platform but eventually I'm planning on building a service in React.  What's the difference between the different interfaces and which is best to use?
For context I'm playing with a few ideas around minting ntf's and creating a new coin.

I would recommend you to checkout https://github.com/StricaHQ/typhonjs, which is a pure js Cardano wallet library, which will be sufficient to creating mint transactions and much more

cardano-rest-api & cardano-graphql are backend components that you can use to run your own infrastructure to read data from the blockchain or submit transaction to via the rest api. Graphql, I believe is required to run in combination with cardano-db-sync.
cardanocli-js and cardano-wallet-js are JS libraries that correspond to cardano-cli and cardano-wallet.
The cli can be used to create transactions manually, make queries against a cardano node instance for retrieving infos of addresses or also to generate verification and signing keys for payment or staking.
The wallet is primarily concerned about allowing to create/ restore HDR wallets based on mnemonic phrases.
I recommend reading the docs for each for more info.


text:
utxo fail problem(utxo fee too small
we faced the utxo failure issue
the error message is like
message: '"transaction submit error ShelleyTxValidationError ShelleyBasedEraAlonzo (ApplyTxError [UtxowFailure (WrappedShelleyEraFailure (UtxoFailure (FeeTooSmallUTxO (Coin 272465) (Coin 269165))))])"',
What is the problem?
We tested many times successfully but the error only occurred when it went to mainnet
Here is our policy id if anyone could help look into the transaction and find out what the problem is?
https://cardanoscan.io/tokenPolicy/2fd5b51792a29d9c0f77297a29bbc262de093b1072f2fc17ee048a81
There are just part of the transactions failed, we want to know why

The attached fee is too small. How are you creating your transactions? If you're using the cardano serialization lib (from here https://github.com/Emurgo/cardano-serialization-lib) and you're using the add_change_if_needed function, call it right before building the tx to make sure it adds the right fee.
Often times while testing you can have single pure Ada UTXOs as inputs and outputs and when you go live you can get fragmented multiple UTXOs to cover the required sum with various assets attached etc., which can cause the fee to vary depending on the total tx size. Depending on the coin selection strategy the mechanism for choosing UTXOs can be random, which is why it only sometimes occurs.

Yes I used cardano serialization lib, and my add_change_if_needed is just right before building the tx

txBuilder.add_change_if_needed(this.S.Address.from_bech32(PaymentAddress));
const transaction = this.S.Transaction.new(
txBuilder.build(),
this.S.TransactionWitnessSet.new(),
AUXILIARY_DATA
);

We calculate the fee and build the transaction in the frontend, then the backend sign and submit the tx, would that be the problem for the wrong tx fee?

That should not be a problem. Creating a tx on the frontend and signing on the backend generally should be fine, but there seems to be a change in tx size happening somewhere, it could be somewhere in the cbor encoding / decoding processes. Maybe this helps: https://developers.cardano.org/docs/get-started/cardano-serialization-lib/generating-transactions/#a-note-on-fees

Just set your fee to 272465 and resubmit the tx, then you should be fine

There are different utxo fee, if I just simply set to 272465, the tx exceeding 272465 will fail, unless I set it to 500000

How are you building your transactions? Because if you're using the cardano cli you can let the cli calculate the fee instead of manually inputting it.
Same can be done using the cardano-serialization library


text:
How to construct `TxOutRef`?
I am building an NFT minting policy which takes an argument of type TxOutRef as parameter. To this when I pass my parameter, it doesn't match with what is actually given in the transaction. Here is my policy:
Suppose my tx-in (in context of cardano-cli) is bccdfb39bcf97b9bc499ef19c02f33c64df1d7e68cfcff7f65a737c9c6ce4224#0. Then this is how I am passing it to compiler:
I tried comparing what I passed with what is actually received in my mkPolicy but surprisingly, if I remove out firstInput, it is able to print my error message, else with firstInput being present, I get the following in my console:

Following suggestion from here, I got it working by doing following modification:
As TxId has an instance for IsString derived via LegerBytes. In particular, this answer is also helpful.


text:
Does it make sense to talk of reference script in the context of parameterized script?
In my understanding, if my script is parameterized, I would need to know the parameters to generate the script and then store it at an address to be later referred. But usually set of possible values for parameters could be very large, so am I right in assuming that design decision of making script parameterized would make me lose the benefit of referencing it?

You are correct, if you have a parametrized script which you did not 'inject' yet with the parameters, you cannot leverage the referencing of the script.
Note that script referencing is also costly, the initial transaction that attaches the script to an output is expensive. You pay for the size you put on the active part of the chain. If your script is used often, you can save these costs by having lower transaction costs when referencing the script. This break even point has to be considered! If you only use it once, you won't get the cost of it out of the usage.
That said, you could also inject this parametrized data via another way! That is, do not parametrize your script, but retrieve the data from a reference input. Important here, do not forget to mark this input with an NFT to make it secure (remember that anybody can send anything anywhere). The location of the NFT + data in datum is your choice. You could make it so that you can update it, or so that you can have multiple instances of it. So, you can reference an unparametrized script this way :)


text:
`set` generic meaning in CDDL specification
I see the set generic in babbage.cddl file but couldn't find it's definition. It seems to be defined as set<T> = [ * T]

yes it is an array of T
the only difference is that it is meant to have unique elements; which is a constraint that you can't express in the CDDL.
You will see ofthen used as
set<transaction_input>

where transaction_input is an utxo reference; it is obvious then that it needs to be an array with unique elements (eg you CAN NOT have the same UTxO spent twice)

Thanks, is this set inbuilt in CDDL specification (RFC 8610), o/w it should be defined somewhere right?

no set is not part of the CDDL spec, that's why it is defined so

My question was, if it's not part of CDDL spec, then it should be defined somewhere right? Now I know where it is defined, which is here. I got earlier misled by the comment at top, These are definitions ... thinking these definitions are for testing purposes but rather, the ones here are for testing.

yeah, you should assume all CDDL files for a single era to be a single file; if they are referring to a set then the definition you found is correct


text:
How do I log all individual network messages in the cardano-node within a file?
I am trying to collect as much information as possible from a running Cardano node. Is there a way we can log the messages/packets exchanged between nodes in the Cardano P2P network?
Thank you.

Can you give us more information? Which platform are you running on? How did you install cardano-node? As a service(systemd) or in another way? Do you need all cardano-node logs or just part of it?

Hi, thank you for your response. I set up the cardano-node using the NIX package manager. I wanted to set it up as a service but could not find the documentation on how to do so. I would like to collect as much data as possible.

Hi, maybe this link could help you, what you need to do is to create a script to start the node and then create a service and enable it, let me know if you need help on setting things up
https://www.coincashew.com/coins/overview-ada/guide-how-to-build-a-haskell-stakepool-node/part-ii-configuration/creating-startup-scripts
After that, you can check logs using "journalctl" command

Thank You @Nic_T2H, I will check out the steps. It seems to be a promising way to go about it. Doing this with NIX can get messy. The service will surely be the cleaner solution.

Good, let me know if you need help :-)

Do you really want packet level information?
If so, search the internet for network tools like 'wireshark' or 'tcpdump' and log IP/port traffic that is of interest.
If you want application level messages you can set your node logging to debug instead of the default info to get a heap more information from your node. This change will require a restart of your node.

Hi, thank you for your response. I changed the log file to debug and enabled logging for all the application level P2P mini-protocols. With regards to the packet level information, I wanted to collect the block information that is exchanged from specific peers along with their addresses. Wireshark/TCP dump traffic does not collect readable data. I assume the connections are encrypted.

I think TCP is used directly and that the connections aren't encrypted. Deserializing the raw packets will of course be a major hassle


text:
How to Count plutus transactions?
i'm connected to the cardano-db-sync, someone knows how to count the ammout of transactions that use plutus script?
i'm using two methods here
select block.epoch_no,
count(distinct tx.id) as txs_in_epoch,
sum(case when script.type = 'plutus' then 1 else 0 end) as txs_on_plutus_contracts

from tx inner join block on block.id = tx.block_id
left join redeemer on tx.id = redeemer.tx_id
left join script on redeemer.script_hash = script.hash
where epoch_no = 298
group by epoch_no

diff

count(distinct tx.id) as txs_on_plutus_contracts
from...
where script.type = 'plutus'


text:
Plutus datum and redeemer on cardano-cli
I'm trying to deploy a smart contract on cardano-cli after its implementation on plutus playground.
Imagine that I have:
data TradeDatum = StartBid | Bid TradeDetails | Offer TradeDetails
    deriving (Generic, ToJSON, FromJSON)

data TradeDetails = TradeDetails
    { tradeOwner :: !PubKeyHash
    , budId :: !BuiltinByteString
    , requestedAmount :: !Integer
    } deriving (Generic, ToJSON, FromJSON)

How can I write this in an example JSON to submit on cardano-cli? I saw an example with int: 42,
{
  "constructor": 0,
  "fields": {int: 42}
}

but I really don't know.

How can I define the different types?
Inside the tradedetails, how can I define? and for example, how to express the pubkeyhash?

Can you give me an exmaple? There are some tutorials with the types of data that I can write inside the JSON (like int)?
Thanks.

Have a look at the following source Cardano-Api Haddock. Here you will find all about the conversion between Haskell data types and the Json format the cardano-cli uses.
I noticed that you used the marketplace of SpaceBudz as an example, so lets have a look at the other code in that repository. Notice the line 99.
print $ "Datum value: " <> encode (scriptDataToJson ScriptDataJsonDetailedSchema $ fromPlutusData (Plutus.toData offerDatum))

Here that function prints the offerDatum defined at line 85. You see here how the function from the cardano-api are used and then encoded to convert the datum to a json form? Here the <> symbol just means concatenate the two strings.
For a more detailed explanation of what is going on in this line have a look at the PPP cohort 3 lecture 3 from lars on youtube.

got it. thanks :)

{
"constructor": 0,
"fields": {int: 42}
}

This isn't valid because fields must be an array. The index of the constructor and fields will match the order of types defined for the validator script. For a Bid you'd use constructor 0 with a single field which is a json representation of TradeDetails (bytestring, bytestring, integer).
It is easier and safer to use scriptDataToJson.

got it. thanks :)

This answer helps me, indirectly. Thanks


text:
Error signer not found - txInfoSignatories
I'm trying to implement lock and withdraw of an NFT, but when I tried to check the signer on-chain with the function:
signer :: PubKeyHash
signer = case txInfoSignatories (scriptContextTxInfo ctx) of
            [pkh] -> pkh
            _ -> traceError "Signer could not be found."

It gets always signer could not be found. Why it is not found? It worked on playground until today, but I don't know if there were some updates on plutus.

Make sure the transaction has the correct required witness.

It worked on playground until today

It sounds like you had this working at some point but now you don't, what's changed? There have been no changes to that repo for a few days now. Try finding the exact commit that supposedly broke this.

when I tried to check the signer on-chain
Blockquote

If you're using a real blockchain network then perhaps you're using cardano-cli? You need to build a transaction with required-signer flag.

Maybe there was some change in some days ago, I have to check . because now in the playground, when the script has a validation with error, the transaction appears between the wallet in the same way, and in the other version the transaction does not happen because it is not validated. I don't understand... it does not make sense to change a lot of things.


text:
Plutus Script Validation Metadata
I have a question but I cannot find a concrete answer for that. I have a smart contract developed in Plutus for managing locking and withdraw of Tokens/NFTs. I'm wondering if I can validate some metadata of my NFT onchain, in my validator script.
For example, imagining this NFT: https://pool.pm/asset16tkxq9yrk6lmkwld6vnz5m8f6j54gj376jy2xx
The metadata contains: Artist, Artist Website, Id, Rarity and so on; Can I get the information about the metadata onchain on my validation script? so I can verify an specific word contained on this attributes?
Thank you so much.

There is a solution proposed in this question https://cardano.stackexchange.com/q/4609/5589 . As proposed, you can send another token to the validator script and set its datum to metadata.
Another option is proposed https://cardano.stackexchange.com/questions/4609/how-to-retrieve-the-datum-added-with-the-option-tx-out-datum-embed-file-from-th#comment4987_4609

If the NFT was minted using a transaction with metadata (cardano-cli), then the Plutus script won't be able to access this information. This is because you can only feed UTxOs to Plutus validator scripts. UTxOs don't contain the data stored on the ledger.
If you are in this situation, I would solve your problem by getting the metadata of the NFT from the ledger (using a service like Blockfrost) and validating it BEFORE feeding the UTxO to the validator script. This way, if metadata doesn't match, then there's no point in continuing with the execution of the Plutus script.
On the contrary, if the NFT was minted using a Plutus minting policy, as per this tweet, you have the ability to store this information in the UTxOs, using TxWitness field, as part of the datum hash.

If by "BEFORE" you mean in off chain code, than I don't think this is a right approach as advarsery can easily bypass that and send invalid/different metadata to an chain code.
Second proposal will work, if you store datum or datum hash in validator script utxos. If the number of NFTs is big (lets say 10_000), than this will require creation of 10_000 utxos which is costly. Currently every utxo has to have at least 1 ada so in this case that would cost 10_000ada just to be able to verify the metadata on chain.


text:
Cardano DB Sync - RTS Options
After successfully with previous question, where I tried to make cardano-node and cardano-db-sync run as a services, I tried to play around with +RTS ... -RTS option on cardano-db-sync, specifically to reduce the RAM consumption with some option.
Here's the RTS option I tried +RTS -N2 -A16m -qa -qb -qg -M6000M -RTS.
With cardano-node run ..., I can do above RTS options, but with cardano-db-sync ..., I couldn't, here's the sample command
...
...
...
PGPASSFILE=${PGPASSFILE} cardano-db-sync +RTS -N2 -A16m -qa -qb -qg -M4500M -RTS --config ${CONFIG} --socket-path ${CARDANO_NODE_SOCKET_PATH} --state-dir ${STATE_DIR} --schema-dir ${SCHEMA_DIR}

But, it fails, the error shown as below
Mar 08 09:54:54 cardano-db-sync: Most RTS options are disabled. Link with -rtsopts to enable them.
Mar 08 09:54:54 cardano-db-sync-run.service: Main process exited, code=exited, status=1/FAILURE
Mar 08 09:54:54 cardano-db-sync-run.service: Failed with result 'exit-code'.

I tried to add -rtsopts as suggested on that error, but it also fails
PGPASSFILE=${PGPASSFILE} cardano-db-sync +RTS -N2 -A16m -qa -qb -qg -M4500M -RTS -rtsopts --config ${CONFIG} --socket-path ${CARDANO_NODE_SOCKET_PATH} --state-dir ${STATE_DIR} --schema-dir ${SCHEMA_DIR}

Same error is shown
cardano-db-sync: Most RTS options are disabled. Link with -rtsopts to enable them.

Also, I tried to do that with another way (reference - on official documentation), -with-rtsopts="-N2 -A16m -qa -qb -qg -M6000M", but it also fails with error, as shown below
Invalid option `-with-rtsopts=-N2 -A16m -qa -qb -qg -M4500M'

Is it possible to add the options +RTS ... -RTS like I tried above?
Or, am I did wrong? Like, it must come sequentially right after/before some command?
Thanks in advance! And, have a great day!

*PS

The reason I did try to reduce the RAM consumption is because cardano-node run and cardano-db-sync keeps dropped (killed) from the services, since I had limited RAM (16GB) on my test server. I kinda aware with RAM requirement, but I tried to reduce it, due some circumstances, I can't upgrade RAM on my test server, since it has cardano node running too.

I'm not GHC expert or even linux expert. So, if there's some terms or RTS option that I use incorrectly, please let me know, so I can do in a correct way. :)

I am the main developer on db-sync. Trying to reduce the memory footprint of db-sync using RTS options will fail with 100% certainty.
The problem is that both node and db-sync have a data structure called ledger state (which is huge, like 8 Gigabytes huge) that is basically identical. Long term, we want to reduce that so that db-sync does not need to maintain that. Until then, you need to just live with the high memory usage.

Hi @ErikdeCastroLopo - thanks for your comment & explanation. Want to confirm for your statement - "Trying to reduce the memory footprint of db-sync using RTS options will fail with 100% certainty." - is that meant I couldn't use RTS options, like I used on cardano-node run? || And, "Until then, you need to just live with the high memory usage." - you mean, the only way is to upgrade RAM?

RTS options might allow you to shave as much as 20% off the memory usage at the cost of a performance hit (because the garbage collector will need to run more often). Unfortunately the only current solution is more RAM.

Do you know what RTS options that might be available for me to use? since, from what I test around from initial options +RTS -N2 -A16m -qa -qb -qg -M6000M -RTS it gives me error message Most RTS options are disabled. Link with -rtsopts to enable them.. Anyway, thanks for your comments.

Oh, sorry, RTS opts are disabled by default in the db-sync build.
To enable it add -rtsopts after -with-rtsopts=-N3 for the cardano-db-sync executable in the file cardano-db-sync/cardano-db-sync.cabal

Thanks for your guide! seems it kinda works, but unsure if it will fail or not, since I just started the cardano-node run again, so it needs time to catch-up. Have a great day! :)

It will like work really well for the vast majority of the mainnet chain. You are really only likely to run into problems later on the chain where there is just orders of magnitude more data on the chain.

Ahh yes.. I tried to tweak around the RTS options, but on some options, it will be dropped (service killed since it needs more RAM consumption). Anyway, your comment to add "-rtsopts" is correct, do you mind to post it as answer perhaps? so I can mark it as the correct answer on this post. :)

RTS opts are disabled by default in the db-sync build. To enable it add -rtsopts after -with-rtsopts=-N3 for the cardano-db-sync executable in the file cardano-db-sync/cardano-db-sync.cabal.

thanks for this! hope the others will got help in the future!


text:
Plutus: Integer->Value?
I give to Integer via an endpoint function, multiply them and give them to
Constraints.mustPayToTheScript. For this I need the result to be converted into an Value. Does Anyone know how to do this?
 buy =  endpoint @"buy" @BuyParams $ \ (BuyParams fst scd ) -> do
    let amt = fst*scd
    let tx         = Constraints.mustPayToTheScript (hashString fst) amt
    void (submitTxConstraints gameInstance tx)

Is ADA what you want to pay to the script?

Supposing that you want to pay ADA to the script, you can use lovelaceValueOf :: Integer -> Value from Plutus.V1.Ledger.Ada as follows:
import qualified Plutus.V1.Ledger.Ada as Ada

buy = endpoint @"buy" @BuyParams $ \ (BuyParams fst scd ) -> do
   let amt = fst*scd
       val = Ada.lovelaceValueOf amt
       tx  = Constraints.mustPayToTheScript (hashString fst) val
   void (submitTxConstraints gameInstance tx)

Hope this will be useful.

Yes! Solved it thanks :)

@John_Bones more than welcome!


text:
Select only one UTxO from script address
I need to get only one UTxO from the script address, where its datum hash matches the redeemer hash. For example I have locked two UTxO with 10 Ada  and the DatumHash "house" at the script and only want to unlock one of them.
I use the guessing game example of the Plutus Playground, but it unlocks both UTxO when the Redeemer has the same hash:
guess = endpoint @"guess" @GuessParams $ \(GuessParams theGuess) -> do
    -- Wait for script to have a UTxO of a least 1 lovelace
    utxos <- fundsAtAddressGeq gameAddress (Ada.lovelaceValueOf 1)

    let redeemer = clearString theGuess
        tx       = collectFromScript utxos redeemer

    let hashedSecretWord = findSecretWordValue utxos
        isCorrectSecretWord = fmap (`isGoodGuess` redeemer) hashedSecretWord == Just

    void (submitTxConstraintsSpending gameInstance utxos tx)

-- | Find the secret word in the Datum of the UTxOs
findSecretWordValue :: Map TxOutRef ChainIndexTxOut -> Maybe HashedString
findSecretWordValue =
  listToMaybe . catMaybes . Map.elems . Map.map secretWordValue

-- | Extract the secret word in the Datum of a given transaction output is possible
secretWordValue :: ChainIndexTxOut -> Maybe HashedString
secretWordValue o = do
  Datum d <- either (const Nothing) Just (_ciTxOutDatum o)
  PlutusTx.fromBuiltinData d

At which part do I have to change the code, so it only unlocks one UTxO (best case: a random choice of both)?

You may need to update this part:
utxos <- fundsAtAddressGeq gameAddress (Ada.lovelaceValueOf 1)
Try:
utxos <- Map.take 1 <$> fundsAtAddressGeq gameAddress (Ada.lovelaceValueOf 1)
You need to change the import on top to
import PlutusTx.Prelude hiding (pure) so as to use <$>.
I have tried it using 4 wallets (somehow the Playground does not allow one wallet to make multiple calls) and it worked.


text:
How to get the address which locked the fund on a smart contract?
I have two users. The first user locks 1 ADA with a Datum at a script address. The second one unlocks the 1 ADA with the same Datum and should now send 5 ADA to user one.
Can I now implement a logic in my endpoints so that the second user can send 5 ADA directly to the first user. In order to do that the second user needs two know the wallet address of the first user, but how does he get this information?
Thanks!


text:
How to get tAda?
Currently tAda faucet is down ("We are curently experiencing techincal issues with the faucet"). Please bear with us while we get this sorted"). Is there any alternative to get tAda?
If anybody can help by sending me tAda, below is my address :
addr_test1qzea2taqlalpquy8mysrzu399lrqwyn3rh0j6uxlhrlrm8kdvc7hex6r9hyqh0pfwa4creandeuv0cv8slyj5qrwzurqk3a0gn

The faucet worked for me just now, even though it shows the message: "We are curently experiencing techincal issues with the faucet. Please bear with us while we get this sorted".
It only took about 1 minute to complete.
I've sent you 750 tADA anyway, just in case.

Thank you so much, received tAda you sent.

Also I've just tried the faucet, it works now. Thank you.

It works fine. Just the API on the wallet is responding really slowly because the tx history has ballooned recently. We'll fix this when we get a chance but ignore the server error for now. I've tested it a couple times and eventually received the funds about 10 minutes after I requested.

Here the screenshot of the faucet experiencing server error

great reaction Samuel,
thanks for the update and verification.

please find here all info,
and you can request them
To request tokens using the faucet:
https://testnets.cardano.org/en/testnets/cardano/tools/faucet/

The problem is currently the faucet in that link is down. Is there any alternative?

another try i would do by join the groups below, - either telegram, https://t.me/CardanoStakePoolWorkgroup - or cardano forum forum.cardano.org/ - and ask people if they have to share them with you.


text:
How to query cardano graphql api to get all assets metadata from a specific policy id
currently I'm using blockfrost to request NFT metadata information one by one from a specific policy_id. A policy ID can have up to 10k assets minted so it takes quite a while to fully sync to my local database.
Can I define a graphql schema to do the same thing with dbsync but with just 1 or a few request to the Cardano graphql server?
Was trying on https://graphql-api.mainnet.dandelion.link/ and couldn't figure this out, any help would be appreciated, thanks.

Took a while for me to figure out as well but this works. It will return all the asset ids of a particular policy
query TokensByPolicy($policy_id: Hash28Hex) {
  assets(where: { policyId: { _eq: $policy_id } }) {
    assetId
    policyId
    assetName
  }
}

And you need to pass the policy id as a parameter
{"policy_id": "7be8b5c60e913079bc1ccf58247dbaf5433fcb70d0abc89a7dd333d4"}

You can try it out at https://graphql-api.mainnet.dandelion.link/


text:
Automatically "taxing" native token transactions
To fund the "commons" for some community with some token T, it might make sense to "tax" transactions within this community, similarly to how a gas fee funds the operations of the underlying blockchain, or how a town raises money for the fire department through a sales tax on retail transactions.
The idea is that if A sends 100 T tokens to B, say 1 of those gets sent to C (the commons) and only 99 arrive with B. I would want this to be automated, so that within that community, nobody can cheat.
Can I do this with a native token? If so, how?

I know that royalties can be set for NFT projects. I haven't yet seen royalties set for fungible tokens, but I don't see why it wouldn't be possible. What you're proposing sounds like a 1% royalty.  You may find some good information here: https://github.com/cardano-foundation/CIPs/pull/116/files

Ah, excellent, the ground work seems to come into existence then.


text:
What is the exact transaction lifecycle?
Something which is still fuzzy to me. What is the exact transaction lifecycle?
What happens after we submit a transaction via the cli? Does the transaction get broadcasted to the nodes directly for the validation process to kick off?
Thanks!

I asked a similar question here. It’s great that this being discussed and the external links provided in the answers have been helpful. https://cardano.stackexchange.com/q/7537/4685

Importantly, a transaction, when sent, cannot be cancelled. One can only request forgetting about it in order to try spending (concurrently) the same UTxO in another transaction. But, the transaction may still show up later in a block and therefore, appear in the wallet.
Discovering a transaction happens regardless of a transaction being present or not as pending. Actually, only outgoing transactions are going through the pending state. Incoming ones or, outgoing ones that have been forgotten may be discovered directly in blocks.
please check here :
https://input-output-hk.github.io/cardano-wallet/concepts/transaction-lifecycle

Super thanks for this. This is really helpful.


text:
What is an unbalanced transaction? How does adjusting an unbalanced tx actually work?
In Week06, there was an implementation of adjusting an unbalanced transaction in the plutus script.
Can someone explain what an unbalanced transaction really is?
And how does it actually work when we say adjusting an unbalanced transaction?
How do we basically identify that a transaction is unbalanced?
Thank you!

A transaction consumes a set of funds (so called UTxOs) and produces a set. Additionally, it can burn or mint native tokens. An unbalanced transaction is a transaction where the sum of fees and funds produced are not equal to the sum of input funds, minted tokens, and burned tokens.
The balancing takes care of this and adds necessary funds in the inputs and outputs to get to the equality.

Thanks! Oh so this is basically what Lars initially mentioned that the sums of the amounts that are used as inputs, should equal the amounts of the output? Adjustment then is basically the distribution of funds in order for those numbers to add up?

Balancing consists of two parts: i) adding additional inputs ii) distributing excess funds to outputs. Often both parts are needed but in some cases i) or ii) can also be needed alone.


text:
Can I use Blockfrost to call custom endpoints of my Plutus offchain contract?
Blockcfrost-related question. Can we expose our own custom endpoints in our off-chain Plutus contract, and use your API to send requests from our own frontend client? For example, if I expose an endpoint named "collect-funds" in my Plutus off-chain contract, can I call that endpoint from my react app via your API to execute my Plutus contract functionality which is related to that endpoint? Super thanks in advance!

You can blockfrost-haskell from you off-chain code to call the Blockfrost API.
Or you can use Blockfrost endpoint integration for the PAB available in PAB directly.


text:
How to link custom API endpoints with Plutus script? (Without Blockfrost or PAB)
I have a few questions, which I think might interest a lot of folks here.
Me and my team we are developing an app on Cardano and we want to avoid using PAB or Blockfrost for our infrastructure. We are thinking about creating our own custom APIs using Express/Node, and we will do all the transaction construction/balancing on the client-side using serialization library.
My questions are:

How do we should design our APIs (i.e for a liquidity pool smart contract or a voting smart contract)?

What is the actual coding process? Do we code endpoints via express, and we code the same endpoints inside our Plutus script?

Do we need to do something for the Plutus script & our custom API endpoints to be able to talk with each other?

Thank you in advance for your help.

Have you already written and tested your smart contracts with the PAB? I think, this would be a starting point do understand what you need. For quick development, the PAB is great. Only actual deployment is a pain.

Hey thanks for this. Is PAB really good for fast development? I mean I need to run so many things on my machine to make it work which are resource heavy.

What things do you mean ? For testing with EmulatorTrace you don't need chain index and a Cardano node for example. It is very convenient for defining your scenarios, seeing what happens when you execute them, and debugging. For real tests on the public testnet you would need chain index and Cardano node, though. This is when the problems start : ).

Yeah exactly. Im referring for end-to-end production ready solutions.

Using the PAB for development and testing does not mean you can't use another solution for end-to-end production. Developing inside the PAB will help you find out which API endpoints you need and how the user should interact with your Plutus scripts. These scripts are independent of the PAB anyway. You will also realise that you cannot do everything client-side and that you need some component that can query the blockchain.

Yeah ofcourse. But as you said, when u want to do real things/tests on the testnet/mainet, is when the problems start. With that being said, I want to avoid PAB. Do you know how to achieve what I am asking? Super thanks!


text:
How can I code a liquidity pool?
I am really interested in how i can code a liquidity pool using Plutus.
What are the mechanics & the components I need to handle? Is there a specific pattern, skeleton to follow?

I think a good starting point are the following links bc the question is fairly broad. Perhaps also take a look at existing Dexes that (plan to) open source their code.

https://www.youtube.com/watch?v=CPfcyDaDtt8
https://plutus-pioneer-program.readthedocs.io/en/latest/pioneer/week10.html


text:
Cardano dapp user authentication based on the wallet address
What are the best options to add user-authentication system based on the wallet address for my website? Thanks

There a few ways to do this- one way I've seen is to request a very specific (small) amount of ADA from that wallet, then send it back (minus TX fees).
Alternatively, you may ask the wallet holder to sign a message with their private key, as specified by CIP-8


text:
Dapp connection with mobile browser
How do I connect my cardano website (dapp) with cardano mobile wallet. currently, I am using yoroi-frontend for desktop browsers.

You will be more likely to get answers if you follow the guidelines in [ask]

@gRebel Thanks a lot!

Look in the window object for window.cardano and then look for the property yoroi and then you can interact with the public API.
To enable the wallet use window.cardano.yoroi.enable(). This will return an object with the endpoints to interact with the wallet or will fail if the user does not allow to read the wallet.


text:
Connect Unity 3D game with cardano
I am creating a play to game in Unity 3D. What is the best way to authenticate wallet of the users and send cardano native tokens.

You can use cardano-unity SDK for this purpose.


text:
4 purchased CNFTs showing no asset image?
asset1w2pqwj7cnv0dw40rtgv5vuzwa7jswcl24lkyw6
a0e859a7b29dbfc2b798ed720802fff406fe09b8e3c9a6b3affb7320
asset19s8v6a43k4ngrmy6wvccxqm08kuae4hfftt0ah
a0e859a7b29dbfc2b798ed720802fff406fe09b8e3c9a6b3affb7320
asset1pe24aeqhr0z9d0cq6pgrjf7dzegrdkgf0dv9af
84c0acb101c14416ad92859c429058871e201804468d5f353be31d71
asset1v34sp6q60z2c2u8fy6gh0su8hc0frghmtr0n9g
a0e859a7b29dbfc2b798ed720802fff406fe09b8e3c9a6b3affb7320
Policy IDs and fingerprints of the 4 CNFTs
I have bought 11 altogether and all the rest have no issues.
Any help would be greatly appreciated.

where do you try to check and you find no asset image?
for all your assets i check on links below, using the asset ID next to pool.pm/asset_here :
https://pool.pm/asset1w2pqwj7cnv0dw40rtgv5vuzwa7jswcl24lkyw6
you can replace the "assetXXXX" with one of your address in your wallet, and you can see all your tokens in your wallet.
please let me know if you need something more,
TTS17


text:
Error querying protocol parameters in local network created from scratch
I'm creating a local testnet for development purposes with the following steps:
  # create genesis files:
  mkdir /tmp/cardano
  cd /tmp/cardano
  cardano-cli genesis create --testnet-magic 777 --gen-genesis-keys 1 --gen-utxo-keys 1 --supply 1000000000 --genesis-dir /tmp/cardano/

  # KES keys
  cardano-cli node key-gen-KES --verification-key-file /tmp/cardano/kes.vkey --signing-key-file /tmp/cardano/kes.skey

  # Operational certificate (VRF keys created automatically under /tmp/cardano/delegate-keys/)
    cardano-cli node issue-op-cert --kes-verification-key-file /tmp/cardano/kes.vkey --cold-signing-key-file /tmp/cardano/delegate-keys/delegate1.skey --operational-certificate-issue-counter /tmp/cardano/delegate-keys/delegate1.counter --kes-period 0 --out-file /tmp/cardano/op.cert

  # download & tweak node configuration
    wget https://raw.githubusercontent.com/input-output-hk/cardano-node/master/configuration/defaults/byron-mainnet/configuration.yaml
    sed -i 's/Protocol: RealPBFT/Protocol: TPraos/' configuration.yaml
    sed -i 's/minSeverity: Info/minSeverity: Debug/' configuration.yaml

   # create a topology file (empty because I'm not conneting to anyone)
    echo '{"Producers": []}' > node-topology.json

   # start the node:
     cardano-node run \
      --config configuration.yaml \
      --topology node-topology.json \
      --database-path /tmp/cardano/db \
      --socket-path /tmp/cardano/db/node.socket \
      --shelley-kes-key /tmp/cardano/kes.skey \
      --shelley-vrf-key /tmp/cardano/delegate-keys/delegate1.vrf.skey \
      --shelley-operational-certificate /tmp/cardano/op.cert \
      --port 7777

Everything seems to work  fine up until this point. However, when I try to query the protocol parameters:
   # Check node status
   export CARDANO_NODE_SOCKET_PATH=/tmp/cardano/db/node.socket
   cardano-cli query protocol-parameters --testnet-magic 777

I get this error:
cardano-cli: encodeFailure: local state query: using acquire without a Point must be conditional on negotiating v8 of the node-to-client protocol
CallStack (from HasCallStack):
  error, called at src/Ouroboros/Network/Protocol/LocalStateQuery/Codec.hs:80:7 in ouroboros-network-0.1.0.0-IeuFKu6VZwxK0UqIEQ0YeE:Ouroboros.Network.Protocol.LocalStateQuery.Codec[

Querying a UTxO also produces the same error:
cardano-cli query utxo --testnet-magic 777 --cardano-mode --address addr_test1vz9vqpp232vpgh9w7m86qwy48a0e2c99thvqkp6jvatutecfngfmt

cardano-cli: encodeFailure: local state query: using acquire without a Point must be conditional on negotiating v8 of the node-to-client protocol
CallStack (from HasCallStack):
  error, called at src/Ouroboros/Network/Protocol/LocalStateQuery/Codec.hs:80:7 in ouroboros-network-0.1.0.0-IeuFKu6VZwxK0UqIEQ0YeE:Ouroboros.Network.Protocol.LocalStateQuery.Codec

I'm not exactly sure what this error means and what can be done to make these commands work. It used to work fine with older cardano-node versions and I was able to execute local tests very efficiently with this. My current version is:
cardano-node 1.33.0 - linux-x86_64 - ghc-8.10
git rev 814df2c146f5d56f8c35a681fe75e85b905aed5d

Can anyone help me getting a local blockchain started from scratch? The only documentation I found seems to be outdated (here: https://cardano-foundation.gitbook.io/stake-pool-course/reference/shelley-genesis)

You might want to build your script using mkfiles.sh script instead.
While TPraos based networks will stand up and function for basic node/CLI commands, there are a lot of nuances and not all tools/components built around will support the network. Instead you can make use of config options to allow your nodes to fork into specific eras - important to note tho, that when using Cardano mode in config, your Shelley genesis should not include initialFunds - which would break support for that network for components like cardano-db-sync.

You could increase the node logging to 'debug' and restart it, then retry the CLI command while monitoring the log.
Could be some more detailed info in the node log.
As an FYI I get the same error if I try to force a different mode on my mainnet connection eg --shelley-mode addded:
$cardano-cli query protocol-parameters --shelley-mode --mainnet

cardano-cli: encodeFailure: local state query: using acquire without a Point must be conditional on negotiating v8 of the node-to-client protocol
CallStack (from HasCallStack):
  error, called at src/Ouroboros/Network/Protocol/LocalStateQuery/Codec.hs:80:7 in ouroboros-network-0.1.0.0-12...12:Ouroboros.Network.Protocol.LocalStateQuery.Codec

Your setup might need --shelley-mode rather than the default --cardano-mode .
eg

cardano-cli query protocol-parameters --shelley-mode --testnet-magic
777

I presume that cardano-cli is also version 1.33.0?

The guide that you followed is from 2020 and refers to cardano-cli version 1.11.0 - a lot has changed since then.


text:
Short address crashed blockfrost calls
Using blockfrost I have pulled a list of addresses of owners of a specific fungible token.
Some of the addresses are significantly smaller than the others (about  2/3 the length).
When querying blockfrost for stake keys (or pool.pm) with those addresses i get an error 504 after a long timeout, while all the others work smoothly.
An example of the syntax and function used with python is the following api.address(addr_str)
Here is the address causing me trouble addr1w999n67e86jn6xal07pzxtrmqynspgx0fwmcmpua4wc6yzsxpljz3
How should I handle those, what are they?

Those are called Enterprise addresses, originally intended for exchanges but everyday users have started to adopt them for various reasons. Unfortunately, I can't speak to why Blockfrost API chokes when it encounters one, but there are other APIs that support these. Try Koios for example.
https://api.koios.rest/#get-/address_assets
EDIT: Ah! Just noticed an important part of your message.. The reason you're getting the timeout error is because enterprise addresses do not have stake addresses as they were never meant to stake (again they are intended for exchanges). That's why this is timing out.

Wow, thanks for the great answer !! That makes perfect sense. Do you have any specific way to spot those addresses (length of the address?)

Yes, length of address would be a great way to go. As far as I know the enterprise addresses are all the same length. The reason they are shorter is because they lack the stake key hash.


text:
Cbor address to bech32 type address in JS or python
I have managed to retrive a user address from a dapp connector wallet using JS:
api_promise = window.cardano.{wallet}.enable();
api_promise.then(function(api) {
  addr_promise = api.getUsedAddresses();
  addr_promise.then(
    function(addr) {
      value[0];  // this is a CBOR address !
...

I get this type of (presumably CBOR) address: 012f4d0b584ecb52e4e4b8e78e4ce77a6f822e59ede3277305fd526b71824b2d2740284cf6a28e2a512cc4a00f41004c18ed728a0f7a04eb29
Apparently with some skill it could be read using this -> https://cbor.me.
# Is there any method to extract a shelley addr_34.... using JS or python?
Working implementations are available in node.js, but I'm using flask (python + JS). And I'm struggling to make it work wit packages cbor2 and bech32.
For example I tried cbor2.loads(bytes(addr_str, 'utf-8')) without success.
My further goal is to query blockfrost.

You can also use typhonjs used by typhonwallet. It's a Pure JS library not dependent on WASM.
Install
npm i @stricahq/typhonjs

Usage
const typhonjs =  require("@stricahq/typhonjs");

const bech32Address = typhonjs.utils
  .getAddressFromHex("012f4d0b584ecb52e4e4b8e78e4ce77a6f822e59ede3277305fd526b71824b2d2740284cf6a28e2a512cc4a00f41004c18ed728a0f7a04eb29")
  .getBech32();

I might appear clueless, but I am running code via python Flask. It means the javascript is executed client-side. In the background, everything is executed via python and ajax queries. Will I be able to execute this client side?

Yes, you can execute this code client side :) @Lokinou

First install the npm module:
npm i @emurgo/cardano-serialization-lib-browser

Then you need a wasm loader module
class wasm {
  async load() {
    if (this._wasm) return;
    /**
     * @private
     */
    this._wasm = await import(
      "@emurgo/cardano-serialization-lib-browser/cardano_serialization_lib"
    );
  }

  get Cardano() {
    return this._wasm;
  }
}

export default new wasm();

Then import into your module/component using:
import WASMLoader from "../../utils/Loader";

Now you should be able to use wasm module to convert the CBOR address into bech32 (addr1.., stake1.. etc)
const getAddressToBech32 = async () => {
    await WASMLoader.load();
    const address = (await api.getUsedAddresses())[0];
    return WASMLoader.Cardano.Address.from_bytes(Buffer.from(address,"hex")).to_bech32();
};

Now that you have a bech32 address you should be able to use with for blockfrost API queries


text:
How to architect a truly decentralized dApp on Cardano?
I have been doing some research on how to properly design and architect a dApp solution on Cardano and came across this nicely, written article (albeit on Ethereum) The Architecture of a Web3.0 Application. I was wondering if anyone could point me in the right direction for something similar on Cardano. How are mainstream dApps like Sundaeswap, etc. architecting their solutions? I think having such documents/diagrams/suggestions readily available in the Cardano community can be of great help! Possible design ideas are also welcome.
Thanks in advance for your responses.

My self have been looking for something similar to the Web 3 stack on Ethereum. I think I found an example of a dApp which illustrates the integration between a web application and the Cardano blockchain through not just one but three wallets (Nami, CCVault, Flint).
https://jsrepos.com/lib/dynamicstrategies-cardano-wallet-connector

Depending on how many features your dApp needs, most of it cannot be fully decentralized yet. The following is a non-exhaustive list of common components of an application, and how to decentralize them on Cardano:

Authentication - If you store additional data about a user - besides what can be determined from the contents of their wallet - you need a way to authenticate them with your backend. See the guide here.
One-time payments - You can use a wallet for payments to a smart contract or wallet. This can be accomplished by making the user send money themselves through their wallet app, or by using a wallet extension (which will only work on desktop currently, as mobile phones don't support browser extensions to my knowledge).
Recurring payments - I don't think this is possible in the traditional sense. You could allow users to send extra funds to give their account "credit", then subtract from this credit whenever your payment period starts. In the future, it would be cool if you could use a reputation system to create a "credit score" for a user, and allow users to build up debt if you trust that they will pay it.
Identity - The most well-known decentralized identity system being built on Cardano is Atala Prism. It's still in develop from what I understand, but you can join their pioneer program if you'd like to integrate it into your application. Identity will be the basis of reputation systems, as over time they can generate a web of trust.
Public time-series data - Public data from sensors, IoT devices, drones, price feeds, etc. will be best suited to store on oracles. There are many companies creating oracles on Cardano. You can find a list here. I don't believe any of these are fully working yet.
Random numbers - This is also a service handled by oracles. Here is how Chainlink does it.
Small, unchanging public data - Probably something that should be stored on-chain or on IPFS.
Large, unchanging public data - IPFS may be suitable for this, but I'm not sure.
Private data - This can be as simple as using the FileSystem API (which I believe only works on Chrome - not even Brave) to read/write data locally on the user's machine. You can also use a service like Storj for private cloud data. Ideally, there would be some program that users can run on their local machine that syncs data between their local file system, their backup drives, and the decentralized cloud so applications don't need to set up access to their cloud account directly. But such a service does not exist.
NoSQL database - I don't think any decentralized databases are stable enough for a production application yet, but you could look into OrbitDB.
SQL database - No decentralized SQL database architectures exist, unfortunately.
Hosting - The only decentralized hosting platform I know of being built on Cardano is NuNet. They are in private alpha, so you can't use it yet. Alternatively, you can host your application using Akash. The only downside is that this is on the Cosmos blockchain, so if you're hoping to pay for your website automatically from user payments in Ada, good luck.
Certificates - Likely every dApp is using Let's Encrypt, which is great because it's free, automated, and open-source (I think). But I don't believe it is decentralized.


text:
Historical price data for Cardano native assets
Does anyone know where I can get historical price data for Cardano native assets? Data that can subsequently be used for data analysis and visualization. Something similar to what taptools is using highs, lows, pct change, etc.
Thanks in advance

i think you are out of luck with this one
only way to do this from the start of smart contracts and accurately would be to parse dex transactions on the blockchain
the good thing is there aren't that many dex's, especially in the early days, unfortunately it'll likely require collaboration with some dexes to pull it off
imho the only viable solution for your use case is to stick with taptools data along with additional feeds from coinmarketcap for the handful of native tokens that are on there


text:
Overlap in epochs
Is there an actual overlap in epochs (see https://poolpeek.com/#/epochcalendar)? If so why? Or is this only an allowance for timezones, or are epochs somewhat unpredictable.  On a related note on https://adapools.org/epochs most epochs are 120 hours, but some are 119.9 hours. Why?
Sorry, Probably a noob question but Why do Daedalus Rewards Report Epoch End Dates differ from other sources? doesn't quite seem relevant to my question.

epoch and slots are effectively just ways to express time from start of the chain. What you're looking at on adapools is likely the difference between first and last block within an epoch. You can check the epoch start/end time of given epoch, as well as first/last block of epoch at koios

The overlap shown is because of the display format of full days. The epoch transitions at 21:44:51 every 5 days, so for most of the day it will be previous epoch and last few hours it will be the new epoch.

No, epochs do not overlap. They are also 100% deterministic and exactly 120 hours long (on mainnet).
I cannot answer questions about poolpeek.


text:
Stake Pool Locations. How is the best way to obtain a list of cardano stake pools by country?
I'd like to develop a list of cardano stake pools by country. A static list would be OK, but a repeatable method of developing an updated list by country would be much better. Is there a way of doing this? There are some groovy maps around like The https://input-output-hk.github.io/shelley-node-map/, but a live list by country? Pool explorers dont seem to offer it easily if at all.

In general I do not think there is a reliable way to do this.
The recommended best practice is to have the actual block producing node hidden behind two public relay nodes. If the BP and the 2 relays are in three different countries, which country are you going to assign it to?
If a pool operator says their node is for country X but they run their nodes from another country Y, which country are you going to assign it to?

Makes sense! I guess I am interested in the pools claim to be from country X. So back to the website for that - as you say not particularly reliable.

You may want to look at some of the web sites like https://pooltool.io which may have country information


text:
User error: Caused by: [ (builtin unConstrData) (con data #187b) ] while trying to unlock tokens from contract
hi I am getting this error while trying to unlock tokens from my treasury contract it is already topp up with tokens when trying to unlock with the access token doesn't know the exact reason behind this pls help me out
StackingTreasury.hs
{-# LANGUAGE DeriveAnyClass        #-}
{-# LANGUAGE DeriveGeneric         #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE MultiParamTypeClasses      #-}
{-# LANGUAGE OverloadedStrings          #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TemplateHaskell #-}
{-# LANGUAGE TypeApplications #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE TypeOperators #-}
{-# LANGUAGE NoImplicitPrelude #-}
{-# LANGUAGE DataKinds #-}
module Stake.StackingTreasury where

import              Ledger              hiding (singleton)
import qualified Ledger.Typed.Scripts as Scripts
import              Ledger.Value        as Value
import              Ledger.Ada
import qualified    PlutusTx
import              PlutusTx.Prelude    hiding (Semigroup (..), unless)

import              Stake.StackingTypes

{-# INLINEABLE mkValidator #-}
mkValidator :: TreasuryParam -> WithdrawalDatum -> StackingDetails -> ScriptContext -> Bool
mkValidator tp dat b ctx =    traceIfFalse "Only Issuer can change Treasury"              signedByIssuer ||
                              traceIfFalse "Access token missing from input"              inputHasAuthToken &&
                              traceIfFalse "Access token missing from contract output"    contractOutputHasAuthToken &&
                              traceIfFalse "Output Value must match StackingDetails"      checkValueToStackingContract &&
                              traceIfFalse "Treasury must keep remaining tokens"          treasuryGetsTokensBack &&
                              traceIfFalse "redeemer is not datum"                        checkReIsOutDat

  where
    info :: TxInfo
    info = scriptContextTxInfo ctx

    signedByIssuer :: Bool
    signedByIssuer = txSignedBy info $ tTreasuryIssuerPkh tp

    -- Create a list of all CurrencySymbol in tx input
    inVals :: [CurrencySymbol]
    inVals = symbols $ valueSpent info

    -- Check that list of CurrencySymbols includes Auth CurrencySymbol
    inputHasAuthToken :: Bool
    inputHasAuthToken = tAccessTokenPolicyId tp `elem` inVals

    -- The Value to be included in Stacking Contract UTXO
    toStackingContract :: Value
    toStackingContract = valueLockedBy info (bountyContractHash tp)

    -- Check that the Auth Token is sent to Bounty Contract UTXO
    contractOutputHasAuthToken :: Bool
    contractOutputHasAuthToken = tAccessTokenPolicyId tp `elem` symbols toStackingContract

    -- Check that the Value sent to Contract UTXO matches what is specified in the Redeemer
    -- Note: For now, we can just remember to match Treasury Redeemer to Bounty Datum
    -- when we build transactions
    checkValueToStackingContract :: Bool
    checkValueToStackingContract =  valueOf toStackingContract (tBountyTokenPolicyId tp) (tBountyTokenName tp) >= tokenAmount b

    -- The UTXO input from Treasury
    ownInput :: TxOut
    ownInput = case findOwnInput ctx of
        Nothing -> traceError "treasury input missing"
        Just i  -> txInInfoResolved i

    -- The UTXO output back to Treasury
    ownOutput :: TxOut
    ownOutput = case getContinuingOutputs ctx of
        [o] -> o -- There must be exactly ONE output UTXO
        _   -> traceError "expected exactly one treasury output"

    -- Values of each
    treasuryInputValue :: Value
    treasuryInputValue = txOutValue ownInput

    treasuryOutputValue :: Value
    treasuryOutputValue = txOutValue ownOutput

    -- Compare Values from and to Treasury to make sure that Treasury gets the right value back.

    treasuryGetsTokensBack :: Bool
    treasuryGetsTokensBack = valueOf treasuryInputValue (tBountyTokenPolicyId tp) (tBountyTokenName tp) - valueOf treasuryOutputValue (tBountyTokenPolicyId tp) (tBountyTokenName tp) <= valueOf toStackingContract (tBountyTokenPolicyId tp) (tBountyTokenName tp)

    getStackingDatum :: Maybe StackingDatum
    getStackingDatum = let os = [ o | o <- txInfoOutputs info, txOutValue o == toStackingContract ] in
                  case os of
                    [o] -> stackingDatum o (`findDatum` info)
                    _   -> Nothing

    checkReIsOutDat :: Bool
    checkReIsOutDat = case getStackingDatum of
      Nothing -> False
      Just ns -> bedIssuerPkh   ns == issuerPkh b &&
                 bedContributorPkh ns == contributorPkh b &&
                 bedTokenAmount ns == tokenAmount b &&
                 bedExpirationTime ns == expirationTime b

-- typedValidator :: TreasuryParam -> TypedValidator TreasuryTypes
-- typedValidator tp =
--   mkTypedValidator @TreasuryTypes
--     $$(PlutusTx.compile [||mkValidator||]) `PlutusTx.applyCode` PlutusTx.liftCode tp
--     $$(PlutusTx.compile [||wrap||])
--   where
--     wrap = wrapValidator @WithdrawalDatum @StackingDetails

-- validator :: TreasuryParam -> Validator
-- validator = validatorScript . typedValidator

typedValidator :: TreasuryParam -> Scripts.TypedValidator TreasuryTypes
typedValidator tp = Scripts.mkTypedValidator @TreasuryTypes
    ($$(PlutusTx.compile [|| mkValidator ||])
        `PlutusTx.applyCode` PlutusTx.liftCode tp)
    $$(PlutusTx.compile [|| wrap ||])
  where
    wrap = Scripts.wrapValidator @WithdrawalDatum @StackingDetails

validator :: TreasuryParam -> Validator
validator = Scripts.validatorScript . typedValidator

utxo at treasury address with datum hash of 123
cardano-cli query utxo --address addr_test1wpcsng9wvph3yn6felqewnq9wwcvuwpwdumrax2dset0vecwhasah --testnet-magic 1

result
                     TxHash                                 TxIx        Amount
--------------------------------------------------------------------------------------
0e4f0c3c372bb3c3d044f4ff72f200ad962f0f51190794dc43ca8f119b0faec2     1        2000000 lovelace + 99999999 d7d0b7e1195d3c51fefcf4e40146de39fe11162dcc56427f9e9db196.48616c + TxOutDatumHash ScriptDataInBabbageEra "7cfec515f56d4413375aa9775f5de15ee60180861e9eaa954bcf9d015054857c"

getting this error while trying to unlock funds from treasury conttract to stacking contract
Command failed: transaction build  Error: The following scripts have execution failures:
the script for transaction input 0 (in the order of the TxIds) failed with:
The Plutus script evaluation failed: An error has occurred:  User error:
The machine terminated because of an error, either from a built-in function or from an explicit use of 'error'.
Caused by: [ (builtin unConstrData) (con data #187b) ]
Script debugging logs:

unlocking command
CONTRACT_TXIN="0e4f0c3c372bb3c3d044f4ff72f200ad962f0f51190794dc43ca8f119b0faec2#1"
TOKENS_BACK_TO_TREASURY=99999989
BOUNTY_ADDR=addr_test1wz0r05r5gmfykqzt6uavku4ncacxxd60sj2auadaefudntc3cyvrk
BOUNTY_ASSET="d7d0b7e1195d3c51fefcf4e40146de39fe11162dcc56427f9e9db196.48616c"
CONTRIBUTOR_ASSET="e8abf29fc898134b44c1af4148ad15a6840c53d4d5e67483fba24ac3.6e696b6b69"
TREASURY_ADDR=addr_test1wpcsng9wvph3yn6felqewnq9wwcvuwpwdumrax2dset0vecwhasah
TREASURY_PLUTUS_SCRIPT="output/treasury.plutus"
BOUNTY_DATUM="datum.json"
CONTRIBUTOR=addr_test1vr5uap3n4mu4kcetl0luz25re3x93yfjc3kdq0ud4c2xassvq0wsd
TXIN1="b61083800814c048d1c464d8306cc817a559565e6ca10d7f887eb23cfd3e5f1b#1"
TXIN2="b72f8592ab7f740f46ba461d0302f82a69c0134c95df1622fb31ca7b5141f405#0"
COLLATERAL="290fa91f253f968f20fa347c9a8371263c7e852e9bf611a7eb91c35818fd0edf#0"
BOUNTY_AMOUNT=10

cardano-cli transaction build \
--babbage-era \
--tx-in $CONTRACT_TXIN \
--tx-in-script-file $TREASURY_PLUTUS_SCRIPT \
--tx-in-datum-value 123 \
--tx-in-redeemer-file $BOUNTY_DATUM \
--tx-in $TXIN1 \
--tx-in $TXIN2 \
--tx-in-collateral $COLLATERAL \
--tx-out $BOUNTY_ADDR+"2000000 + 1 $CONTRIBUTOR_ASSET + $BOUNTY_AMOUNT $BOUNTY_ASSET" \
--tx-out-datum-embed-file $BOUNTY_DATUM \
--tx-out $TREASURY_ADDR+"2000000 + $TOKENS_BACK_TO_TREASURY $BOUNTY_ASSET" \
--tx-out-datum-hash 7cfec515f56d4413375aa9775f5de15ee60180861e9eaa954bcf9d015054857c \
--change-address $CONTRIBUTOR \
--protocol-params-file protocol.json \
--testnet-magic 1 \
--out-file commitment-tx.draft

You need to provide datum and redeemer that match the types your validator is expecting. Those funds cannot be unlocked now because the datum hash is for a value of a different type.
You're using datum value 123, which is of type Integer but your validator expects WithdrawalDatum. You're passing datum.json for your redeemer, that must be using correct schema for type StackingDetails.

i used datum hash of 123 for locking funds should I try a different datum with unlocking

is there no way to unlock a utxo that was instansiated with the wrong datum type?

There's currently no way to unlock utxo with a hash for the wrong datum type, same goes for the absence of hash.


text:
How to use a relay node as a wallet for faster transactions
So I have set a relay node up on a vps. Now I want to connect it to my wallets in order to send transactions faster. How do I do that? Thanks

It is a common myth inside the NFT community that a node sends transactions 'faster' than a wallet. Daedalus is a node itself so there is no difference between sending a TX via Daedalus and sending it via cardano cli wallet aside from a TON more manual effort in the latter and the risk you'll overwrite and lose your payment keys and permanently lose access to your funds... That said, it seems as though you've bought into this myth, so very well.. here are the answers:
First, you'll want to become familiar with the cardano-cli wallet commands. They can be found here, https://input-output-hk.github.io/cardano-wallet/user-guide/cli
Specifically, you'll want to 'create a wallet from recovery phrase' to restore a wallet into your VPS and then you'll want to use the "cardano-cli transaction" command to send a TX to the NFT vendor.
Examples:
cardano-wallet wallet create from-recovery-phrase [--port=INT] <name> [--address-pool-gap=INT]

cardano-wallet transaction create [--port=INT] WALLET_ID [--metadata=JSON] [--ttl=SECONDS] --payment=PAYMENT...

He only asked how to connect a wallet not necessarily create a new one.
If you have an existing node running and fully in sync, you can use Nami to point to your node under settings - then submitting any tx goes through your node and not blockfrost.

If you don't want to create an HD wallet using the command line and just want to submit transactions to your custom node from existing wallets, check this link out on how to connect Nami/ CCVault (Eternl) to your own node.
HowTo

Before setting up your own cardano-node to use it as an submit-api endpoint, you might want to take a look at https://www.freeloaderz.io/.
This is a group of SPOs offering to the community submit-api endpoints that users can set in their wallets exactly for this purpose.


text:
cbor encode and decode
hope you all are doing great.
I am looking for a way to encode and decode the cborHex. I've done the following:
cardano-cli text-view decode-cbor --in-file wallet.vkey --out-file tx.alonzo

and I get the hex binary format but not a utf8 (human readable) format, how can this be done?
for reference, I've followed this question How to decode cbor which is generated with cardano-cli build command?

I use python cbor2 library or https://cbor.me. In the case of a wallet vkey, it's just a hex value that it'll decode as. Something like a transaction will have more data types embedded in the CBOR.