text:
How to create an unspent UTXO with specific value
I want to create a script (smart-contract) utxo with a specific number of tokens (it can be an output of a transaction before) in cardano-serialization-lib - javascript. I need this utxo to be part of a future output of a transaction. How can I do this?
-- Scenario to explain better --
Imagining a scenario where we have a smart contract feeded with 1000 tokens. Then, I want to send 30 tokens for a client (when he claims these tokens). If I want to have an UTXO with only these 30 tokens, I have to create an output before that transaction (for example, when the user locks an asset, the output for the smart contract will be the asset + 30 tokens), but these tokens are not an input from the client, is "from smart contract to smart contract".

You can follow this example on how to generate a transaction using Cardano Serialization Lib.
For your specific question, focus on the following section of the code that will help you create an output with the ada value you like:
// add output to the tx
txBuilder.add_output(
    CardanoWasm.TransactionOutput.new(
    shelleyOutputAddress,
    CardanoWasm.Value.new(CardanoWasm.BigNum.from_str('1000000'))
    ),
);

If you also like to add assets to that output, you can try this code:
  const outputAddress = CardanoWasm.Address.from_bech32(toAddress);

  var txOutputBuilder = CardanoWasm.TransactionOutputBuilder.new();
  txOutputBuilder = txOutputBuilder.with_address(outputAddress);
  var txOutputAmountBuilder = txOutputBuilder.next();

  const multiAsset = CardanoWasm.MultiAsset.new()

  const assets = CardanoWasm.Assets.new()
  assets.insert(
    CardanoWasm.AssetName.new(Buffer.from(assetName, "hex")), // Asset Name
    CardanoWasm.BigNum.from_str(amount) // How much to send
  );
  multiAsset.insert(
    CardanoWasm.ScriptHash.from_bytes(Buffer.from(policy, "hex")), // PolicyID
    assets
  );

  txOutputAmountBuilder = txOutputAmountBuilder.with_asset_and_min_required_coin(multiAsset, CardanoWasm.BigNum.from_str(params.data.genesis.alonzo.lovelacePerUTxOWord.toString()))
  const txOutput = txOutputAmountBuilder.build();

This second example is more in line with what is being used recently to create transactions and outputs in Cardano (TransactionOutputBuilder object).

Hey! Thanks for your answer. I was wondering if I explain well my question, because I already have this code. However, I want to create an output of a smart contract (a script) that will be an UTXO (without input provided), I mean, an output to the smart contract itself. Then, I can use this UTXO with this specific number of tokens to send to a client that is interacting with the smart contract.

I added a scenario on the question to be more easier to explain what I want

But... can't you just create the UTxO with the 30 tokens + the asset when the user "locks" that asset? That way, you will have generated a new UTxO with 30 tokens + 1 locked asset + some ada, in that same smart contract, for future use at some point in time.

BTW, you can't generate an output without an input since UTxOs are static: they only get spent by a trigger. The triggers are the inputs.

Yes Falcon, it is that I want (30 tokens + the asset + some ada). But this way I have to make some thing like: input -> 1000 tokens from smart contract ; output -> 30 tokens to smart contract ? but I have to spent the rest to the smart contract? how can I make this?

You don't have to spend the rest of the UTxO in the smart contract if you do that. You can just consume the UTxO with 1000 tokens and generate the one you need with 30 tokens (as I explained before). Then the remaining 970 tokens will be automatically sent to ANOTHER UTxO, in the same contract, as change for your transaction. Is this clear?

Yes @Falcon thanks. In the continuation of this question, I made a new one : https://cardano.stackexchange.com/q/8606/6611 if you can help me I will appreciate it.


text:
Cardano DB Sync as Service (running on background) on Ubuntu
Linux/Ubuntu - Cardano newbie, want to ask things around! :)
At the moment, I'm successfully installed cardano-node and can make it run as a service (pulling data automatically on the background), by following some of these instruction. I only follow some / few steps.
I tried to replicate it into cardano-db-sync version, so I can do cardano-db-sync automatically on the background. But, it gives some error / issue.
I already make, .sh and .service file.
Below is the code for, .sh file
#!/bin/bash
PGPASSFILE=/cardano/cardano-db-sync/config/pgpass-mainnet
CONFIG=/cardano/cardano-db-sync/config/mainnet-config.yaml
SOCKET_PATH=/cardano/db/node.socket
STATE_DIR=/cardano/cardano-db-sync/ledger-state/mainnet
SCHEMA_DIR=/cardano/cardano-db-sync/schema/
PGPASSFILE=${PGPASSFILE} cabal run cardano-db-sync -- --config ${CONFIG} --socket-path ${CARDANO_NODE_SOCKET_PATH} --state-dir ${STATE_DIR} --schema-dir ${SCHEMA_DIR}

And for .service file
# The Cardano DB Sync service (part of systemd)
# file: /etc/systemd/system/cardano-db-sync-run.service

[Unit]
Description     = Cardano DB Sync service
Wants           = network-online.target
After           = network-online.target

[Service]
User            = root
Type            = simple
WorkingDirectory= /cardano/cardano-db-sync
ExecStart       = /bin/bash -c '/cardano/cardano-db-sync-run.sh'
KillSignal=SIGINT
TimeoutStopSec=300
LimitNOFILE=32768
Restart=always
RestartSec=5
SyslogIdentifier=cardano-db-sync

[Install]
WantedBy        = multi-user.target

When I test to manually run /bin/bash -c '/cardano/cardano-db-sync-run.sh' it's working well and I can see some data get into database.
BUT, when I tried to run it as a service, it gives and error.
Here's what I did to make it run as a service
> sudo systemctl enable cardano-db-sync-run
> sudo systemctl start cardano-db-sync-run

And then, checking its log by
> journalctl --unit=cardano-db-sync-run --follow

And it shows an error - line 7: cabal: command not found.
I tried to see and one of my colleague advise me, to use full path of "cabal", since it isn't on /bin, so I change a bit .sh file to be
...
...

PGPASSFILE=${PGPASSFILE} /root/.ghcup/bin/cabal run cardano-db-sync -- --config ${CONFIG} --socket-path ${CARDANO_NODE_SOCKET_PATH} --state-dir ${STATE_DIR} --schema-dir ${SCHEMA_DIR}

Notice, that I change cabal into /root/.ghcup/bin/cabal. But, by doing so, it also gives an error message, as shown below
Feb 28 06:40:44 systemd[1]: Started Cardano DB Sync service.
Feb 28 06:40:44 cardano-db-sync[20548]: /cardano/cardano-db-sync
Feb 28 06:40:45 cardano-db-sync[20548]: Warning: Requested index-state 2021-07-02T00:00:00Z is newer than
Feb 28 06:40:45 cardano-db-sync[20548]: 'hackage.haskell.org'! Falling back to older state (2021-07-01T22:06:28Z).
Feb 28 06:40:45 cardano-db-sync[20548]: Resolving dependencies...
Feb 28 06:40:45 cardano-db-sync[20548]: cabal: Could not resolve dependencies:
Feb 28 06:40:45 cardano-db-sync[20548]: [__0] trying: Win32-network-0.1.0.0 (user goal)
Feb 28 06:40:45 cardano-db-sync[20548]: [__1] trying: base-4.9.1.0/installed-4.9.1.0 (dependency of Win32-network)
Feb 28 06:40:45 cardano-db-sync[20548]: [__2] next goal: base-deriving-via (user goal)
Feb 28 06:40:45 cardano-db-sync[20548]: [__2] rejecting: base-deriving-via-0.1.0.0 (conflict:
Feb 28 06:40:45 cardano-db-sync[20548]: base==4.9.1.0/installed-4.9.1.0, base-deriving-via => base>=4.14)
Feb 28 06:40:45 cardano-db-sync[20548]: [__2] fail (backjumping, conflict set: base, base-deriving-via)
Feb 28 06:40:45 cardano-db-sync[20548]: After searching the rest of the dependency tree exhaustively, these were the
Feb 28 06:40:45 cardano-db-sync[20548]: goals I've had most trouble fulfilling: base, Win32-network, base-deriving-via
Feb 28 06:40:45 systemd[1]: cardano-db-sync-run.service: Main process exited, code=exited, status=1/FAILURE
Feb 28 06:40:45 systemd[1]: cardano-db-sync-run.service: Failed with result 'exit-code'.

Again, I already try to run it manually, using /bin/bash -c '/cardano/cardano-db-sync-run.sh' and it works well, BUT, only when I make it run as a service, it shows that error.
My guess is that "cabal" isn't really recognized.
Any suggestion on why it failed?

PS --

I built cardano-node by follow this docs precisely. So, even the ghc --version and/or cabal --version is same
cardano-db-sync that I built is using Cabal (ghc stuffs), not using Nix / docker.

Thanks in advance!

*Edit #1 - after read the comments and replies from Eric de Castro Lopo and George - APEX Stake Pool, I got question
Do I need to wait this part to be done? So, I can make cardano-db-sync as a service?

PGPASSFILE=config/pgpass-mainnet cabal run cardano-db-sync --
--config config/mainnet-config.yaml
--socket-path ../cardano-node/state-node-mainnet/node.socket
--state-dir ledger-state/mainnet
--schema-dir schema/

*It's written on the docs

*Edit #2 - after checking more
Question from *Edit #1 - can be ignored, but for someone who looking for the answer, the answer is didn't need to. Detail can be seen on comment / replies by others.
Anyway, finally I can make it work as service. And as per guidance from Eric de Castro Lopo and George - APEX Stake Pool, seems I mistakenly put the syntax/command on .sh file as mentioned. Thanks!
In-case someone need, the workaround I did is to make a symlink of the executable file of cardano-db-sync

Do find . -name cardano-db-sync -executable -type f to find its location
Then, I did symlink (register cardano-db-sync) into /usr/local/bin (or wherever suitable for you), using sudo ln -s  ... (or other similar syntax / command).
And finally, on .sh file, I change this part ... cabal run cardano-db-sync -- ... into ... cardano-db-sync -- ...

Anyway, I will mark George - APEX Stake Pool's answer as it's the closest hint for me.
And, sorry Eric de Castro Lopo that I couldn't upvote your comment, as it's helpful too for me! Need +15 rep to upvote your comment :(
Thanks for your time! :)

As the main dev on cardano-db-sync I would recommend that you avoid building it every time you run it.
Build it once and then install it (will probably need to be manually, as root) and then it should all work (the reason it does currently work is that the service is running as root, and root does not have access to the cabal executable).

Hi @ErikdeCastroLopo - thanks for your explanation! Do you mind to explain a bit more about this sentences of yours "I would recommend that you avoid building it every time you run it" - I still not really understand, which part that "build" every time I run which? *sorry, I kinda lost on that part.

cabal build ... builds the executable. Every time you run that command the executable gets build.

Gotcha! Thanks for your kind explanation! :)

Why are you running cardano-db-sync with cabal? You should just run cardano-db-sync or cardano-db-sync-extended.
And another question, more important: why are you running the service as root? This is always a security issue. You should never run a service as root (unless really needed, which is not the case here) or as an user with sudo rights. And cardano-db-sync should be in /usr/local/bin, for example.
I'm posting here my service file and my shell script executed by the service:
# cat /etc/systemd/system/cardano-db-sync.service
# The Cardano db-sync service (part of systemd)
# file: /etc/systemd/system/cardano-db-sync.service

[Unit]
Description      = Cardano db-sync service
Wants            = network-online.target
After            = network-online.target

[Service]
User             = cardano
Type             = simple
WorkingDirectory = /home/cardano/cardano-node
ExecStart        = /bin/bash -c '/home/cardano/cardano-node/bin/db-sync.sh'
KillSignal       = SIGINT
TimeoutStopSec   = 120
LimitNOFILE      = 32768
Restart          = always
RestartSec       = 5

[Install]
WantedBy         = multi-user.target

# cat /home/cardano/cardano-node/bin/db-sync.sh
PGPASSFILE=/home/cardano/cardano-node/config/pgpass-mainnet cardano-db-sync-extended \
    +RTS -N -RTS \
    --config /home/cardano/cardano-node/config/mainnet-db-sync-config.json \
    --socket-path /home/cardano/cardano-node/db/node.socket \
    --state-dir /home/cardano/cardano-node/ledger-state/mainnet \
    --schema-dir /home/cardano/cardano-node/schema/

Hi! Thanks for your explanation and sample codes. It kinda gives me more explanation. About your question "Why are you running cardano-db-sync with cabal? You should just run cardano-db-sync or cardano-db-sync-extended - it seems I kinda misunderstood the documentation. And, because its last step, I kinda confuse on where can I found the "cardano-db-sync-exe", so, I follow the previous step where it says "... cabal run cardano-db-sync .... "

--continue-- About your concern, why I run it as root, it's because the server is a test server, and I still learn things around since I super newbie! Anyway, thanks a lot for that! really means a lot for me to learn! || And "And cardano-db-sync should be in /usr/local/bin" - I don't see that on that folder. I just follow their docs.

You are welcome. I am keeping all cardano-related binaries in /usr/local/bin, it's probably the best location for them.

ohh! I see! I thought it supposed to be there after installation. Thanks for your tips!

source: Stack Exchange

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

sort: votes


text:
setting postgresql for db-sync
I have followed the instructions bo build both the cardano-node and cardano-db-sync in the same folder.
I managed to fully sync the node, which is running when attempting to use dbsync.
When I try to follow the instructions to launch db-sync
PGPASSFILE=config/pgpass-mainnet cabal run cardano-db-sync -- \
    --config config/mainnet-config.yaml \
    --socket-path ../cardano-node/state-node-mainnet/node.socket \
    --state-dir ledger-state/
    --schema-dir schema/

I get the following error
[db-sync-node.Subscription:Error:51] [2022-03-09 21:22:29.03 UTC] Identity Connection Attempt Exception, destination LocalAddress "../cardano-node/state-node-mainnet/node.socket" exception: Network.Socket.connect: <socket: 22>: does not exist (Connection refused)
[db-sync-node.ErrorPolicy:Warning:6] [2022-03-09 21:22:29.03 UTC] IP LocalAddress "../cardano-node/state-node-mainnet/node.socket" ErrorPolicySuspendPeer (Just (ConnectionExceptionTrace Network.Socket.connect: <socket: 22>: does not exist (Connection refused))) 20s 20s

When I copy the lines from the postgresql setup command that seems to answer my issue:
~/cardano/cardano-db-sync$ PGPASSFILE=config/pgpass-mainnet scripts/postgresql-setup.sh --createdb

this error message is more telling
psql: error: connection to server on socket "/var/run/postgresql/.s.PGSQL.5432" failed: FATAL:  database "cexplorer" does not exist

I must admit I installed postgresql via sudo apt-get install and I don't know how to proceed properly from there. Do I have to set up a new datbase called cexplorer? should I create a new user for postgresql? for linux? should I edit permissions (i get a permission 600?
After running PGPASSFILE=config/pgpass-mainnet psql cexplorer i got the following error
WARNING: password file "config/pgpass-mainnet" has group or world access; permissions should be u=rw (0600) or less
psql: error: connection to server on socket "/var/run/postgresql/.s.PGSQL.5432" failed: FATAL:  database "cexplorer" does not exist

The documentation is so comprehensive and well done!, I don't understand why this very specific part is not in it (or I am not able to jauge my own incompetence;) )

edit: removed "mainnet" from the db-sync call parameters. Failing to find the .sql file from the restored snapshot lead the psql database to revert to  genesis. --state-dir ledger-state/mainnet(wrong)

should I edit permissions (i get a permission 600?

Yes, you need to reduce the permission down to 600. In addition you might also want to look at few things from a default Postgres deployment (authentication, contents of your private file, [unrelated to this issue - tuning], etc.)
Also, a sample of instructions going through above for setup of Postgrest itself can be found here - ensure you update the folder structure as per your environment, and steps post setup of Postgres instance and building cardano-db-sync here.

Seems like there was two missing parts:
First, add a new user to postgres:
(from https://cardano-community.github.io/guild-operators)
echo $(whoami)
# <user>
sudo su postgres
psql

CREATE ROLE <user> SUPERUSER LOGIN;
ALTER USER <user> PASSWORD 'PasswordYouWant';
\q

Not sure where to specify the password, so I used my account password (yikes!)
Second, create the database
with the db-sync provided script (dbsync)
cd cardano-db-sync
scripts/postgresql-setup.sh --createdb

Third, define the communication socket
My db-sync parameters points to a socket, but cardano-node doesn't seem to open the socket by default.
I added a the socket to the parameters when launching the node as follow:
cd cardano-node
cardano-node run --socket-path ./state-node-mainnet/node.socket

Then launched db-sync with the same exact parameters (other terminal)
cd cardano-db-sync
PGPASSFILE=config/pgpass-mainnet cabal run cardano-db-sync -- \
    --config config/mainnet-config.yaml \
    --socket-path ../cardano-node/state-node-mainnet/node.socket \
    --state-dir ledger-state/mainnet \
    --schema-dir schema/

note that both socket-path points to the same path
it works !
After a few minutes of verification and syncing the node created the socket!
Thanks for all your very helpful answers.
My next steps will obviously be security and tweaking.

I recently set up everything and it works, but I used nix and not cabal as I assume from your PGPASSFILE command that you used.
Regarding the permissions, no, you do not need to do it, I had the same error and it doesn't affect anything. You can do it if you want to be sure.
Your last error regarding the socket is also perfectly normal. The database cexplorer gets created automatically for mainnet the moment you start DB sync and since you are not at that point yet you get this error. After DB sync has started you can use
psql cexplorer

and access the database (have in mind the command psql is followed by a database name, if none is given, the name postgres is the default and a postgres database already exists).
It says about the socket being down anyway, but also make sure to have the socket online by using
pg_lsclusters
pg_ctlcluster <Ver. number(1st column)> main start

If your socket 5432 is down, that might also explain the initial errors you get.

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


text:
Issues running Chain-index on WSL2 - fully syncing but not running the webserver
I've run into an issue with the chain-index while trying to run a PAB testnet environment. The index will start up, sync to 100%, update to new blocks, but the webserver will never start. In fact, the port that the chain-index is supposed to occupy remains empty throughout this process. Commmands like curl -s localhost:9083/tip | jq '.tipSlot.getSlot' return nothing.
After some debugging, I isolated this piece of code - this is the last piece of code that runs after starting the chain-index server:
withAsync (runLogEffects (convertLog PrettyObject trace) $ logProgress chan) wait

It seems to log the output of the chain-index's progress, but I'm not sure. I believe it's responsible for outputs like this on the console:
[chain-index:Info:39] [2022-03-06 10:13:17.47 UTC] Still in sync. Applied 13 blocks, 0 rollbacks in the last 300s. Current tip is Point(Slot 52192355, BlockId 1893367e3a8139b6866e4c6e81bb1d2ecfa80660b1b027785f05d3e309a2d6d6)
That was a real output from my chain-index server - and proof that it's updating to the current testnet slot (at the time of this post).
This is the full block of code with the problematic line:
runMain :: CM.Configuration -> Config.ChainIndexConfig -> IO ()
runMain logConfig config = do
  withRunRequirements logConfig config $ \runReq -> do

    putStr "\nThe tip of the local node: "
    slotNo <- getTipSlot config
    print slotNo

    -- Channel for broadcasting 'ChainSyncEvent's
    chan <- newBroadcastTChanIO
    syncHandler
      <- defaultChainSyncHandler runReq
        & storeFromBlockNo (fromCardanoBlockNo $ Config.cicStoreFrom config)
        & writeChainSyncEventToChan convertEventToSyncStats chan

    putStrLn $ "Connecting to the node using socket: " <> Config.cicSocketPath config
    syncChainIndex config runReq syncHandler

    putStrLn $ "Connected to node socket."

    (trace :: Trace IO (PrettyObject SyncLog), _) <- setupTrace_ logConfig "chain-index"
    putStrLn $ "Trace completed." -- Added
    withAsync (runLogEffects (convertLog PrettyObject trace) $ logProgress chan) wait
    putStrLn $ "Async completed." -- Added

    let port = show (Config.cicPort config)
    putStrLn $ "Starting webserver on port " <> port
    putStrLn $ "A Swagger UI for the endpoints are available at "
            <> "http://localhost:" <> port <> "/swagger/swagger-ui"
    Server.serveChainIndexQueryServer (Config.cicPort config) runReq

I have two theories, but otherwise don't really know where to go from here.

There are some issues with running an Async function in WSL2 (unlikely as I see Async functions in other, working Plutus apps)
The database is corrupted somehow, and the line of code shown above is parsing through it in an attempt to fix it. I've tried rebuilding the database three times (using different commits on Github) to no avail.

Node version:
cardano-node 1.33.0 - linux-x86_64 - ghc-8.10
git rev 814df2c146f5d56f8c35a681fe75e85b905aed5d


text:
in plutus-pioneer-program iteration 3 not able to use --required-signer-hash in grab.sh so causing beneficiary's signature missing error (if remove)
Invalid option `--required-signer-hash'
Usage: cardano-cli transaction build
[ --byron-era
| --shelley-era
| --allegra-era
| --mary-era
| --alonzo-era
]
[ --shelley-mode
| --byron-mode [--epoch-slots NATURAL]
| --cardano-mode [--epoch-slots NATURAL]
]
(--mainnet | --testnet-magic NATURAL)
[--script-valid | --script-invalid]
[--witness-override WORD]
(--tx-in TX-IN
[--tx-in-script-file FILE
[(--tx-in-datum-file FILE | --tx-in-datum-value JSON VALUE)
( --tx-in-redeemer-file FILE
| --tx-in-redeemer-value JSON VALUE
)]])
[--required-signer FILE]
[--tx-in-collateral TX-IN]
[--tx-out ADDRESS VALUE
[ --tx-out-datum-hash HASH
| --tx-out-datum-hash-file FILE
| --tx-out-datum-hash-value JSON VALUE
| --tx-out-datum-embed-file FILE
| --tx-out-datum-embed-value JSON VALUE
]]
--change-address ADDRESS
[--mint VALUE
(--mint-script-file FILE
[--mint-redeemer-file FILE | --mint-redeemer-value JSON VALUE])]
[--invalid-before SLOT]
[--invalid-hereafter SLOT]
[--certificate-file CERTIFICATEFILE
[--certificate-script-file FILE
[ --certificate-redeemer-file FILE
| --certificate-redeemer-value JSON VALUE
]]]
[--withdrawal WITHDRAWAL
[--withdrawal-script-file FILE
[ --withdrawal-redeemer-file FILE
| --withdrawal-redeemer-value JSON VALUE
]]]
[--json-metadata-no-schema | --json-metadata-detailed-schema]
[--auxiliary-script-file FILE]
[--metadata-json-file FILE | --metadata-cbor-file FILE]
[--genesis FILE | --protocol-params-file FILE]
[--update-proposal-file FILE]
--out-file FILE
Build a balanced transaction (automatically calculates fees)
Please note the order of some cmd options is crucial. If used incorrectly may produce undesired tx body. See nested [] notation above for details.
Command failed: transaction sign  Error: tx.body: tx.body: openBinaryFile: does not exist (No such file or directory)
Command failed: transaction submit  Error: tx.signed: tx.signed: openBinaryFile: does not exist (No such file or directory)
grab.sh file
cardano-cli transaction build
--alonzo-era
--testnet-magic 1097911063
--change-address $(cat 02.addr)
--tx-in a6890c2f1bbcbff5dccbd1dfeb1725af1214757c3bbdc7a4b8dcea0228ba9d18#1
--tx-in-script-file vesting.plutus
--tx-in-datum-file unit.json
--tx-in-redeemer-file unit.json
--tx-in-collateral 7691a7e471f0842deb09da58ae4d4d3c4f59e52aa3bd1eabdaadd6b940714edd#1
--required-signer-hash edb335fdf7b7024f3ce25e556ba4cc9ea329561c16cf1a4b5353e463
--invalid-before 1646588049
--protocol-params-file protocol.json
--out-file tx.body
cardano-cli transaction sign
--tx-body-file tx.body
--signing-key-file 01.skey
--testnet-magic 1097911063
--out-file tx.signed
cardano-cli transaction submit
--testnet-magic 1097911063
--tx-file tx.signed
mkValidator :: VestingDatum -> () -> ScriptContext -> Bool

mkValidator dat () ctx = traceIfFalse "beneficiary's signature
missing" signedByBeneficiary &&
                        traceIfFalse "deadline not reached"
 deadlineReached
   where
 info :: TxInfo
 info = scriptContextTxInfo ctx

 signedByBeneficiary :: Bool
 signedByBeneficiary = txSignedBy info $ unPaymentPubKeyHash $
 beneficiary dat

 deadlineReached :: Bool
 deadlineReached = contains (from $ deadline dat) $
 txInfoValidRange info

so finally found the problem and solved it change --required-signer-hash with --required-signer 02.skey that will solve the problem

Please clarify your specific problem or provide additional details to highlight exactly what you need. As it's currently written, it's hard to tell exactly what you're asking.


text:
Disk Space of Cardano node & Cardano DB-sync
I recently installed the Cardano node and Db-sync and Postgres using nix. I use a server with 97 GB of space, node version 1.34.1 and DB-sync version 12.0. The node took about 70 GB after fully synced and DB-sync is still syncing on epoch 254. So far in total they have taken 88 GB of disk space.
My questions are:

Is this normal?
How much disk space is it expected to take when it is fully synced?
Does installing with cabal save up space? and how much?

Thank you for your answer!
Edit: For anyone interested, the cexplorer (i.e. mainnet) database at epoch 372 takes 221GB and the cardano-node folder 84GB (with nix installation).
The whole installation (node, db-sync, nix, Postgres) takes 338GB of storage.

As an FYI, the mainnet node DB/chain itself is currently using 41GB of disk on Linux.
$du -h db
38G     db/immutable
2.9G    db/ledger
163M    db/volatile
41G     db

Thanks for the info, but if I remember correctly the chain (up to epoch 324) took me about 60-70 GB. Definitely more than 41 GB. Can you tell me please where I can find the db folder?

I found the db folder, mine is named db-mainnet, and you are right. It is indeed 41gb and together with cardano-db-sync folder they are 44 gb. The Postgres cexplorer database is 15 gb. I am sorry for the possibly naïve question, I'm kinda new to cardano and Ubuntu, but where is the rest disk space taken from? Thanks again.

You can check disk usage with the Linux 'du' command eg 'du -h .' to get output of the current directory and sub-directories. You might have hidden directories too, so the command 'ls -la' will show you all directories, then you and do a 'du' on them eg 'du -h dir1'. If building from source then cabal and nix take up a lot of space.

Thanks for the follow-up! I just checked and although the node + db-sync + postgres take up 59 GB, nix alone takes 29 GB! That is extreme. Do you know if it safe to remove nix or will everything collapse? I think I will also make a new post about it.

Yeah probably best to accept an answer on this one and open a new question with more details. In short though, it will depend on what you want to use that system for.

The database for db-sync at chain tip is over 100GB.

Syncing on epoch 254. So far in total they have taken 88 GB of disk space.

Yep and by the time you get to epoch 323 (current tip) the database will need more than 100GB.

Is this normal?

Yes

How much disk space is it expected to take when it is fully synced?

Currently about 100-120 GB.

Does installing with cabal save up space? and how much?

Might save you as much as 10GB.

Thank you for answering! So far I'm at 92 GB with DB-sync at epoch 261 and syncing really slowly.
When you talk about the space needed, you mean for both the node and DB-sync right?
Cabal is definitely not worth re-installing then.

If you are happy with that answer, please consider accepting and up voting it.

I cannot upvote yet because I'm new. Despite I appreciate your answer, I would appreciate helping more, since you even took the time to re-comment, instead of reputation begging.

What is the current storage consumption for DB-sync? There's no "extended" version anymore either, right?

Yes, I believe there is no "extended" anymore. My latest install was through snapshot though and the "extended" parameter was not needed. The "epoch" table was still created. I assume that's the general case and not snapshot specific.

The cardano-db-sync folder is currently at 29GB (epoch 372).

For Epoch 359, cnode at 82G and db sync is 216G (sudo du -hd 1 /var/lib/postgresql/12). Looking  at the comments above it makes sense that the DB is way larger, 2.6x in this case.


text:
What is the derivation path in a Cardano address?
It comes from CCVault.  I saw it in the 'Receive' tab.
You can specify a part of the address, or a derivation path like "m/1852'/1815'/0'/1/32", "1815 0 1 32" or "0 1 32".

...and what do the various numbers mean?

Cardano follows the BIP32-ed25519 standard for HD key derivation. Read more about it here.
In a nutshell, a virtually infinite number of public/private addresses/keys pairs can be derived from a single master key-pair, which itself is derived from an entropic secret (usually in the form of a 24-word mnemonic). Staking (and all other types of) keypairs on Cardano can, in principle, be generated from the same set of root keys, though this is not recommended unless you know how to manage private keys yourself.
Keys used in Cardano transactions are 5 derivations away from the master seed. Your "wallet" is the middle number x in that whole mess there.
m / 1852' / 1815' / x' / 0, 1, or 2 / n
where:

m is the mnemonic
1852 is the coin (ADA) ID#
1815 is an extra, unused path
x is the account/wallet index #
0/1 are wallet x's payment/change keys-paths, and 2 is it's staking key-path
n is the key #

Also, the ' symbol means hardened derivation is used, meaning the child keypairs will be able to make keypaths of their own. if hardened derivation is not useed, the child keys will be "infertile".
Many unique wallets with unique staking keys can be derived from the same master seeds. Unfortunately, most wallet software like Daedalus and or Yoroi don't do this by default. The good news is this can all be done manually using CLI tools!

great answer, thank you

The link has been moved, here's the latest working link: https://input-output-hk.github.io/adrestia/cardano-wallet/concepts/hierarchical-deterministic-wallets


text:
Can I access the epoch nonce from inside a Plutus script?
Is is possible to access the epoch nonce from your Plutus script, to use as a trusted source or randomness  ?
The only suggestion for on-chain randomness I have found, is using an RNG oracle. But the Chain already produces a random number during each epoch!
If I would like to create a Application that uses randomness infrequently, the epoch nonce is a much better candidate, since it has a much stronger source of trust than any oracle, at least the foreseeable future.
Is this possible with the current Plutus V2 implementation ?

I do not think there is a way to get the epoch nonce but I also think that in most cases, the epoch nonce is a good source of " trusted source of randomness".
Maybe explain a bit more thoroughly of what you are trying to achieve.

For example If I would like to make a grand Strategy game where the map gets generated and players get assigned spots based on a Random Number(seed), this would not have to happen often, just every time a game starts and the games can take months so no real reason to need an RNG oracle.
Or for a lottery that happens every 5 days. Epoch nonce is definitely the most trusted randomness to use for a fair draw of the winner.

Using the random-ness for a game is probably fine, but I would definitely not consider it a good source of random-ness for cryptography.

Why not for Cryptography ? Not for seed generation or anything like that(since it is obviously not private), but for a VRF scheme like Ourobors uses for the leadership schedule should be fine.

I am by no means a cryptography expert, but my understanding is that cryptography requires very high quality randomness, specifically, well beyond a single 64 bit nonce on a blockchain.


text:
Will Ouroboros Crypsinous be included in Ouroboros Omega?
Last year at the 2021 Cardano Summit, IOHK provided a YouTube video that overviews the Ouroboros family of protocols developed since 2016, the consensus enhancements and security features they provide, and how Ouroboros Omega will be the culmination of this research.
IOHK published a paper in 2019 on privacy-preserving proof of stake called Ouroboros Crypsinous. The aim of the research was to provide a formal treatment of how a private ledger (ie, private transactions and private balances) could be attained using zk-SNARKS in a proof-of-stake consensus mechanism. The research seems to be inspired by Zcash (then called Zerocash).
There hasn't really been any mention of progress or development of Ouroboros Crypsinous since. Does anyone know if this work will be included in Ouroboros Omega? If not, do you know the reason? Is there still regulatory uncertainty about the use of private ledgers in public blockchains?

There is currently no plan for IOG to implement Ouroboros Crypsinous
https://iohk-io.netlify.app/en/blog/posts/2022/06/03/from-classic-to-chronos-the-implementations-of-ouroboros-explained/


text:
Transaction submit error
Is there anything wrong with
cardano-cli transaction build-raw \
    --tx-in 2b67b1d3cbab8004f469a2a2f260738704810744350119d75079d7b6f4b1842a#0 \
    --tx-out $(cat payment2.addr)+100000000 \
    --tx-out $(cat payment.addr)+997320350 \
    --invalid-hereafter 53808126 \
    --fee 1679650 \
    --out-file tx.raw

because I'm getting
Command failed: transaction submit  Error: Error while submitting tx: ShelleyTxValidationError ShelleyBasedEraAlonzo (ApplyTxError [UtxowFailure (WrappedShelleyEraFailure (UtxoFailure (ValueNotConservedUTxO (Value 0 (fromList [])) (Value 20000000 (fromList []))))),UtxowFailure (WrappedShelleyEraFailure (UtxoFailure (BadInputsUTxO (fromList [TxInCompact (TxId {_unTxId = SafeHash "4e3a6e7fdcb0d0efa17bf79c13aed2b4cb9baf37fb1aa2e39553d5bd720c5c99"}) 4])))),UtxowFailure (WrappedShelleyEraFailure (UtxoFailure (FeeTooSmallUTxO (Coin 168273) (Coin 167965)))),UtxowFailure (WrappedShelleyEraFailure (UtxoFailure (OutsideValidityIntervalUTxO (ValidityInterval {invalidBefore = SNothing, invalidHereafter = SJust (SlotNo 369400)}) (SlotNo 53808413))))])

My math might be off. I have a billion test LoveLace in that address.
Update:
cardano-cli transaction build-raw \
    --tx-in 2b67b1d3cbab8004f469a2a2f260738704810744350119d75079d7b6f4b1842a#0 \
    --tx-out $(cat payment2.addr)+100000000 \
    --tx-out $(cat payment.addr)+899823103 \
    --invalid-hereafter 54208180 \
    --fee 176897 \
    --out-file tx.raw

still doesn't work:
Command failed: transaction submit  Error: Error while submitting tx: ShelleyTxValidationError ShelleyBasedEraAlonzo (ApplyTxError [UtxowFailure (WrappedShelleyEraFailure (UtxoFailure (FeeTooSmallUTxO (Coin 168273) (Coin 167965)))),UtxowFailure (WrappedShelleyEraFailure (UtxoFailure (OutsideValidityIntervalUTxO (ValidityInterval {invalidBefore = SNothing, invalidHereafter = SJust (SlotNo 53808126)}) (SlotNo 54205604))))])

The slot# error is because the transaction expired - the error indicates you submitted an expired transaction.
Use the higher fee as you did in the second tx, as well as a larger slot expiration. Set the --invalid-hereafter to 60000000 and let it rip!

Your trx has --fee 1679650
In the error it notes:

FeeTooSmallUTxO (Coin 168273) (Coin 167965))

Note (Coin 167965) is similar to the fee of 1679650. Could there be a typo somewhere?
Probably good to re-calc the fee amount.
Also, what is the balance of UTxO 2b67b1d3cbab8004f469a2a2f260738704810744350119d75079d7b6f4b1842a#0 ?
To match your trx outputs and fee it should be: 1,099,000,000
If you have 1billion exactly then change:
--tx-out $(cat payment.addr)+997320350 to
--tx-out $(cat payment.addr)+898320350 so that it balances.

I have 1000000000 lovelace + TxOutDatumNone.

Still doesn't work:
`cardano-cli transaction build-raw \
--tx-in 2b67b1d3cbab8004f469a2a2f260738704810744350119d75079d7b6f4b1842a#0 \
--tx-out $(cat payment2.addr)+100000000 \
--tx-out $(cat payment.addr)+898320350 \
--invalid-hereafter 53808126 \
--fee 167965 \
--out-file tx.raw`

It keeps mentioning 167965 even though I put the zero at the end.

Your comment notes a diff fee of '--fee 167965' - this then changes the amount for --tx-out but you did not update that value.  Your amounts have to balance eg --tx-in amount = (--tx-out amount + --tx-out amount + --fee amount) 2) Re-calculate the fee to ensure the correct amount to use eg 'cardano-cli transaction calculate-min-fee ....'
You need to also increase the '--invalid-hereafter' value to beyond the latest maximum testnet slot, check the latest value here https://explorer.cardano-testnet.iohkdev.io/en.html and add about 500 to it.

After doing the above can you then post the command used and error message received.

Refer to this guide to construct a simple trx:  https://developers.cardano.org/docs/stake-pool-course/handbook/create-simple-transaction/

Please check update.

First let's confirm that your local node is 100% synced. Try the command cardano-cli query tip --testnet-magic 1097911063 . Note the "syncProgress" value. Also note the 'slot' value and use that plus 10000 as your '--invalid-hereafter' value.

What CLI version are you using? Try cardano-cli --version . Also, try adding --alonzo-era if on the latest version.

The error still notes 'FeeTooSmallUTxO' - can you copy/paste to your question the full steps taken to calculate the fee. Too much detail is better than not enough.

Also, remove file tx.raw to ensure it gets re-created during your steps, and copy/paste in your 'submit' command too so we can see everything that is taking place, thanks.

I've been giving https://forum.cardano.org/t/how-to-set-up-a-pool-in-a-few-minutes-and-register-using-cntools/48767 a shot. Is there another way to get tAda outside the official faucet since it only lets you get some once a day?

How much tADA do you need for testing with?
If you need a heap of tADA you could ask on Cardano discord for tADA donations from people.


text:
No tAda after requesting from faucet
I'm following the docs and ran:
cardano-cli query utxo \
    --address $(cat payment.addr) \
    --testnet-magic 1097911063

and it shows my address but no tAda several minutes after requesting from this faucet. My testnet is synced and I'm doing this from Debian 11. It wasn't fully synced yet; that was the problem.

I just tried the faucet and received the 1,000 tADA after about 4 minutes.
You can check the testnet explorer for your initial attempt to see what it says: https://explorer.cardano-testnet.iohkdev.io/en
What is your test address, I'll send you the 1,000 tADA.
Edit (for others that end up on this page)
Ensure you are fully synced, check with:

cardano-cli query tip --testnet-magic 1097911063

addr_test1qzfdl3vkyjemg28jfnewsd4qldhemrnrl5np268dswzeaehavclrvqjk72kgfpfs567zpp2r9klu6hkhwynrgjdyr0lq2fpzgv

Explorer shows two transactions but still no balance locally. Not sure if I'm supposed to install the wallet or if just running the node and cli is enough.

Ok it sounds like a local sync issue. Can you run cardano-cli query tip --testnet-magic 1097911063 to see if you're local storage is fully synced.

Also, check your node log file for any issues/errors.

{     "era": "Alonzo",     "syncProgress": "91.73",     "hash": "40f26cdcfff0319d11f3eacb0fb7230fcbf5694afc85499188178229cf87264e",     "epoch": 178,     "slot": 46727389,     "block": 3202975 }
Guess I'm not fully synced yet though the stdout messages don't have any 'progress bars' or anything.

It's progressing but very slowly so I think something's off.

Ok, only 91% synced (syncProgress). Also use https://explorer.cardano-testnet.iohkdev.io/en.html to see the latest SLOT and BLOCK values, and compare to your values. Once synced you'll see your trxs and balance.

cardano-cli query tip --testnet-magic 1097911063

showed that it wasn't fully-synced yet.

I am tempted to delete this answer as it is more a hint than an explanation.  The guidelines in [answer] will help improve your answers.


text:
Cardano Core Node has high Tip Diff in gLiveView after upgrading node(s) to 1.34.1
After upgrading my nodes to 1.34.1, I noticed that the Tip Diff KPI in gLiveView began returning high 200+ results and the block propagation times increased by a couple seconds.  The relay nodes are running fine, no change in behavior.
In addition to the node upgrade, I did implement a firewall threat detection and blocking service called "SNORT" on my WAN.
I have attempted to reboot the nodes, but behavior remains.
Node version: 1.34.1
gLiveView version: 1.26
Overall, I feel that the relay and core nodes are operating fine but perhaps the issue is with gLiveView.
NOTE
The missed slot leader checks KPI did not change.  The value still show "favorable" data after upgrade just as it did before upgrade.
All help / information is very much appreciated.
Nick

This issue has been resolved by reinstalling gLiveView to the latest version.  No issues are caused by the SNORT service on my firewall.
Thank you, Nick


text:
cardano-cli transaction build script (NFT Contract Address Creation)
I am trying to send a market.plutus file to test a NFT marketplace to mainnet. I am building the transaction here like this:
cardano-cli transaction build
--alonzo-era --mainnet
--tx-in $UTxO-VARIABLE
--tx-out $CONTRACT-ADDR-VARIABLE+5400011
--tx-out-datum-hash 67882f9c671cb45fc6990a2d14a20b30bfce29ad99a401c283a100662e6600fb
--metadata-json-file
--change-address $MY-ADDR-VARIABLE
--out-file tx.build

Notice how the --metadata-json-file field is empty. It doesn't let me build it empty of course but I have no idea what goes here or what it should be.

'--metadata-json-file' wants a path to a JSON file eg --metadata-json-file metadata.json
This link shows an example of JSON metadata content, adapt and use as needed -
https://developers.cardano.org/docs/transaction-metadata/how-to-create-a-metadata-transaction-cli/
You can try leaving out this option, or provide the path to a file (that is either empty or that has minimum JSON data).
It's cheaper to experiment on the testnet, but I'm sure that you're aware of that.


text:
Cardano-graphql / Hasura - not found in type: 'query_root'
I found this github issue: https://github.com/input-output-hk/cardano-graphql/issues/507 discussing how to get assets of an address at a certain block using cardano-graphql / Hasura.
When I run the "SDL Version" of the query, as mentioned in the github issue, on the referenced page (https://graphql-api.mainnet.dandelion.link/), it works just fine.
When I try the same query on my cardano-graphql stack in Hasura, I get this error message:

field "paymentAddresses" not found in type: 'query_root'

I searched for similar errors, and it seems to have to do with permissions, but I can't figure out which permissions are missing.

Are you using the hasura console or the apollo graphql console?
That query won't be available through the hasura console since paymentAddresses is not a postgres table that hasura directly binds to. The apollo graphql server actually queries hasura, transforms the data and then returns it. You can see here that payment addresses calls the getPaymentAddressSummary function on the hasura client.

I just now realized the difference between the two consoles. Thanks. All works when entering it in the correct console.


text:
File 'blockfrost-mainnet.key' specified in the --blockfrost-token-file can't be read
I am running this command to run the Cardano light node using cardano-wallet cli
docker pull inputoutput/cardano-wallet:2022.4.27 serve --light --mainnet --blockfrost-token-file blockfrost-mainnet.key
The file blockfrost-mainnet.key contains the blockfrost project API key, when I execute the command I got the following error:
[cardano-wallet.main:Debug:4] [2022-04-28 14:20:55.15 UTC] ServeArgs {_hostPreference = Host "127.0.0.1", _mode = Light "blockfrost-mainnet.key", _listen = ListenOnPort 8090, _tlsConfig = Nothing, _networkConfiguration = MainnetConfig, _database = Nothing, _syncTolerance = SyncTolerance 300s, _enableShutdownHandler = False, _poolMetadataSourceOpt = Nothing, _tokenMetadataSourceOpt = Nothing, _logging = LoggingOptions {loggingMinSeverity = Debug, loggingTracers = Tracers {applicationTracer = Const (Just Info), apiServerTracer = Const (Just Info), tokenMetadataTracer = Const (Just Info), walletEngineTracer = Const (Just Info), walletDbTracer = Const (Just Info), poolsEngineTracer = Const (Just Info), poolsDbTracer = Const (Just Info), ntpClientTracer = Const (Just Info), networkTracer = Const (Just Info)}, loggingTracersDoc = Nothing}}
[cardano-wallet.main:Error:4] [2022-04-28 14:20:55.15 UTC] File 'blockfrost-mainnet.key' specified in the --blockfrost-token-file can't be read.
[cardano-wallet.main:Debug:4] [2022-04-28 14:20:55.15 UTC] Logging shutdown.```

Are the read permissions for the blockfrost-mainnet.key set appropriately?

i found the way i am not sure how its possible but using cardano-wallet binaries or installation works for me instead of using docker image.

Your probably did not mount your blockfrost-mainnet.key and therefore it is not accessible within the Docker container.
Check the docker documentation about bind mounts.


text:
How does db-sync query raw block data if cardano-node doesn't expose them?
I was trying to find a way to get raw block/transaction data and came across this question. The answer was that there is no way to do that currently but db-sync somehow does that. How does it do that? More specifically I was looking for some sort of documentation on how to do that myself (an API reference with the protocol specified).

The answer to that other question is only partly correct ie the node does make this data available, but not in an easy to digest manner.
The node does expose a local chain sync protocol. However this local chain sync protocol is written in Haskell and uses CBOR encoded data. It is theoretically possible to write code in another language that connects to this local chain sync protocol (I think there is Rust code somewhere to do this).
The local chain sync protocol only supports on-chain data. Data that is part of ledger state like epoch rewards and epoch stake distribution are not included.

Looking more into the chain-sync protocol, ogmios wraps it in a websocket API, so I think that's exactly what I am looking for, thanks!


text:
How to get TransactionUnspentOutput as a hex encoded bytes string programmatically
So basically I want to convert a normal UTxO hash like:
550665309dee7e2f64d13f999297f001763f65fe50bb05524afc0990c7dce0c3
to a TransactionUnspentOutput as a hex encoded bytes string like:
828258205537396d59c1b0546bb9cec5cb6b930238af2d8998d24ca1d47e89a3dd400a8701825839016af9a0d2c9b5bce8999bc6430eb48f424399b73f0ecc143f40e8cac89b130cc3198a8594862fe25df331cb79447304dcd49712c86834fdf1821a00150bd0a1581cb0df0ee7dbb96b18b682a1091514f250eb0ec1122e6c4bf3b4d45123a14b436f6e766963743033363701
This is how it is done with a nami wallet implementation:
cardano.getUtxos(amount?: Value, paginate?: {page: number, limit: number}) : [TransactionUnspentOutput]
I tried to pass a UTxO into the lucid utxoToCore() function:
export const utxoToCore = (utxo: UTxO): Core.TransactionUnspentOutput => {
  const output = C.TransactionOutput.new(
    C.Address.from_bech32(utxo.address),
    assetsToValue(utxo.assets)
  );
  if (utxo.datumHash) {
    output.set_datum(
      C.Datum.new_data_hash(C.DataHash.from_bytes(fromHex(utxo.datumHash)))
    );
  }
  return C.TransactionUnspentOutput.new(
    C.TransactionInput.new(
      C.TransactionHash.from_bytes(fromHex(utxo.txHash)),
      C.BigNum.from_str(utxo.outputIndex.toString())
    ),
    output
  );
};

However the only output I get is: TransactionUnspentOutput { ptr: 1247376 }
How to get the unpacked (?), or at least the right format I want,  TransactionUnspentOutput?

Fixed it with this code:
Buffer.from(utxoToCore(data).to_bytes()).toString("hex")
Data example:
  txHash: "5537396d59c1b0546bb9cec5cb6b930238af2d8998d24ca1d47e89a3dd400a87",
  outputIndex: 0,
  assets: { lovelace: 5000000 },
  address:
    "addr1q940ngxjex6me6yen0ryxr453apy8xdh8u8vc9plgr5v4jymzvxvxxv2sk2gvtlzthenrjmeg3esfhx5jufvs6p5lhcsak86ux",
};```


text:
Metadata transactions / eUTOX TTL / locking up ADA
I'm following this guide on metadata transactions with the cardano wallet server. My goal is to prove the existence of a given IPFS hash at a certain point in time. I don't need to send or receive ADA from anyone so as the guide mentions I'm sending 1,000,000 lovelace to myself. I have these two transactions (one & two) on testnet that have been in a pending state for >1 hour.
The first transaction shows ~900 ADA coming from one of my addrs and then 1 ADA going to my address that I specified and then the remainder going to another addr in my wallet. The second transaction is similar but has 3 inputs and 2 outputs.
I'm trying to understand how the eUTXO model works in this situation, I understand that I'm getting all of the ADA back but while these transactions are pending I apparently can't spend anything because I tried a third transaction but it failed saying I don't the 1 ADA required. After some more research I see that I should've specified a TTL so that it doesn't take forever but I have a few questions about how I should I approach this.

Why is the lockup inconsistent? I only need 1 ADA + fee, so why did the first transaction lock up 900 ADA and then the second locked up the remaining ~90? If it is ok with 90 is it possible to specify a smaller number?

What's with the hour long pending state? I have over 150 confirmations, is this due to congestion on testnet? Any suggestions on a TTL for this type of transaction?

The wallet provides several addresses for privacy but in this application design I don't want privacy, the intention is to make the metadata public so it really shouldn't matter what address I use as long as its consistent right? Is there a typical method for selecting an address for public transparancy or just pick the first one?

EDIT
Just a moment ago I realized my local node was showing it was 99.8% synced and I just sent another transaction that updated to in_ledger status really quickly so I'm guessing the sync was why I was seeing the pending status for so long on my local node but I'm still interested in questions 1 & 3 above.

Seeing as you've solved the mystery around the pending state transactions I will try my best to answer questions 1 and 3.
Question 1: Inconsistent Lockup of UTXOs
Wallets use CIP 2 - Coin Selection Algorithms for Cardano to decide which UTxOs to consume.

There are two main algorithms used by Cardano Wallet:

Largest-First
Random-Improve

In general, Cardano Wallet gives priority to the Random-Improve algorithm, as experimental evidence shows that it
performs better at minimising dust and maintaining a UTxO set with
useful outputs. (See Self Organisation in Coin Selection for more
details.)
However, in rare cases, the Random-Improve algorithm may fail to produce a result. In such cases, Cardano Wallet will fall back to the Largest-First algorithm.

Looking into the transaction history here I can see that the wallet had a limited set of UTxOs to work with, one output with 900 ADA, one with 90 ADA and single ADA outputs here and there. In this case it looks like the random-improve algorithm selected the 900 ADA UTxO first.
Given this knowledge, it does make sense to have multiple evenly distributed UTxOs available for your wallet if you need multiple concurrent transactions between blocks. Wallets like Eternl do this with their "Advanced UTxO Management" feature.
Question 3: Addresses to Use if Privacy isn't needed
Yes it doesn't matter which address you use, as the wallet will always have full control to spend UTxOs across its previously derived addresses. For example wallets like Nami always use the first derived address. It is also worthwhile mentioning that there is no privacy between transactions if all your derived addresses use the same staking key, which is the case for most wallets today. An thread from reddit highlights this.

Great, thanks for the info! When my node is synced the transactions settle in ~30 sec so it won't be an issue but just for my understanding; I think I get why the cardano-wallet has the utxo distribution endpoint now. I'm currently using a high level API that simplifies transaction building but if I wanted more control I could use a lower level client and use one of the algorithms you mentioned or implement my own utxo selection method? It doesn't really matter when transactions are expected to settle in a short period but for certain smart contract durations it might end up being important.

Yeah for ultimate flexibility there are already quite a few options around lower level SDKs or clients depending on the tech stack you are using. I personally find cardano-wallet to be a tad heavy-weight and opinionated so I use cardano-cli for ad-hoc transactions and CardanoSharp with my C# code.


text:
Can't compile Plutus Playground examples: Could not find module `Playground.Contract' (Ubuntu 20.04)
I can't compile any of the example scripts using Plutus Playground gui:
Compilation Error, Line 2, Column 1 (jump)
 error:
    Could not find module `Playground.Contract'
    Use -v (or `:set -v` in ghci) to see a list of the files searched for.
  |
2 | import Playground.Contract
  | ^^^^^^^^^^^^^^^^^^^^^^^^^^
Compilation Error, Line 3, Column 1 (jump)
 error:
    Could not find module `Plutus.Contract'
    Use -v (or `:set -v` in ghci) to see a list of the files searched for.
  |
3 | import Plutus.Contract
  | ^^^^^^^^^^^^^^^^^^^^^^
Compilation Error, Line 4, Column 1 (jump)
 error:
    Could not find module `PlutusTx.Prelude'
    Use -v (or `:set -v` in ghci) to see a list of the files searched for.
  |
4 | import PlutusTx.Prelude
  | ^^^^^^^^^^^^^^^^^^^^^^^

Looks like all non-standard modules are considered missing (screenshot from playground gui after hitting "Compile").

I'm using Ubuntu 20.04. Here's what I did:

Installed nix using sh <(curl -L https://nixos.org/nix/install) --daemon (multi-user installation)
Cloned plutus-apps (latest, currently: dd1678bba97e489dc54f2384a7be81e32659ba76)
Ran nix-shell in plutus-apps dir.
Started playground server inside the nix shell using

$(nix-build -A plutus-playground.server)/bin/plutus-playground-server webserver

and client:
npm start

At this point gui was running ok, but I was getting errors while trying to compile examples:
ConnectionError (HttpExceptionRequest Request { host = "localhost" port = 8009 secure = False requestHeaders = [("Accept","application/json;charset=utf-8,application/json"),("Content-Type","application/json;charset=utf-8")] path = "/runghc" queryString = "" method = "POST" proxy = Nothing rawBody = False redirectCount = 10 responseTimeout = ResponseTimeoutDefault requestVersion = HTTP/1.1 proxySecureMode = ProxySecureWithConnect } NoResponseDataReceived)

After some googling/debugging I came up with a solution to connection errors - running the server with:

WEBGHC_URL=http://localhost:8081  $(nix-build -A plutus-playground.server)/bin/plutus-playground-server webserver -p 8081

and changing client configuration in webpack.config.js:
    devServer: {
        contentBase: path.join(__dirname, "dist"),
        compress: true,
        port: 8009,
        https: false, // changed from true due to CA errors
        stats: "errors-warnings",
        proxy: {
            "/api": {
                target: "http://localhost:8081", // port changed from 8080
            },
        },
    },

After these changes playground at least tries to compile the scripts, but it looks like webghc doesn't see plutus packages.
As I mentioned I'm using Ubuntu 20.04 and ghcup with following tool versions:
✔✔ ghc   8.10.7   recommended,base-4.14.3.0 hls-powered
✔✔ cabal 3.6.2.0  latest,recommended
✔✔ hls   1.6.1.0  latest,recommended
✔✔ stack 2.7.5    latest,recommended
✔✔ ghcup 0.1.17.6 latest,recommended

My nix.conf:
» cat /etc/nix/nix.conf

build-users-group = nixbld
substituters        = https://hydra.iohk.io https://iohk.cachix.org https://cache.nixos.org/
trusted-public-keys = hydra.iohk.io:f/Ea+s+dFdN+3Y/G+FDgSq+a5NEWhJGzdjvKNGv0/EQ= iohk.cachix.org-1:DpRUyj7h7V830dp/i6Nti+NEO2/nhblbov/8MW7Rqoo= cache.nixos.org-1:6NCHdD59X431o0gWypbMrAURkbJ16ZPMQFGspcDShjY=
experimental-features = nix-command flakes

Does anyone know what I'm missing? Please halp :)
EDIT:
Output of nix-shell command:
» nix-shell                                                                                130 ↵
trace: To materialize project.plan-nix for cabal-install entirely, pass a writable path as the `materialized` argument and run the 'updateMaterialized' script in 'passthru'.
trace: WARNING: 8.10.5 is out of date, consider using 8.10.7.
trace: haskell-nix.haskellLib.cleanGit: /nix/store/dgp5f75dgadnxvy1mybjky2hm7wyxnpl-cardano-node does not seem to be a git repository,
assuming it is a clean checkout.
trace: To make project.plan-nix for cardano-node a fixed-output derivation but not materialized, set `plan-sha256` to the output of the 'calculateMaterializedSha' script in 'passthru'.
trace: To materialize project.plan-nix for cardano-node entirely, pass a writable path as the `materialized` argument and run the 'updateMaterialized' script in 'passthru'.
trace: WARNING: 8.10.5 is out of date, consider using 8.10.7.
trace: To make project.plan-nix for cardano-node a fixed-output derivation but not materialized, set `plan-sha256` to the output of the 'calculateMaterializedSha' script in 'passthru'.
trace: To materialize project.plan-nix for cardano-node entirely, pass a writable path as the `materialized` argument and run the 'updateMaterialized' script in 'passthru'.
trace: To make project.plan-nix for haskell-project a fixed-output derivation but not materialized, set `plan-sha256` to the output of the 'calculateMaterializedSha' script in 'passthru'.
trace: To materialize project.plan-nix for haskell-project entirely, pass a writable path as the `materialized` argument and run the 'updateMaterialized' script in 'passthru'.
trace: To materialize project.plan-nix for haskell-project entirely, pass a writable path as the `materialized` argument and run the 'updateMaterialized' script in 'passthru'.
trace: To materialize project.plan-nix for haskell-project entirely, pass a writable path as the `materialized` argument and run the 'updateMaterialized' script in 'passthru'.
nix-pre-commit-hooks: hooks up to date
pid 1234077's current affinity list: 0-15
pid 1234077's new affinity list: 0-15

Does your plutus-app checked out commit (dd1678bba97e489dc54f2384a7be81e32659ba76) match your cabal project file dependency declaration of plutus-apps (see tag of repo)?

Did you logout and login after installing nix? Your reachable paths where software might needs to be updated after install. If this is the case, just purge the plutus-app directory and git clone it again. Also check when you enter your nix-shell stuff is being pulled from somy hydra.iohk server.

@William-BerlinPool I'm just trying to get the playground working without any other external projects. (not using plutus-pioneer-program repo atm)

@Fermat I did log out / log in after installing nix. Running nix-shell (for the first time) downloaded lots of deps from cache. I've pasted output of subsequent runs in the main post. I also tried to run playground using Ubuntu 20.04 on Windows WSL2 with the same result.

If you would like we can debug it together on the IOHK dev discord channel collaborate room? Just post a message there and Ill contact you :)

@Fermat I'd love to, but I'm not on that discord. Can you send me a link?

https://discord.gg/m8pHXMDu is the IOG technical community discord server.

@Fermat posted in #pioneers-questions

It turned out that I was starting the playground server wrong - I was trying to use nix-build inside a nix shell.
What actually works (without any code modifications):

server:

> nix-shell
> cd plutus-playground-server/
> plutus-playground-server

client:

> nix-shell
> cd plutus-playground-client/
> npm start

I also added allow-import-from-derivation = true to my nix.conf (as
cardano-node docs suggest).
My nix.conf is now:
substituters        = https://hydra.iohk.io https://iohk.cachix.org https://cache.nixos.org/
trusted-public-keys = hydra.iohk.io:f/Ea+s+dFdN+3Y/G+FDgSq+a5NEWhJGzdjvKNGv0/EQ= iohk.cachix.org-1:DpRUyj7h7V830dp/i6Nti+NEO2/nhblbov/8MW7Rqoo= cache.nixos.org-1:6NCHdD59X431o0gWypbMrAURkbJ16ZPMQFGspcDShjY=
experimental-features = nix-command flakes
allow-import-from-derivation = true

Thank you @Fermat for your help :)


text:
What does it mean when a block with 0 transactions is appended to the blockchain?
E.g. this block has 0 transactions
Is there any technical/ strategic reason for appending such a block to the blockchain?
To make my question more explicit: Why is the block created despite there is no transaction?

In order to understand this you have to understand how mining works and this is generally applicable to all blockchains. With mining there are two main types, PoW (proof of work) and PoS (proof of stake).
Regardless of the method employed miners compete to solve blocks. In the case of PoS miners stake funds and one is selected to solve or "mine" a block based on their stake. With PoW miners compete based on finding the lowest hash value below a certain threshold.
In both cases however miners get rewarded for solving a block. They usually get a portion or all of the transaction fees for the transactions included in that block so will include as many as they can or the highest paying ones but there is also usually a reward for solving the block so miners will try to solve it even if there are no transactions.
With solo mining a miner will get all of the block reward and eligible transaction fees for solving it. In the case of pooled mining miners get rewarded a portion of rewards based on their submitted shares out of all shares after a block is solved. But in both cases there's competition for solving blocks so miners will include empty blocks if no transactions are present.

But why would the cardano system want to choose a staking pool to validate a block when there is no transactions to validate to begin with? Wouldn't it be wasting rewards (from the point of view of the cardano system)?

@Aqqqq That's not really how it works. With any decentralised system there's a consensus mechanism. With PoW this relies on miners submitting blocks as they are mined and if 50% of validators accept a block as valid it gets added to the chain. With PoS this is still the same except it's interval based. So it's not so much choosing but based on rules and there's no rule that a block can't be empty. There may also be reasons that allowing empty blocks encourages contributors making the system more secure. Unless you move to a fee based system only where there's no incentive to mine empty blocks.

Thank you for your answer. Can you give me a source that cardano's PoS is interval based?

The Cardano protocol is set to try and produce blocks every 20 seconds on average
https://developers.cardano.org/docs/stake-pool-course/introduction-to-cardano/

This just means that no transactions happened between the previous block (5387367 at 02/25/2021 5:54:30 PM) and the actual block (5387367 at 02/25/2021 5:54:31 PM).
This behaviour does not affect rewards either: transaction fees are combined together at the end of the epoch and added to the amount of reserves that are being split among the stake pools. This way, it doesn't matter how many transactions a block has in it from a consensus protocol perspective.

But why is the block created despite there is no transaction?

I think this has to do with the fact that the cardano PoS consensus protocol is timed based. Each slot has a fixed schedule and slot leaders can propose their blocks at these slots. Now why slots? Since their is no race in PoS their needs to be a schedule at which block need to be published. The who gets the right of these slots is done via VRF (see https://vincenthz.github.io/ouroboros-vrf-explanation/)

I was just asked to review an answer to this question and thought a different viewpoint might be beneficial to new devs.
I'm sure that you will have heard of the block size wars at some point. This was an event in which the bitcoin community was divided into two camps to keep the same block size or increase it. The key point here is that in the bitcoin protocol blocks have a consent frequency at which they are made. If you multiply this frequency by the number of transactions in a block you get how many transactions a blockchain can process. The problem is that if each transaction takes up some space in a block and blocks have limited space in them meaning there's a cap on transactions. Increasing block size would up that limit.
Now Ethereum has a different approach in which the frequency of blocks is set but the size of blocks is variable (higher usage means bigger blocks). In Cardano we have a different approach in which we have slots and can put the blocks into the slots. Now it's possible to have empty slots i.e. slots with no blocks.
If you understand all that then its should be clear that always having empty blocks appended to the network would prevent transactions from happening and make the chain come to a halt. So it can be considered as an attack on the network.
There is another thing that would tell you why some actors are incentives to make blocks with no transactions in them. That is that in some networks miners are asked to make temporary blocks from the mempool which would be added to the chain if the node making the block wins the right to do so. All temp blocks by the nodes that did not win are discarded.
Now you should be able to conclude that these nodes would be incentivised to put less computational resources into processing the transactions in the mempool and more into winning the round.
That leads to the conclusion that when a block with no transactions is added it normly means one of 3 things:

No transactions in the mempool i.e. no accounts trading value;

An Attack on the Network Is occurring;

Someone gamed the system.

Note: this is in addition to the answer by @Prom not in spite of it. When you combine both answers you get the full picture.

Just to be sure: what is the relationship between makingg the temp blocks and winning the round? Is it the case that the more temp blocks are made, the more likely you would win the round?


text:
How to convert some of the db-sync data types/columns to C# data types?
Specifically, I am using the Npgsql lib in a C# console app, and am reading data just fine so far for the obvious types like bigint, uinteger, boolean, etc. - but for a few different types/columns in some tables I am unsure:

hash32type
lovelace
word64type

Can anyone point me to a resource that would provide me the required knowledge for converting these types into C# types?
Thank you.

SQL domain types like lovelace etc are created in the stage one migration scripts (schema/migration-1* of the repo). Eg lovelace is:
CREATE DOMAIN lovelace AS numeric (20, 0) CHECK (VALUE >= 0 AND VALUE <= 18446744073709551615);

From these domain types you should be able to figure out the appropriate language type for your language.

yes! In the repo - of course it is, thank you!
https://github.com/input-output-hk/cardano-db-sync/blob/acf795fdcb23be0038ffa19554f3c8b0c8c43ed9/schema/migration-1-0001-20190730.sql#L19


text:
How to get unused address for stake key via Blockfrost API
Using Blockfrost API, I can query a stake address, and receive known addresses that have "state=used" like when I query them on my local node via Cardano-Wallet.
I am interested in "state=unused" though.
How can I get unused receiving addresses for a stake key using Blockfrost API?
EDIT:
When I use:

localhost:[port]/v2/wallets/[wallet id]/addresses?state=unused' | jq '.[0]

...on my local instance of cardano-wallet, I get the first addr for the wallet that has state=unused I was hoping for something similar from the blockfrost api - so I could avoid having to setup something that provides it to my web app from my local linux box where I have cardano-node & cardano-wallet running

The ask seems fundamentally wrong, as unused wallets - by definition - are not on-chain and can only be derived using root public keys (in case you haven't, could be helpful for you to check BIP-44 spec that is used by cardano-wallet ). The derivation of addresses can be easily achieved via one of the SDK/libs offline (you can find many of them at developer portal - most popular ones being  cardano-serialisation-lib and cardano-multiplatform-lib).
Some notes tho about these (adding here, tho it may not be relevant for your context):

There can be close to infinite unused addresses for a given stake account. You may see limited number of addresses because of default BIP-44 address gap (20), but that will not be all-inclusive list.
One can only derive addresses at different address idx if they have the root pub key, wouldn't be a good practice to rely on external services, especially when you have libraries to do it locally.
Even if you were to use a remote service that would provide list of addresses , from query pov - it would never be guaranteed to include different combinations of payment and stake key credentials , as they can also be merged across from different wallets.

Thank you for taking the time to answer.
When I use:

http://localhost:[port]/v2/wallets/[wallet id]/addresses?state=unused' | jq '.[0]

on my local instance of cardano-wallet, I get the first addr for the wallet that has state=unused
I was hoping for something similar from the blockfrost api - so I could avoid having to setup something that provides it to my web app from my local linux box where I have cardano-node & cardano-wallet running

You do not need cardano-node/cardano-wallet/etc running, the links above refer to SDKs/libs that should allow you to do this on the device where private keys , while fetching tx-in/UTxO details can be from blockfrost.io/koios.rest/etc

So the correct answer appears to be: "That's not possible".
The Blockfrost API does not have a utility call of any kind that returns an unused address of a given wallet.
The Blockfrost API does have a call that returns known used addresses from the blockchain though.
To generate an address for a given set of private keys, I can use one of the libraries as mentioned by RdLrt, thank you.
cardano-serialisation-lib or cardano-multiplatform-lib.


text:
Guarantee not dispensing native assets to a Franken address
As I understand it, a "mangled" address can be used to spoof ownership of a wallet who's stake address is NOT of a wallet controlled by the one doing the spoofing.
Put another way: I can use someone else's address, and my own address, combined together to fool a dApp into dispensing some native assets to ME even though they should only be claimable by the owner of the wallet who's stake address I have mangled with my spending address.
What is a very concrete way for a dApp to NEVER fall prey to this "exploit"?
It is put this way on a thread I found:

It is not possible if the dApp does not send native assets to the
address paying the fee, but instead to the address that last did a
delegation of the stake key of the address paying the fee, which
requires a signature of that stake key and, hence, guarantees the
ownership.

So...

what about a wallet that never delegated?

If someone uses a Franken Address to claim something or benefit somehow how can I make sure the TRUE owner is the one claiming/benefiting by finding the address to send to from the last time the stake address portion delegated? This must be a possible lookup in db-sync, and I am not sure how to look it up.

I am looking for a guaranteed way of ensuring native assets will (and ADA?) can only ever be sent to the actual wallet of the stake address, not to a wallet pretending to be that wallet by using a franken address.
I believe the simple way to avoid this as an issue is to ALWAYS require a user SIGN any transaction that sends them something or benefits them somehow...in this way, no spoofing is possible.

What is a very concrete way for a dApp to NEVER fall prey to this "exploit"?

Simple: you do not have keys to sign the payment credentials which are the payment part of the address.
And If a dApp is checking the stake key instead of the payment key, that is a major, major security flaw in their contract.
Your dApp should be using only and only the payment credentials of the address.

what about a wallet that never delegated?

Using the strategy outlined above you cannot accept tokens from users who never delegated, so you would need to handle it somehow in your application and not allow those types of users.

If someone uses a Franken Address to claim something or benefit somehow how can I make sure the TRUE owner is the one claiming/benefiting by finding the address to send to from the last time the stake address portion delegated? This must be a possible lookup in db-sync, and I am not sure how to look it up.

Blockfrost has an endpoint to get someone's delegation history
https://cardano-preprod.blockfrost.io/api/v0/accounts/stake_test123.../delegations?order=desc
Now is this the best way of avoiding the Frankenstein address vulnerability? It depends on your application, but I will say probably not.
A different way would be to ask for a CIP-08 signature from the user stake-key. If he can sign an arbitrary message with his staking-key, it means he has the stake-key, you can require this whenever a user wants to claim something.
Another possibility would be to force the user to include the stake address signature in the transaction and invalidate it otherwise. This is useful if you don't want to require the user to sign something twice like in the example above. You can do this by using the transaction to re-delegate to whatever pool he already was delegated (or to a new one if he wasn't previously). This will tell whatever browser wallet he is using that the transaction needs a staking-key witness.


text:
Querying db-sync for ADA Balance
I want to write the ADA balance of my wallet to a console window using sql queries against the db-sync database.
How can I use sql statements to obtain the ADA balance of a given address by querying db-sync via postgresql? I tried querying the sum of the [value] of the utxo's of my wallet but seem to get inaccurate results acording to what my Eternl wallet says my balance is. Somehow I am misunderstanding what I should be summing etc.
There is no straightforward query for "wallet balance" in the interesting queries in the db-sync git repo.

The tx_out table contains both spent and unspent tx outputs. In order to calculate your balance, you need to sum only the unspent outputs.
We can check which outputs are unspent by joining on the tx_in table. If there is no associated entry for a particular tx_out row in the tx_in table, this output has not been spent.
Here are the associated queries for calculating both address and stake address balances:
-- address balance
select sum(tx_out.value)
from tx_out
left join tx_in on tx_in.tx_out_id = tx_out.tx_id and tx_in.tx_out_index = tx_out.index
where address = '<your-address-here>'
  and tx_in.id is null

-- stake address balance
select sum(tx_out.value)
from stake_address
inner join tx_out on tx_out.stake_address_id = stake_address.id
left join tx_in on tx_in.tx_out_id = tx_out.tx_id and tx_in.tx_out_index = tx_out.index
where stake_address.view = '<your-stake-address-here>'
  and tx_in.id is null

Note that these balances will not include your staking reward balance.

This is a concise and correct answer.
I ran the queries and they work just as expected.
Much appreciated, thank you!


text:
Can db-sync be used to "listen" for transactions involving particular smart contracts?
Take JPG store as an example.
When someone lists an NFT for sale there, or when someone buys an NFT there, a smart contract governs that transaction.
Can sql queries against the db-sync generated blockchain data "see" that?
I'd like to write sql queries against the db-sync data that show the most recent transaction involving a particular smart contract, but I'm not sure what to query for...
UPDATE:
Here is a call to opencnft's free api which allows me to know the most recent transactions involving a particular NFT policy, sorted by date.
If I want to simple replicate that by using sql queries against db-sync, that's also something I am interested in:
https://api.opencnft.io/1/#/Policy/PublicController_getPolicyTx
However...that makes the NFT policy the focus of the query, whereas I am also looking for a query that would find the same resulting transaction had occurred but with the Smart Contract being used as the criteria I am querying on.
So in plain language - there are two generalized queries I am hoping to create as a basis and launching pad for other queries?

select the latest transaction 'Smart Contract X' was involved in, and the  assets involved in that transaction.

select the latest transaction 'Policy Id X' was involved in and any Smart Contracts and/or other assets involved in the transaction.

...sort of like looking for the same thing but from two different perspectives in terms of the criteria and tables involved in building the query?

What data specifically are you hoping to get out of db-sync ?

That a smart contract was executed, and what assets / values were involved..? For example: If someone lists an NFT for sale on JPG store, then the policy of the JPG store smart contract is the signature I am looking for, and I am interested in what asset was listed for sale. The smart contract has an identity, the NFT being listed for sale has an identity, so I am assuming I should be able to build a query that returns the last time a smart contract was executed in a transaction, and what assets are involved in that transaction? Of course, I may have a misconception about what can be queried.

Updated with an Edit to give a comparison to opencnft.io

Would something like the Blockfrost API for watching transactions happening against an address work for you? Something like this maybe? You could also query for assets held by an address
Ultimately, you can query specific details using multiple queries and filters on the JSON data returned and probably achieve what you want.

Thanks Bharat - I have used Blockfrost, but am seeking to do everything I want to do using only my own node, db-sync, and wallet.
I do already use db-sync to watch addresses.
My question is more about how to query what tables to find records related to the use of a specific smart contract - my thought was to build a query that uses the ID of a smart contract as the key to query on, and hopefully to find it's most recent execution, and the tx_outs/assets associated with that, so I could say basically: show me the last time this SC ran and what assets were inputs/outputs in that transaction.

Maybe oura is something for you to be worth looking into. https://github.com/txpipe/oura
In a nutshell: Oura allows you to watch for patterns in the blockchain as it progresses and then if you have found a match trigger your own events. So in your case you could have different filters that would trigger the same web enpoint but offer different payloads.


text:
What is your comfort level for Number Of Confirmations, and why?
As an example, in Eternl wallet, a new transaction is marked as follows:

red (0 to 9 confirmations)
yellow (10 to 19 confirmations)
green (20+ confirmations)

I have been watching blocks in db-sync, and have observed that 20 confirmations takes anywhere from 7 to 8 minutes.
In my service, I think I will be starting with a value of 20 for minimum confirmations, or block depth in my query for new transactions, but I also would like to keep it as low as possible to shave as many minutes off users seeing their new transaction reflected in my service, while still remaining confident in the level of finality I am accepting as valid.
So...I am not yet sure where the sweet spot between speed of acceptance and confidence of finality is, so I am hoping everyone will state their view on the matter, and importantly, why.
Thank you!
EDIT:
I have examined my node console and remarked the "Switch to new fork" is an event that occurs consistently, perhaps a number of confirmations that on average correlates to that is an objective measure of confidence? Here's what I observed:
2022-07-28 06:50
2022-07-28 07:14 => 24 mins
2022-07-28 07:29 => 15 mins
2022-07-28 07:37 =>   8 mins
2022-07-28 07:44 =>   7 mins
2022-07-28 08:12 => 28 mins
2022-07-28 08:22 => 10 mins
2022-07-28 08:34 => 12 mins
2022-07-28 09:11 => 37 mins
2022-07-28 09:31 => 20 mins
2022-07-28 09:33 =>   2 mins
2022-07-28 09:36 =>   3 mins
2022-07-28 09:45 =>   9 mins
2022-07-28 10:13 => 28 mins
2022-07-28 10:23 => 10 mins
===================
               Sum =>213 mins

                Avg=>14.2 mins

So, switches to new fork on average about every 15 mins which is a long time in terms of confirmations...if I were to say, select the number of confirmations that on average certainly pushes beyond the most recent "switch to new fork" than I'd guess about 40 to 50 confirmations, and though it would often be overkill, it would also almost always be enough to cause a delay that extended beyond whatever the next "switch to fork" was following a given new transaction being tracked.

I have not had to do this, but if I did, my level of comfort would depend on the amount in question. If it was US$20 I might want 2 confirmations whereas if it was US$20,000 I might want 20 confirmations.

have observed that 20 confirmations takes anywhere from 7 to 8 minutes.

Basically each block added to the chain adds a confirmation. The average block time interval is about 20 seconds and if you have the ocassional missed block it will be slightly higher than that.
20 blocks * 20 second block interval => 400 seconds => 6.667 minutes

Good point about "greater amount requires greater confidence".


text:
tx_metadata: How to interpret a CBOR string
In the document:
https://github.com/input-output-hk/cardano-node/blob/master/doc/reference/tx-metadata.md
We are told: "JSON strings are represented as CBOR strings"
How can I interpret these?
The source of th eformat of those appears to be here:
https://www.rfc-editor.org/rfc/rfc7049
Here is an example of one from a transaction in the tx_metadata table of cardano-db-sync

d8799f581c25fa506339b24dc4e1a643637325e700ae498e646746a5426739f2

...there is this:
https://github.com/CardanoSharp/CBOR
...and this:
https://github.com/input-output-hk/cardano-node/blob/master/doc/reference/tx-metadata.md
...and this:
https://input-output-hk.github.io/cardano-wallet/user-guide/common-use-cases/TxMetadata

A good tool for manually analyzing CBOR is https://cbor.nemo157.com/
What they probably meant by "JSON strings are represented as CBOR strings" is that typical JSON objects can be represented in tx-metadata using CBOR

I am trying to figure out how a value like this one, in the object, is a value that decodes to a wallet address:
BAED3AE13D7EEB93BB4B4F44E10AFF9F1FC052869F4A1CD1501BE928

I don't think there are any easy-to-use online tools for converting the hex of, I'm assuming, a pubkeyhash into a bech32 encoded address. You would have to use a library. Eg. with Javascript and Helios: let isTestnet=true;helios.Address.fromPubKeyHash(isTestnet, helios.PubKeyHash.fromHex(" BAED3AE13D7EEB93BB4B4F44E10AFF9F1FC052869F4A1CD1501BE928")).toBech32() which results in addr_test1vzaw6whp84lwhyamfd85fcg2l703lszjs60558x32qd7j2qnwhmq3


text:
Cardano-Wallet on LAN
No connection could be made because the target machine actively refused it.
That's all I can manage to get when making an http call to cardano-wallet on another machine on my local LAN.
Cardano-wallet is synced and I used 'serve' when launching the wallet and the port I specified is open and listening...

What wallet software and software version are you using? On what OS (WIndows/Mac/Linux)? What are you trying to connect to?

Apologies, I realize this is not really a Cardano-specific question - I am just very frustrated lol

So...using curl in a command line on the SAME linux machine where I have the node & wallet running, I am able to use the web api without issue - I just ran a v2/wallets to list known wallets and it works fine.
It's just calling from any other machine on my LAN I am only getting "...target machine actively refused it..." even though I have confirmed the firewall on that machine is inactive and the cardano-wallet process is reporting 'LISTEN' on the port it was launched to serve on...

I think it must have something to do with the host being configured when the wallet launches as the loopback 127.0.0.1 but that not mapping for requests to the ip of the machine

--listen-address
!!! THAT was it :)
The default in the startup command for Cardano-wallet is the loopback address so of course I could not reach that from anywhere except the same machine the wallet was running on!
Got it - now connecting and interacting on LAN woot!


text:
To create a dead-end "burning mechanism" contract for a specific native token
I am not sure how this should, or could, be done on Cardano...
I would like an address/script which, if a specific native token were submitted there, that token would become permanently irretrievable.
The goal is to effectively "burn" specific tokens so they are no longer considered as a part of the circulating supply of that token.  The policy used to create them is closed, so truly using the mint/burn mechanism is no longer possible.
I am seeking advice/guidance/examples of a way to transparently, and verifiably remove some of these tokens from circulation.

It should be irreversible.
It should only be for a specific token.
It should be possible for anyone to verify for themselves on-chain, that the tokens are truly locked irreversibly.

How can this be done?
Also, if there are more ways than one, what are the pros & cons of doing it one way vs another?
Thank you for helping me get this question answered!


text:
window.cardano undefined
I would to use window.cardano when a user just "enter" to website. Sometimes window.cardano is still undefined
How can i solve this problem? I try to use await window.cardano but is not a Promise.
I try to use this code in a react useEffect:
let cardanoExist = await window.cardano
    if (cardanoExist) {
       let namiExist = await window.cardano.nami
           if (namiExist) { \\ do some stuff } else {return}
    } else {
           return
    }
}

But sometimes window.cardano is undefined, also if i have installed, for example, nami wallet
Thanks!

What website are you calling window.cardano from? If you call it from a new tab or a localhost port that's not running a frontend, then it will be undefined.

Please clarify your specific problem or provide additional details to highlight exactly what you need. As it's currently written, it's hard to tell exactly what you're asking.

I try to use this code in a react useEffect:
`
let cardanoExist = await window.cardano
        if (cardanoExist) {

            let namiExist = await window.cardano.nami

            if (namiExist) {

               \\ do some stuff

`
But sometimes window.cardano is undefined, also if i have installed, for example, nami wallet

I am using this code in react:
const isBrowser = () => typeof window !== "undefined";

export const getCardano = (): Cardano | undefined => {
  const cardano = isBrowser() && window.cardano;
  return cardano;
};

export type Cardano = {
  [key: string]: {
    name: string;
    icon: string;
    version: string;
    api?: WalletApi,
    enable: () => Promise<WalletApi>;
    isEnabled: () => Promise<boolean>;
  };
};

export interface WalletApi {
  getNetworkId: () => Promise<number>;
  getUtxos: () => Promise<string[] | undefined>;
  getBalance: () => Promise<string>;
  getUsedAddresses: () => Promise<string[]>;
  getUnusedAddresses: () => Promise<string[]>;
  getChangeAddress: () => Promise<string>;
  getRewardAddresses: () => Promise<string[]>;
  signTx: (tx: string, partialSign: boolean) => Promise<string>;
  signData: (
    address: string,
    payload: string
  ) => Promise<{ signature: string; key: string }>;
  submitTx: (tx: string) => Promise<string>;
  getCollateral: () => Promise<string[]>;
  experimental: {
    getCollateral: () => Promise<string[]>;
    on: (eventName: string, callback: Function) => void;
    off: (eventName: string, callback: Function) => void;
  };
};

and when the user selects his/her wallet of choice in the app, I set the wallet name and run the following code:
const existingWallets = cardano
    ? Object.keys(cardano).filter(
      (walletName) =>
        walletName === "nami" ||
        walletName === "eternl" ||
        walletName === "gerowallet" ||
        walletName === "flint"
    )
    : [];

{...setting walletName...}

const cardano = getCardano()!;
const api = await cardano[walletName]!.enable();
const usedAddresses = await api.getUsedAddresses();
{...}

// copies wallet api into cardano object which allows to use cardano.selectedWallet anywhere in the app
cardano.selectedWallet = {
    ...cardano[walletName],
    api
};

First of all, window.cardano can be undefined if the user doesn't have a Cardano wallet installed on their browser.
Secondly, you don't need to use await with window.cardano as it's not an async function. Also, you should avoid nested hell and instead try something like this:-
const isCardano = window && window.cardano
const isNamiInstalled = isCardano && window.cardano.nami
const isNamiEnabled = isNamiInstalled ? await window.cardano.nami.isEnabled() : false

Edit: sometimes window.cardano or window.cardano.nami can be undefined even if you have nami installed. That happens mostly when you try to access these parameters before the extension is even injected to the site. To prevent such scenarios, you can try wrapping your code with a setTimeout delay.
setTimeout(()=> {
    const isCardano = window && window.cardano
    const isNamiInstalled = isCardano && window.cardano.nami
    const isNamiEnabled = isNamiInstalled ? await window.cardano.nami.isEnabled() : false
}, 1500)

Had same issue. I found that both nami and eternl are just to slow with their injections into website. This solved problem :
if (cardanoExist) {
await new Promise(resolve => setTimeout(resolve, 100));
let namiExist = window.cardano.nami;

Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers in the help center.


text:
Cardano serialization lib for PHP
I'm trying to authenticate a user against a (or any) PHP platform (Drupal, Symfony, Laravel,..) by having the user connect with their wallet (Eternl, Nami, ...).
As far as I understand, the following things need to happen:

Backend provides a nonce or unique string to the client
Client signs a message containing the string with their wallet
Client sends the signature back to the server
Server deserializes the signature and checks if the signature is valid
Server issues a JWT token (or other means of authentication), the client can use in later requests

There is a good example of how to do this using NodeJs and javascript (https://github.com/pyropy/web3-cardano-token). However, I can't seem to find anything that would enable me to do the same using PHP.
Any help would be greatly appreciated.
Thanks alot!
Edit: Taking matters into my own hands. Currently porting https://github.com/StricaHQ/cip08 to a php library. Halfway there. Will report back when I have it in a public repo.

DId you ever get round to this?

Any update on this?