text:
Can you burn/lock/self-destruct NFTs in a a smart contract?
I am involved in an NFT project where there is a policy locking date coming up, but I would like to give the option burn/lock/self-destruct the NFT through a smart contract (SC) at any time after that point, and create a new 'evolved' NFT to give to the holder.
Is this 'locking/burn' possible in Plutus?
I don't want to create a burn wallet as there are obvious security concerns there with private keys. So I think an SC is the only way to go.
I am rather new to plutus so any help is appreciated.

As @kindofdev points out, it is very simple to burn tokens with Plutus scripts. It is a little more involved if you want some kinda of side-effect/record of burning tokens. Still shouldn't be too difficult, although Plutus takes some time to learn.
Background
There are no bounds on what can be sent to a Plutus Script, i.e. the script doesn't do any checks on new UTxOs at the address. This means you can't make the script do something just by sending something to it. The script only sees what is included in transactions spending the UTxOs at that address or minted from the address. It can see the entire transaction though, so multiple scripts can ensure something happens in other scripts atomically before validating.
Why does that matter?
You mention that you want to, for example, send an NFT to be replaced with an "evolved" NFT. You can definitely do this. In the simplest case, you can have your minting policy check that the old NFT is being burnt, at which point it will allow minting an "evolved" NFT.
Minting policies can't track any state though. They don't have a datum. So if you want to include any additional context for when tokens can be minted or evolved, that state must be stored on a separate validator script. This will require (at the very least) one validator script and one minting policy:

A script for validating the burning of the original NFT
A minting policy for minting the new "evolved" NFT

A transaction for evolving your NFT would spend a datum at Script #1 and replace it with a new datum (either identical or with some book-keeping data). The transaction would also mint the new NFT with Minting Policy #2.
The minting policy will only validate if the Script #1 Datum is spent in the transaction and the script will only validate if the old NFT is spent to the script and the new NFT is minted + any additional constraints you want to include.
TL;DR
You can have your "evolve" minting policy check if the pre-evolution NFT is being burned. If you need to include additional state/context for when that can happen, you can include that data on a separate, but inter-dependent, validator script.
Hope that helps. Might be worth looking at these other questions to give you more ideas:
How to lock funds in a smart contract?
Ensuring NFT collection uniqueness using counter as asset name?
Can a smart contract only be interacted with once

I think you could also use two minting policies. One for the "normal" token that will enable it to be burnt and one for the "special" token that will only mint it if the normal token is burnt, no script involved. Both policies would be "invoked" in the same transaction

The problem I see is that neither scripts or policies have access to the tx metadata, where the NFT content is. This means the user could mint a special token with any characteristics he wanted (only constrained by the token name)

One for the "normal" token that will enable it to be burnt and one for the "special" token that will only mint it if the normal token is burnt, no script involved
Thanks. Good point. I'll note this. I think in many cases you'd want to follow the access token pattern to allow any bookkeeping, but there are cases where that is probably superfluous.
WRT metadata. I'm actually unfamiliar with how metadata works. But I'm certain you can put whichever constraints you'd want by recording in the Validator Datum. They might not live on the token directly, but can still be recorded and read.

One option would be to define a validator which always fails and therefore, funds sitting at its address will be locked forever, ie, burned.
{-# INLINABLE mkValidator #-}
mkValidator :: () -> () -> ScriptContext -> Bool
mkValidator _ _ _ = False

Then, you can create a transaction which sends the NFT to the script address using mustPayToTheScript.
Hope this will be useful.


text:
Unable to get transaction hash and index of the UTXO to spend
We are unable to get transaction hash and index of the UTXO to spend. Actually we are creating simple transaction and were using this link https://developers.cardano.org/docs/stake-pool-course/handbook/create-simple-transaction
but we are not getting transaction hash and index of the UTXO to create draft transaction. Please help us to resolve it and give me any suggestion to sort out it.
Thanks.

Why are you not getting it? What error are you receiving and what command are you executing?

Sounds like cardano-cli isn't running properly for you, so lets start with something simple to prove that it is working.
Can you successfully run 'cardano-cli --version' and get the version number?
Also, as others have mentioned here, 'cardano-cli query utxo --address $(cat payment.addr) --mainnet' is all you need to list the details.

Thanks for the quick response.
I am using below command but not getting any output. How could we create Draft the transaction without transaction hash and index of the UTXO. Please help me.
cardano-cli query utxo --address $(cat payment.addr) --mainnet
Thanks.

sorry my english is not so great and i loose it a bit your question. 1. i asked you please for an error message, 2. the "$(cat payment.addr) " , is that file in the same folder you are executing the command? 3. can you replace the "$(cat payment.addr)" with your address? and let us know if you still have an issue. last but not least :) if any question helps you, please vote with the upper arrow :)

Yes, payment.addr file in in the same folder from where we are shooting above command nor we are getting any error to run the command even we try to put direct address in the command but same result not getting any output. Output is coming blank without any error.

Please use reply within threads instead of creating new answer to the post, so that it's easier for you to answer respective queries (you have currently - possibly unknowingly - overlooked other questions). This is also easier for an onlooker to follow the flow of post

Okay, I am still struggling. Please help me on this.

Yes, payment.addr file in in the same folder from where we are shooting above command nor we are getting any error to run the command even we try to put direct address in the command but same result not getting any output. Output is coming blank without any error
Thanks.

source: Stack Exchange

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

sort: votes


text:
How do I get bids or listed NFTs using the cardano serialization libray?
We're building a marketplace for cardano and we're aware that the owned tokens/nfts can be fetched via the getBalance() function. How do we get the bids or lists (for sale) for a particular owner address? Is this stored and decoded somewhere in the blockchain much like the owned nfts? THanks

You cannot get the bids and the listings of NFTs directly from the wallet that is bidding or selling. You need to know which Marketplace (smart contract) has that wallet used and get the information from there.
For example, you can check the contracts of the most popular Marketplace in Cardano (jpg.store) here: https://github.com/jpg-store/contract-v2

Actually, you can't get bids information from blockchain itself.
Since those information are on marketplace smart contract (Jpg.store).
But you can get these information using some provided API.
For example, you can use api which is provided by CNFT.TOOLS.
https://cnft.tools/
Here is example of api.
https://api.cnft.tools/api/external/${policyId}/
This api will give you the current price, and whether nfts are on sale or not, and their metadata, etc...
Hope this will help you.

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


text:
2 Validators for one Transaction
I'm building a use case where a person can buy a token and depending on the amount of ADA spent, he gets X tokens and a Special NFT.
Each Validator represent the policy Id of these native tokens I'm creating.
Now I must prevent anyone from minting without paying and off course check if the ADA is the value of the mint
mintWithFriend :: MintParams -> Contract w FreeSchema Text ()
mintWithFriend mp = do
        let  destinations       = paymentTo mp
             referralAddr       = pubKeyHashAddress (referral destinations) Nothing
        now                     <- currentTime
        utxosReferral           <- utxosAt referralAddr
        let
            vals                =  (_ciTxOutValue <$> (snd <$> Map.toList utxosReferral))
            referralOk          =  extractLevel (getTot vals []) 0

            yacada              = Value.singleton yacadaSymbol (U.yacadaName) (U.calculateYacada $ mpAdaAmount mp) -- coins for customer
            yacadaNft           = Value.singleton yacadaNFTSymbol  (U.giveReferralNFTName (mpAdaAmount mp) now)  1 -- NFT for is base referral
            yacadaReferralNft   = Value.singleton yacadaNFTSymbol  (U.upgradeReferralNFTName (referralOk+1) now)  1 -- upgrade for the referral account
            treasuryAdas        = Ada.lovelaceValueOf $ U.treasuryAda (mpAdaAmount mp) referralOk
            referralAdas        = Ada.lovelaceValueOf $ U.referralAda (mpAdaAmount mp) referralOk
            lookups             = Constraints.mintingPolicy policy
                                    <> Constraints.mintingPolicy levelPolicy
            payment             = Constraints.mustPayToPubKey (treasury destinations) treasuryAdas
                                    <> Constraints.mustPayToPubKey (referral destinations) (referralAdas <>  yacadaReferralNft)
            mint                = Constraints.mustMintValue (yacada <> yacadaNft <> yacadaReferralNft)
            tx                  = mint <> payment

        ledgerTx <- submitTxConstraintsWith @Void lookups tx
        void $ awaitTxConfirmed $ getCardanoTxId ledgerTx

On this Off-chain contract, I'm building such transaction.
The policy and LevelPolicy are my 2 validators.
the only utxo sent are the payment.
being that I have 2 validators can I define what utxo goes for each?
{-# INLINABLE yacadaPolicy #-}
yacadaPolicy ::  () -> PlutusV1.ScriptContext -> Bool
yacadaPolicy _ ctx  =
    traceIfFalse "not ok" True

    where
        allOk :: Bool
        allOk = True

        info :: TxInfo
        info = scriptContextTxInfo ctx

        minted :: Value
        minted = txInfoMint info

        mintedValue :: [(CurrencySymbol, TokenName, Integer)]
        mintedValue = flattenValue (minted)

        -- ?? Paied amount ?? --
        -- ?? amount of yacada == minted amount ??
        -- ?? name of yacadaNFT == level given by amount of ADA && quantity == 1
        -- ?? did the treasury account received the ADA
        -- ?? did the referral NFT name correct quantity = 1??
        -- ?? did the referral received ADA and new NFT

The full source is https://github.com/cmorgado/yacada_learning
Many thanks in advancednat

being that I have 2 validators can I define what utxo goes for each?

No, both scripts have visibility of all inputs and outputs of the transaction.
You can try ensuring that unique outputs are checked for each script.

I have distinct outputs how do I see them in the validator?

Your can access transaction outputs with txInfoOutputs info


text:
Multiple minting on one TX
I'm trying to mint a utility token and based on this quantity the investor will get different NFT bonus.
----------
mint :: MintParams -> Contract w FreeSchema Text ()
mint mp = do
        let yacada          = Value.singleton yacadaSymbol yacadaName (calculateYacada $ mpAdaAmount mp)
            yacadaNft       = Value.singleton yacadaNFTSymbol  "NFT" 1 --(giveReferalNFTN
            adas            = Ada.lovelaceValueOf $ mpAdaAmount mp
            lookups         = Constraints.mintingPolicy policy <> Constraints.mintingPolicy levelPolicy
            destinations    = paymentTo mp
            payment         = Constraints.mustPayToPubKey (treasury destinations) adas
            mintYacada      = Constraints.mustMintValue yacada <> Constraints.mustMintValue yacadaNFT
            tx              = mintYacada

        ledgerTx <- submitTxConstraintsWith @Void lookups tx
        void $ awaitTxConfirmed $ getCardanoTxId ledgerTx
        logInfo @String $ printf "------------------------------------------------------"
        logInfo @String $ printf "We forged y:%s NFT:%s" (show yacada)  (show yacadaNft)
        logInfo @String $ printf "------------------------------------------------------"

----------

The thing is that when I see the token in the wallet they both have the same policy :
(
Wallet 2:
{32d66bc1df769f6af0d37ccd9e3510ebf38b5e4c7235a2b2e4e9d08c, "NFT"}: 1
{32d66bc1df769f6af0d37ccd9e3510ebf38b5e4c7235a2b2e4e9d08c, "YACADA_TOKEN"}: 2000
{, ""}: 99697225
Wallet 1:
{32d66bc1df769f6af0d37ccd9e3510ebf38b5e4c7235a2b2e4e9d08c, "NFT"}: 1
{32d66bc1df769f6af0d37ccd9e3510ebf38b5e4c7235a2b2e4e9d08c, "YACADA_TOKEN"}: 1000
{, ""}: 99697137
Any ideas?
I have this "test code" on github if any needs it.

Just found my mistake. Just need to have the multiple policies in diferent files..


text:
scriptCurrencySymbol in V1 libs to mint assets
I'm using the latest Plutus-Stater project with this script
module FreeMinting where

import           Control.Monad          hiding (fmap)
import           Data.Aeson             (ToJSON, FromJSON)
import           Data.Text              (Text)
import           Data.Void              (Void)
import           GHC.Generics           (Generic)
import           Plutus.Contract        as Contract
import           Plutus.Trace.Emulator  as Emulator
import qualified PlutusTx
import           PlutusTx.Prelude       hiding (Semigroup(..), unless)
import           Ledger                 hiding (mint, singleton)
import           Ledger.Constraints     as Constraints
import qualified Ledger.Typed.Scripts   as Scripts
import           Ledger.Value           as Value
import           Playground.Contract    (printJson, printSchemas, ensureKnownCurrencies, stage, ToSchema)
import           Playground.TH          (mkKnownCurrencies, mkSchemaDefinitions)
import           Playground.Types       (KnownCurrency (..))
import           Prelude                (IO, Show (..), String)
import           Text.Printf            (printf)
import           Wallet.Emulator.Wallet

--ON-CHAIN

{-# INLINABLE freeMintingPolicy #-}
freeMintingPolicy :: () -> ScriptContext -> Bool
freeMintingPolicy _ _ = True

policy :: Scripts.MintingPolicy
policy = mkMintingPolicyScript $$(PlutusTx.compile [|| Scripts.wrapMintingPolicy freeMintingPolicy ||]) --unTypedValidator

curSymbol :: CurrencySymbol --aka PolicyID
curSymbol = scriptCurrencySymbol policy

But now scriptCurrencySymbol does not exists
Any tips on its substitute?

You should use
import Plutus.Script.Utils.V1.Scripts qualified as Scripts

-- ...

curSymbol = Scripts.scriptCurrencySymbol policy

You need to modify the cabal.project file to use v0.1.0 of plutus-apps which has Plutus.Script.Utils.V1.Scripts module
-- Plutus apps revision from 2022-04-06
source-repository-package
  type: git
  location: https://github.com/input-output-hk/plutus-apps.git
  tag: v0.1.0

Ref: Plutus.Script.Utils.V1.Scripts code

thanks a lot... still trying to get how documentation works with Cardano/Plutus ;)

my solution is copy the function which is not existed, and search on input-output-hk github (scope organization). There is some commit or code related to the function we need. in this case the function is scriptCurrencySymbol, then we infer to the correct module ;)


text:
traceIfFalse is it possible to pass a string not "fixed"
Is this even possible?
traceIfFalse  ("A"++show(scriptContextTxInfo)) FoundIt

As logging onchain is just possible with this traceIfFalse ... I'm not finding a solution to make that line work

What I've done to debug Integers is to write a function that converts them into a BuiltinByteString and then decodeUtf8 it into a BuiltinString which is passed to any of the available trace functions.
I assume it could work for more complex data as well, but I have not tried that yet.
Example of what I described above:
{-# INLINABLE intBS #-}
intBS :: Integer -> BuiltinByteString
intBS i
  | i < 10    = consByteString (48 + i) emptyByteString
  | otherwise = appendByteString (intBS (divide i 10)) (intBS (modulo i 10))

-- ...
    traceIfFalse (decodeUtf8 $ intBS coolInt) $ ...
--...

Hope this helps.

This is probably not possible as the redeemer code is manipulated/examined from within a template haskell splice and you are running into what is called the "template haskell stage restriction".


text:
Uninstalling Nix after Node, Db-sync & Postgres Installation
I have installed via Nix a cardano node, DB-sync and Postgres on a single server.
My plan is to pass my Postgres data into an Apache Kafka cluster.
My node is synced to tip and DB-sync is on epoch 264.
So far they have taken in total 93 GB of disk space.
I searched for what is taking the most space and I found out that the node & DB-sync are only taking 44 GB, while the Postgres database 15 GB. On the other hand the nix folder alone is taking 29 GB.
My question is, is it possible to uninstall/delete nix to save space or will the whole installation collapse?
Thank you for your answer!

You can garbage collect nix store with nix-collect-garbage tool. This is useful if you have multiple versions in the nix store to get rid of older ones.

Thank you for answering. I only have one version of nix installed and used. Can the garbage tool be of any use then?

No, the Nix database is required as long as you are using Nix.
At chain tip, the PostgreSQL database will take over 100G.


text:
What is the total size of cexplorer on Postgres?
I have a relay node fully synced with the tip of the mainnet chain and DB-sync filling the Postgres database. DB-sync is currently syncing on epoch 321 and the database takes 103 GB of disk space. I noticed that as epochs move forward more storage space is required (and syncing is much slower).
I currently have only Postgres filling up a disk volume on Linux of total 187 GB.
My question is, what will be the total size of the cexplorer (for mainnet) database? Do I need more than 187 GB? Currently the chain is on epoch 342.

I noticed that as epochs move forward more storage space is required (and syncing is much slower).

Yes, that is the unfortunate reality.

I currently have only Postgres filling up a disk volume on Linux of total 187 GB.

It will continue growing. There is an SQL query that will tell you the size of the database. Last time I ran that on a fully synced database it was 140G.

Thanks for the reply. So it is 140GB in total (currently), that's good!
I use that query as well to check the size.

Its is 140G at epoch 336 and we are currently at epoch 342 so its a bit bigger than 140G (and its constantly growing).


text:
Submitting Transaction with CSL Metadata Isn't Showing
I've forked a dApp Connector I found on Github and I'm trying to add some transaction metadata to the ADA transaction it builds. This is what I currently have:
buildSendADATransaction = async () => {
    //metadata
    const messageData = {
      receiver_id: "SJKdj34k3jjKFDKfjFUDfdjkfd",
      sender_id: "jkfdsufjdk34h3Sdfjdhfduf873",
      comment: "happy birthday",
      tags: [0, 264, -1024, 32],
    };
    const generalMetadata = GeneralTransactionMetadata.new();
    console.log(Buffer.from(generalMetadata.to_bytes(), "hex").toString("hex"));

    generalMetadata.insert(
      BigNum.from_str("674"),
      encode_json_str_to_metadatum(JSON.stringify(messageData))
    );
    const _metadata = AuxiliaryData.new();
    _metadata.set_metadata(generalMetadata);

    console.log(`the metadata is ${_metadata.metadata()}`);

    // build tx
    const txBuilder = await this.initTransactionBuilder();

    const shelleyOutputAddress = Address.from_bech32(
      this.state.addressBech32SendADA
    );
    const shelleyChangeAddress = Address.from_bech32(this.state.changeAddress);

    txBuilder.add_output(
      TransactionOutput.new(
        shelleyOutputAddress,
        Value.new(BigNum.from_str(this.state.lovelaceToSend.toString()))
      )
    );

    // Find the available UTXOs in the wallet and
    // use them as Inputs
    const txUnspentOutputs = await this.getTxUnspentOutputs();
    txBuilder.add_inputs_from(txUnspentOutputs, 1);

    // calculate the min fee required and send any change to an address
    txBuilder.add_change_if_needed(shelleyChangeAddress);

    // once the transaction is ready, we build it to get the tx body without witnesses
    const txBody = txBuilder.build();
    txBody.set_auxiliary_data_hash(hash_auxiliary_data(_metadata));

    // Tx witness
    const transactionWitnessSet = TransactionWitnessSet.new();

    const tx = Transaction.new(
      txBody,
      TransactionWitnessSet.from_bytes(transactionWitnessSet.to_bytes()),
      _metadata
    );

    let txVkeyWitnesses = await this.API.signTx(
      Buffer.from(tx.to_bytes(), "utf8").toString("hex"),
      true
    );
    txVkeyWitnesses = TransactionWitnessSet.from_bytes(
      Buffer.from(txVkeyWitnesses, "hex")
    );

    transactionWitnessSet.set_vkeys(txVkeyWitnesses.vkeys());

    const txBodyFinal = tx.body();
    const signedTx = Transaction.new(
      txBodyFinal,
      transactionWitnessSet,
      _metadata
    );

    const submittedTxHash = await this.API.submitTx(
      Buffer.from(signedTx.to_bytes(), "utf8").toString("hex")
    );
    console.log(submittedTxHash);
    this.setState({ submittedTxHash });
  };

It constructs the transaction just fine with a wallet like Nami, but there's no metadata attached to that transaction. Any thoughts?

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.

If you are open to integrating with wallets other than Nami Wallet,
Typhon Wallet DApp connector has simple, ready-to-call methods to build a transaction with metadata and/or tokens.
Below is transaction method that adds metadata to a transaction.
const auxiliaryDataCbor = typhonjs.utils
  .createAuxiliaryDataCbor({
    metadata: [
      {
        label: 674,
        data: {
          msg: ["This is a comment for the transaction xyz, thank you very much!"],
        },
      },
    ],
  })
  .toString("hex");

const paymentTransactionResponse = await typhon.paymentTransaction({
  auxiliaryDataCbor: auxiliaryDataCbor,
  outputs: [
    {
      address:
        "addr_test1qz7jw975stagnvs00wsjny6y6gpazn86yvwcm2vy02j3up7mt68vuzvz4nzgs00x0shrgywvy674v6r2zcs8fxvvq27qfjq8np",
      amount: "6000000",
    },
  ],
});

Example at https://docs.typhonwallet.io/examples/paymentTransaction.html#sending-metadata
https://typhonwallet.io

Yeah, I saw that -- but I'd prefer to stick with CSL, any thoughts?

This answer is refferenced from https://cardanoupdates.com/commits/6af4284b32841a13ebe86fdcc6f10dd1d74ddfdc and I have used similar code in production. I haven't tested this function but you should get the idea.
buildSendADATransaction = async () => {
const messageData = {
    receiver_id: "SJKdj34k3jjKFDKfjFUDfdjkfd",
    sender_id: "jkfdsufjdk34h3Sdfjdhfduf873",
    comment: "happy birthday",
    tags: [0, 264, -1024, 32],
};

const txBuilder = await this.initTransactionBuilder();
const shelleyOutputAddress = Address.from_bech32(
    this.state.addressBech32SendADA
);
const shelleyChangeAddress = Address.from_bech32(this.state.changeAddress);

txBuilder.add_output(
    TransactionOutput.new(
        shelleyOutputAddress,
        Value.new(BigNum.from_str(this.state.lovelaceToSend.toString()))
    )
);

/////////////////////////////////
// Add metadata here

txBuilder.add_json_metadatum(
    BigNum.from_str("674"),
    JSON.stringify(messageData)
);
/////////////////////////////////

const txUnspentOutputs = await this.getTxUnspentOutputs();
txBuilder.add_inputs_from(txUnspentOutputs, 1);
txBuilder.add_change_if_needed(shelleyChangeAddress);
const txBody = txBuilder.build();

////////////////////////////
// Create unsigned tx with metadata included

const unsignedTransaction = txBuilder.build_tx();
/////////////////////////////

const transactionWitnessSet = TransactionWitnessSet.new();
const tx = Transaction.new(
    txBody,
    TransactionWitnessSet.from_bytes(transactionWitnessSet.to_bytes()),
    ///
    unsignedTransaction.auxiliary_data() // Include metadata

);
let txVkeyWitnesses = await this.API.signTx(
    Buffer.from(tx.to_bytes(), "utf8").toString("hex"),
    true
);
txVkeyWitnesses = TransactionWitnessSet.from_bytes(
    Buffer.from(txVkeyWitnesses, "hex")
);
transactionWitnessSet.set_vkeys(txVkeyWitnesses.vkeys());

const txBodyFinal = tx.body();
const signedTx = Transaction.new(
    txBodyFinal,
    transactionWitnessSet,
    ///
    unsignedTransaction.auxiliary_data() // Include metadata

);

const submittedTxHash = await this.API.submitTx(
    Buffer.from(signedTx.to_bytes(), "utf8").toString("hex")
);
console.log(submittedTxHash);
this.setState({ submittedTxHash });};


text:
Not enough ADA leftover to include non-ADA assets in a change address
I am getting the error when using @emurgo\cardano-serialization-lib-asmjs
txBuilder.add_change_if_needed(shelleyChangeAddress)
throws an exception
Not enough ADA leftover to include non-ADA assets in a change address

I'm not familiar with that code, but in general moving native assets needs to go along with some ADA eg 1 or 2 ADA.
Does your input UTxO have enough ADA balance to cover everything eg fees and output ADA?
If not then you can add a second input UTxO that has more ADA into the transaction.

thanks, its a stange issue. if i execute couple of time the same code it work after couple of retries. but I have a different problem in submitting the transaction. Sign the tx is fine Error: submit tx failed: Error: 400:
0: "278ad827cb923ed800fcb2028114ee8e9bca875059e1389ca1f49755c1c9a629"
at checkResponseNoError (apiDom.ts:334:1)
at Object.submitTx (apiDom.ts:270:1)

Can you post the full input code, and response output/errors/messages. There are often multiple messages in the output which give better clues.

Posting an alternative where you don't need to build a transaction in front-end https://cardano.stackexchange.com/a/7658/117

Unexpected error value: "Not enough ADA leftover to include non-ADA assets in a change address" I am getting this error, using nami, I have 5+ ada as collateral. I get the message when I try to harvest in the farm.

If you have a question then please raise it as a new question with full details of what you were trying to do and how, and what errors/output to received. The Answers space here is intended for answers to the question above about the library cardano-serialization-lib-asmjs, not for a new question. We're happy to help but as a new question, cheers.

(1) Make sure you have enough ADA in your wallet that can be used to pay for transaction fees. Transaction fees are increasing the more native assets you add to the transaction.
(2) If you use add_change_if_needed make sure to add enough inputs before calling this method that can cover the transaction fees.
(3) If you hardcode your input UTxO like you probably did with 278ad827cb923ed800fcb2028114ee8e9bca875059e1389ca1f49755c1c9a629 then running your code multiple time with of course fail, because you've consumed the unspent output with your first execution. Any second try won't be able  to spend this output again, since it's already been spent.
You will need to update your code manually or write some logic to select the new UTxO.

Comment converted into answer:
I'm not familiar with that code, but in general moving native assets needs to go along with some ADA eg 1 or 2 ADA. Does your input UTxO have enough ADA balance to cover everything eg fees and output ADA? If not then you can add a second input UTxO that has more ADA into the transaction.


text:
Error: submit tx failed: Error: 400: 0: "278ad827cb923ed800fcb2028114ee8e9bca875059e1389ca1f49755c1c9a629"
this.API.submitTx is throwing error
Error: submit tx failed: Error: 400:
0: "278ad827cb923ed800fcb2028114ee8e9bca875059e1389ca1f49755c1c9a629"
at checkResponseNoError (apiDom.ts:334:1)
at Object.submitTx (apiDom.ts:270:1)

Is 278ad827cb923ed800fcb2028114ee8e9bca875059e1389ca1f49755c1c9a629 one of your input UTxOs? Do you recognise this hash? Help us to help you.

An alternative to avoid building transaction in front-end https://cardano.stackexchange.com/a/7636/117


text:
Verify Tx Signature
Say I created a multi-sig transaction and I am now gathering signatures using the Cardano-multiplatform-library.
How can I check that the signature is correct for my transaction body, and the signers pub-key ?

Found it.
In case you find your self coming here to find the answer, you can create an instance of TransactionWitnessSet, using the witness you got from the wallet api.
const witness  =  C.TransactionWitnessSet.from_bytes(hexToBytes(signature))

You can then derive the publicKey of the signer, and use the publicKey method verify() to verify against your transaction.
Const validSignature =   witness.vkeys().get(0).vkey().public_key().verify(tx, witness.vkeys().get(0).signature()))


text:
minted NFT is shown as solid color of picture in Nami wallet
I have some questions about NFT mint.
I minted NFT using Nami Wallet API, but sometimes error occurred.

I need to mint several NFTs at once. So I submit minting transactions in for loop.
But sometimes transactions make Utxo failure error. I think it's because the new transaction's Utxo input is not same as the old transacion's Utxo input. Help me to mint several NFTs at once.
And sometimes Minted NFT is shown as solid color picture in Nami wallet.
I checked that image in IPFS and it same as what I uploaded. But why Nami wallet can't include it?

Try to have the asset_name and name the same:
"asset_name": "TestNFT1",
"name": "TestNFT1",

For some reason, when they are different, Nami shows the solid color, in ccvault/Eternl works well with spaces.


text:
Convert xpub public key from ccvault to bech32 or acct_ public key
Trying to import my wallet into Koinly for tax-purposes and unfortunately it doesn't accept xpub public addresses.
They just recently added Cardano Native Tokens to their platform and they support act_ keys (and bech32?)
Just wondering if there's a way I can convert xpub to either an act_ key or a bech32-compatible key so I can import my ccvault wallet into Koinly.
I tried the bech32.exe program for Windows but I could not figure out how to use it or convert my public key.

You can use the bech32 command line software that comes preinstalled with cardano-wallet.
Install bech32 or cardano-wallet.
Here is an example:
Say I have an cc.xpub file from ccvault like this: xpub1vep8yyse8ja7yspv0ytjdu0rnk4ek08prkuvre6t76mwryp6cdq7azzd684psvm2j55qp2rhm3zpl0x7en96p2esnvfj905pax48czc7hc0f6
From your command line, run: cat cc.xpub | bech32 >> cc.b32 - this will output the bech32 format (in the above example, it would be 66427212193cbbe2402c791726f1e39dab9b3ce11db8c1e74bf6b6e1903ac341ee884dd1ea18336a952800a877dc441fbcdecccba0ab309b1322be81e9aa7c0b), and save it under the file cc.b32
Next, run: bech32 acct_xvk <<< $(cat cc.b32) >> cc.xvk
This will convert the bech32 encoded cc.b32 key into a cardano-wallet compatible acct_xvk, saved under the file cc.xvk
In the above example, the result is: acct_xvk1vep8yyse8ja7yspv0ytjdu0rnk4ek08prkuvre6t76mwryp6cdq7azzd684psvm2j55qp2rhm3zpl0x7en96p2esnvfj905pax48czcdg4029

This worked! Thank you very much! Can't upvote unfortunately due to low karma.


text:
Fetching exchange prices via an API?
Are there any APIs currently available that let you fetch Cardano native token prices without web-scraping?
SundaeSwap, ADAX, MuesliSwap, and MinSwap don't appear to have this functionality.
ErgoDEX may have it in the future but is there anything right now that works?
Just want to get the last known token prices for specific pairs. Doesn't matter if it's in ADA or USD.

MuesliSwap does provide some API endpoints that you could look into:
https://docs.muesliswap.com/cardano/api
There's a ticker that provides "24-hour pricing and volume summary for each market pair available on the exchange":
http://analytics.muesliswap.com/ticker
And you can also get more detailed historical price (or volume) data on each token, eg: https://analytics.muesliswap.com/price?policy-id=8a1cfae21368b8bebbbed9800fec304e95cce39a2a57dc35e2e3ebaa&tokenname=MILK&interval=hourly
Here's an example site powered by their API according to the docs: https://cardanoassets.com/

On how to get the number of decimals of a token to convert the pricing data:
I couldn't find that info in the MuesliSwap API, though it could still be hidden in there somewhere.
In general though that info can be derived from the metadata of the minting transaction, eg here:
https://cardanoscan.io/transaction/d74798c4a1e453fbc6ba4fbb1d785e0534fb8531fd1bc054ceff5b086240d3b5?tab=metadata
(Check under label "20", which is defined in CIP-38 here: https://github.com/cardano-foundation/CIPs/pull/137)
If you need to automatically get this info, one way would be to use a service like Blockfrost to query it.
Once you have the policy id and asset name (eg from the muesliswap api), you could use this endpoint to fetch the asset details, including the metadata with the decimals field:
https://cardano-mainnet.blockfrost.io/api/v0/assets/9a9693a9a37912a5097918f97918d15240c92ab729a0b7c4aa144d7753554e444145
(You'll need to convert the asset name "SUNDAE" from the MuesliSwap API to hex "53554e444145" and add it to the policy id)

Thank you. But some have very strange decimal numbers. For example SUNDAE_ADA: http://analytics.muesliswap.com/trades/9a9693a9a37912a5097918f97918d15240c92ab729a0b7c4aa144d77.SUNDAE_ADA
How do I fix the prices with these decimal points?

If you're in Javascript, you could simply call "toFixed()" on those numbers to convert the floating point to fixed point representations, eg "(2.5e-3).toFixed(4)" becomes "0.0025", if you want 4 decimal places; for those smaller numbers you'll need more decimal places (https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/toFixed)

But the problem is those aren't the correct prices. 2.5e-7 = 0.00000025 for the SUNDAE token. But the actual SUNDAE price on MuesliSwap is 0.25 ADA. Why is the price incorrect on the MuesliSwap api and how do I properly convert it?

Ah I see, okay thats because 1 SUNDAE has 6 decimals, so technically 1 SUNDAE is a million "tokens" (like 1 Ada is 1,000,000 Lovelace) - so you can just multiply the price by a million like so: (2.5e-7 * 1e6).toFixed(2) to get 0.25 (the actual SUNDAE price in Ada)

How do I automatically retrieve the number of decimals though?

Added the info to the answer above. There might be a better solution, but blockfrost definitely works for that. You'd probably just query this info once and store it on your end, so you should just need very few requests, ie one per token.

just to add, in case there's a token that doesn't follow the CIP-38 yet, you can also check the token registry here for the info https://github.com/cardano-foundation/cardano-token-registry/, eg here's the entry for SUNDAE: https://github.com/cardano-foundation/cardano-token-registry/blob/master/mappings/9a9693a9a37912a5097918f97918d15240c92ab729a0b7c4aa144d7753554e444145.json


text:
Create a smart contract in Marlowe from A to Z
What is the process of building a smart contract in Marlowe from start to deployment and first main net transaction? I know that there's blockly and Marlowe playground. But I can't figure out the step-by-step algo of doing it from the docs.
Here's what I want to build:
Bob deposits 100 iUSD Ann deposits 10 iUSD, if event "1" happens Ann gets 105 iUSD, Tom gets 5 iUSD else if event "2" happens Bob gets 100 iUSD, Tom gets 10 iUSD.
Events will be triggered in the frontend.
Thanks for help!

Guidance on building a Marlowe contract and running it on mainnet is split into two pieces because Marlowe is a blockchain-agnostic language but it is also implemented on Cardano. Playground lets one simulate Marlowe contracts in the abstract while Runtime lets one execute them concretely on the Cardano blockchain.

The Concepts tutorials teach the Marlowe language and walk through examples.
The Guides exemplify using the Marlowe Starter Kit, which is freely available on https://demeter.run/ for use without installing any software.

Regarding your specific example, the sixth lesson of the starter kit shows how to build a simple front end for a Marlowe contract.

I feel more comfortable using VS code on my PC than https://demeter.run/ I hope that doesn't break anything. I would be running smart contracts from frontend later anyway.
A very high level question correct me if I'm wrong. Smart-contract building algo looks something like this:

Build SC in Blockly.
Test SC in Runtime.
Import it into the App bundle
Production build
Deploy optimized bundle to prod server.

Demeter Run provides convenience, but the starter kit and other examples should work fine if one is using a local Marlowe Runtime or some other service provider.


text:
ADA handle NFT royalty address
Is it possible to use an ADA handle as the address for NFT royalties? I’d like a way of changing the address that royalties get sent to if I decide to sell my project in the future. Maybe it would be possible to do this through a smart contract instead?

This is possible. You can make a script address where royalties are send to with an Ada handle in the datum. The script only permits grabbing those funds if the corresponding ada handle is part of the transaction.
With the upcoming HF (cip 31) you can even make it so that the script can allow grabbing by anyone as long as the destination of the funds are the same as the referenced utxo that contains the ada handle. Hope this helps.

AdaHandles are used to query the blockchain with either Block Frost or DB-Sync to find the wallet containing the NFT, in this case it would depend on how the marketplace uses the metadata in the CIP-27 royalty token.


text:
Reactivate Retired Stake Pool
If I still have all the keys is it possible to reactivate a stake pool that was previously retired?

All you need is the cold key to reactivate a stake pool. The rest can be replaced. If you have all the keys and you want to reuse them, you can. But only the cold skey matters.
I assume you will need to pay attention to the counter for the operational certificate. You will need to have a bigger counter (preferably +1) for the operational certificate than the one used to mint the last block.


text:
Will stakepool rewards statistically even out over time if I run a pool with a small stake?
If I start a pool with a large pledge of around 170k ADA but I struggle to get people to stake to my pool and I just end up having only the 170k pledge of ADA staked to the pool the entire time the pool is run will the rewards I earn eventually make running a pool worthwhile?
I'm thinking long term, like 5-10 years, and not considering the costs of running the pool such as electricity, equipment, and an internet bill. I'm just comparing running a stakepool with a large stake to just staking it in an already well performing pool.
I think I'd like to take the chance of running a pool but I don't want to sink my bag into a pool that makes me nothing if I could have it in a larger pool and earn rewards.
Also, I realize that cardano.org has a calculator for calculating stake pool rewards but it doesn’t give much indication on what rewards would be for smaller stakes.

The rewards of staking on Cardano are, on average, 5% APY.
At the moment, a pool with 170K ADA of stake has a 12.89% chance of producing a block per epoch (you can check the "Rewards" tab of this pool for reference, as it has that same amount of stake: https://adapools.org/pool/34736425217f45cc1f6e59a88bd253e50b90f47ea206ec7f26afdfc5). This means that, to produce a block every epoch, you need to have a stake of 1.4M ADA at least.
In your case, and probabillistically, you'll be signing a block every 7.75 epochs (1 epoch has 5 days in Cardano's blockchain). One year has 73 epochs, so you will be signing a block in 9.41 of those epochs. Every epoch you mint a block, as an operator, you'll get 340 ADA on top of your rewards (this is the most usual fixed fee for SPOs).
I run a stake pool and I can assure you that, if you won't be promoting it or at least trying to get more delegators to join your pool, then I reckon that with that amount of stake it's better for you to join a pool. I would consider running my own pool without caring about delegators at least with a chance of 50% of minting a block each epoch. But this is just my opinion.

Would the rewards and pool fees I would receive every 7.75 epochs equal or exceed the rewards of just staking?

That's not something I can answer straight away as there are so many variables in play and the performance of your pool is one of those. As per this website (https://cardanode.com.au/cardano-staking-calculator-rewards-ada/) you'll be getting 8,713.0276 ADA each year staking on a 5% APY pool. The rewards you will receive if you mint a block in an epoch will exceed the rewards of just staking BUT you need to consider the costs of running the pool (servers) and the time you'll have to dedicate to maintain it. In my experience as an SPO, it's not profitable to run a stake pool with only 170K ADA.


text:
How to differentiate NFTs of the same policy id?
For Example:
You have an NFT collection that has 5 different tiers all under the same policy ID (cip-25 metadata standard). You want to be able to provide on-chain benefits to holders of the NFT dependent on the tier they hold.
Because each tier shares the same policy ID what is the easiest way to categorize and reward the different tiers?
The solution that comes to my mind is having 1 piece of the NFTs metadata mention its tier, then using blockfrost to take a policy ID snapshot that sorts by tier name.

You can add custom metadata to your NFT. The most used standard is CIP-721.
The metadata could look like this:
{
  "721": {
    "<policy_id>": {
      "<asset_name>": {
        "name": <string>,
        "image": <uri | array>,
        "tier": 1
      }
    }
  }
}

As you mentioned you could then use an API like blockfrost or Koios to get the metadata, check the tier property and do whatever you want with that information.

Brilliant! This seems like the perfect solution to go with.
I will take a look at the blockfrost docs and see the best way to do so. If you happen to know any open source code or a good pre-built tool for this that would be fantastic!
Thank you for the help!

You could build a Merkle tree of asset names for each tier and encode the root hash in the smart contract.
In the redeemer you give the correct intermediate hashes (public), compute the root hash and verify with the tier root hash.

Ok fantastic! I appreciate this advice.
I think we are staying away from smart contracts on this one and just using NMKR for the minting side of things.
Where the more code intensive side of things come into play will be around differentiating asset types and then rewarding.

Definitely easier to start without smart contracts and do this with a backend / multi-sig instead. Something like a merkle tree based solution could still be added later.


text:
Is there an API for Cardano Blockchain Insights?
I'm looking for any API or any source that would allow me to export data & statistics?
(Specifically Blockchain load per day)
I found that DataStudio has stats, yet it doesn't have any export options.
And I found that Blockfrost also has an API but I didn't find Blockchain load per day option there.
Cheers

You should upvote the answer when you accept it.

@gRebel I don't have enough reputation to upvote answers, however I did tag it as accepted answer.

If you don't want to run a node or services yourself you can use https://api.koios.rest/#overview
If you run your own node or are friendly with someone who does you can use DB-Sync.
DB-Sync is a PostgreSQL relational DB of Cardano blockchain data.
You can query it using standard SQL.
DB-Sync:
https://github.com/input-output-hk/cardano-db-sync
DB Schema:
https://github.com/input-output-hk/cardano-db-sync/blob/master/doc/schema.md
Example queries:
https://github.com/input-output-hk/cardano-db-sync/blob/master/doc/interesting-queries.md
Docs:
https://docs.cardano.org/cardano-components/cardano-db-sync

Thanks a lot :)


text:
How to get blockchain block load from blockfrost?
I'm currently going through Blockfrost documentation and trying to figure out if there is a way to fetch block load for each day.
Seems like they don't have such option, in that case: Is there a way to calculate block load?

No Blockfrost endpoint retrieves this information.
As per this tweet, the current size of blocks is 88KB.
So, you can calculate the % of block load for each block this way:
( cardano_node_metrics_blockfetchclient_blocksize / (88 * 1024) ) * 100

cardano_node_metrics_blockfetchclient_blocksize is a metric exposed by Prometheus in the cardano-node. You can query it using Grafana. Unfortunately, you will need to run your own node for this.
This is a very useful link on how to setup the Grafana Dashboard: https://developers.cardano.org/docs/stake-pool-course/handbook/grafana-dashboard-tutorial/

Thank you! However, there is no APIs that will not require to run node? I assume I just need to fetch size of the block and then make calculations myself

The problem is that, in order to fetch the size of the block (cardano_node_metrics_blockfetchclient_blocksize), you need to use Grafana. And Grafana is a tool made to monitor your own node: you can't plug it to an API.

Since you're looking for a way without running a node, example using Koios (am sure blockfrost offers similar endpoints too):

Max size of block from current protocol can be found using epoch_params

I am not sure if I fully understand the term block load , but I assume you mean average size of blocks for a specific time range. You can get a filtered list of size and time using blocks endpoint, the list is - ofcourse - paginated, which you can find an average of.
Sample: here


text:
Rust Serialization Lib Minting NFT - Missing Key Witnesses Error on Submission
I am running into an error with the CSL Rust Lib when submitting a minting NFT tx.  I am following a minimal example in JS https://gist.github.com/lovalabs/83d08796ab9ff65cbf188fbca8d03343 as a guide for the RUST library.  I receive the following error when attempting to submit the built tx via the cardano-CLI:
Error: Error while submitting tx: ShelleyTxValidationError ShelleyBasedEraAlonzo (ApplyTxError [UtxowFailure (WrappedShelleyEraFailure (MissingScriptWitnessesUTXOW (fromList [ScriptHash "d47c1b40ca47ac8f1b0c0f01941acbc634dbd5896239a2ade9548557"]))),UtxowFailure (WrappedShelleyEraFailure (UtxoFailure (UtxosFailure (CollectErrors [NoRedeemer (Minting (PolicyID {policyID = ScriptHash "d47c1b40ca47ac8f1b0c0f01941acbc634dbd5896239a2ade9548557"})),NoWitness (ScriptHash "d47c1b40ca47ac8f1b0c0f01941acbc634dbd5896239a2ade9548557")]))))])

My RUST declarations are as follows:
Policy NativeScripts
 //Initialize 'NativeScript' for NFT Policy
    let mut native_scripts = NativeScripts::new();
    let script_public_key = NativeScript::new_script_pubkey(&ScriptPubkey::new(&policy_public_key_hash));

    //Initialize 'TimelockExpiry' and 'NativeScript'
    let timelock_expiry_fmt = TimelockExpiry::new_timelockexpiry(&BigNum::from_str("59634480").unwrap());
    let script_timelock = NativeScript::new_timelock_expiry(&timelock_expiry_fmt);

    //Add Public Key and Timelock 'NativeScript' to Collection of 'NativeScripts'
    native_scripts.add(&script_public_key);
    native_scripts.add(&script_timelock);

    //Initialize 'ScriptAll' type of 'NativeScript' & Add 'NativeScripts' with script public key and timelock expiry
    let policy_script = NativeScript::new_script_all(&ScriptAll::new(&native_scripts));

    //Initialize 'PolicyID', 'AssetName', and 'Amount'
    let asset_name = AssetName::new("Rust-CSL-NFT-Mint".as_bytes().to_vec()).unwrap();
    let amount = Int::new(&BigNum::from_str("1").unwrap());

Builder & Witnesses
//Add 'NativeScript', 'AssetName', 'Amount' (Int), and 'TransactionOutputAmountBuilder' to 'TransactionBuilder'
    tx_builder.add_mint_asset_and_output_min_required_coin(&policy_script, &asset_name, amount, &tx_output_amount_builder).unwrap();

    //Set 'ttl' for 'Transaction'
    tx_builder.set_ttl_bignum(&BigNum::from_str("59634480").unwrap());

    //Add 'TransactionInputs'
    tx_builder.add_key_input(&input_public_key_hash, &tx_input_1, &tx_value);

    //Add Change Wallet
    tx_builder.add_change_if_needed(&addr_1).unwrap();

    //Build Transaction
    let transaction = tx_builder.build_tx().unwrap();

    //Set 'TransactionWitnessSet'
    let mut vkey_witnesses: Vkeywitnesses = Vkeywitnesses::new();
    let tx_hash = hash_transaction(&transaction.body());
    let vkey_witness_wallet = make_vkey_witness(&tx_hash, &input_private_key);
    let vkey_witness_policy = make_vkey_witness(&tx_hash, &policy_private_key);
    vkey_witnesses.add(&vkey_witness_wallet);
    vkey_witnesses.add(&vkey_witness_policy);
    let mut tx_witness_set = TransactionWitnessSet::new();
    tx_witness_set.set_vkeys(&vkey_witnesses);
    tx_witness_set.set_native_scripts(&native_scripts);

    //Sign Transaction
    let signed_transaction = Transaction::new(&transaction.body(), &tx_witness_set, None);

I hope that I am missing something simple here.  I have added the input and policy keys as witnesses and I have added the policy nativescripts to the tx_witness_set but have not had any success resolving the error.  There is more than enough Test Ada in the utxo and I understand that the add_mint_asset_and_output_min_required_coin() handles the min fee and defines the PolicyID associated with the tx.  Any help or guidance is greatly appreciated as I have not found any rust tutorials or examples for the CSL.

I was able to complete the NFT Minting successfully following a different JS demo as a reference https://github.com/Emurgo/cardano-serialization-lib/blob/master/doc/getting-started/minting-nfts.md There are zero RUST examples online for using the Cardano Serialization Library so I will post the code for any future Rustaceans in search of help.
//------------------------------------------NFT Policy------------------------------------------
    //Initialize 'NativeScript' for NFT Policy
    let mut native_scripts = NativeScripts::new();

    //let script_public_key = NativeScript::new_script_pubkey(&ScriptPubkey::new(&policy_public_key_hash));
    let policy_addr = BaseAddress::new(NetworkInfo::testnet().network_id(), &StakeCredential::from_keyhash(&policy_public_key_hash), &StakeCredential::from_keyhash(&policy_public_key_hash)).to_address();
    let policy_keyhash = BaseAddress::from_address(&policy_addr).unwrap().payment_cred().to_keyhash().unwrap();
    let key_hash_script = NativeScript::new_script_pubkey(&ScriptPubkey::new(&policy_keyhash));
    native_scripts.add(&key_hash_script);

    //Initialize 'TimelockExpiry' and 'NativeScript'
    let timelock_expiry_fmt = TimelockExpiry::new_timelockexpiry(&BigNum::from_str("59634480").unwrap());
    let script_timelock = NativeScript::new_timelock_expiry(&timelock_expiry_fmt);
    native_scripts.add(&script_timelock);

    let mint_script = NativeScript::new_script_all(&ScriptAll::new(&native_scripts));

    let addr = BaseAddress::new(NetworkInfo::testnet().network_id(), &StakeCredential::from_keyhash(&input_public_key_hash), &StakeCredential::from_keyhash(&input_public_key_hash)).to_address();
    let private_key_hash = BaseAddress::from_address(&addr).unwrap().payment_cred().to_keyhash().unwrap();

 //--------------------------------------Transaction Builder--------------------------------------
    //Initialize 'TransactionBuilder' from 'TransactionBuilderConfig'
    let mut tx_builder = TransactionBuilder::new(&tx_builder_config);

    //Add 'TransactionInputs'
    tx_builder.add_key_input(&private_key_hash, &tx_input_1, &tx_value);

    //Initialize 'PolicyID', 'AssetName', and 'Amount'
    let asset_name = AssetName::new("Rust-CSL-NFT-Mint".as_bytes().to_vec()).unwrap();
    let amount = Int::new(&BigNum::from_str("1").unwrap());

//------------------------------------Outputs (Wallet Addresses)---------------------------------
     //Initialize 'TransactionOutputAmountBuilder' from 'TransactionOutputBuilder'
     let tx_output_builder = TransactionOutputBuilder::new();
     let tx_output_amount_builder = tx_output_builder.with_address(&addr).next().unwrap();

    //Add 'NativeScript', 'AssetName', 'Amount' (Int), and 'TransactionOutputAmountBuilder' to 'TransactionBuilder'
    tx_builder.add_mint_asset_and_output_min_required_coin(&mint_script, &asset_name, amount, &tx_output_amount_builder).unwrap();

    //------------------------------------------NFT METADATA------------------------------------------
    //Generate Policy ID and Metadata
    let _policy_id = hex::encode(mint_script.hash().to_bytes());
    let metadata_input_string = String::from("{\"[d47c1b40ca47ac8f1b0c0f01941acbc634dbd5896239a2ade9548557]\": {\"[Rust-CSL-NFT-Mint]\": {\"name\": \"Rust-CSL-NFT-Mint-Example\",\"description\": \"Rust CSL NFT\",\"image\": \"bafkreibsko7qh472qkkwmk6fcfhbrhiuvzna5fkqzvak7gvgqosasaubi4\",\"type\": \"image\"}}}");
    let metadata = encode_json_str_to_metadatum(metadata_input_string.clone(), csl::metadata::MetadataJsonSchema::BasicConversions).expect("encode failed");
    let metadata_output_string = decode_metadatum_to_json_str(&metadata, csl::metadata::MetadataJsonSchema::BasicConversions).expect("decode failed");
    //println!("{}", metadata_output_string);

    //Set 'ttl' for 'Transaction'
    tx_builder.set_ttl_bignum(&BigNum::from_str("59634480").unwrap());

    //Set NFT 'MeatadatumLabel' (721)
    tx_builder.add_json_metadatum(&BigNum::from_str("721").unwrap(),metadata_output_string).unwrap();

        //Add Change Wallet
    tx_builder.add_change_if_needed(&addr).unwrap();

    let tx_body = tx_builder.build().unwrap();
    let tx_hash = hash_transaction(&tx_body);
    //println!("{:?}", hex::encode(&tx_hash.to_bytes()));

    let mut tx_witness_set = TransactionWitnessSet::new();
    let mut vkey_witnesses: Vkeywitnesses = Vkeywitnesses::new();
    vkey_witnesses.add(&make_vkey_witness(&tx_hash, &policy_private_key));
    vkey_witnesses.add(&make_vkey_witness(&tx_hash, &input_private_key));
    tx_witness_set.set_vkeys(&vkey_witnesses);
    tx_witness_set.set_native_scripts(&native_scripts);

    let mut witness_scripts = NativeScripts::new();
    witness_scripts.add(&mint_script);
    tx_witness_set.set_native_scripts(&witness_scripts);

    let unsigned_transaction = tx_builder.build_tx().unwrap();

    let signed_transaction = Transaction::new(&unsigned_transaction.body(), &tx_witness_set, unsigned_transaction.auxiliary_data());

https://explorer.cardano-testnet.iohkdev.io/en/address.html?address=addr_test1qpus2z0svc6n6dv64cryzdc695430lpkqvk5dsp6lltn8zteq5ylqe34856e4tsxgym35tftzl7rvqedgmqr4l7hxwys99g6gw
Hope this is useful for someone, I spent awhile searching for RUST examples and came up empty-handed.


text:
blockfrost.io API, reference inputs and redeemer tx_index
AIUI, when using the blockfrost.io API, the tx_index field in a redeemer contains the index of the enclosing transaction's input that it consumes (is that true ?).
However, with reference inputs, it seems that in this API the reference inputs and "regular" inputs are all merged in the transaction's utxos.inputs list.
In that case, it looks the tx_index field in the redeemer no longer matches the index of the referenced input in the inputs list, but rather the position of the Nth non-reference input in the list.
Example:

without reference inputs:

utxos.inputs = [i1,i2,i3]`
redeemer.tx_index=2

In that case, the redeemer points at i3

with reference inputs (marked as ri):

utxos.inputs = [ri1, ri2, i1,i2,i3]`
redeemer.tx_index=2

In that case, the redeemer also points at i3 because the reference inputs are ignored in the indexing.
Can someone confirm that this understanding is correct, or provide the correct way of interpreting the redeemer's tx_index field ?

AIUI, when using the blockfrost.io API, the tx_index field in a redeemer contains the index of the enclosing transaction's input that it consumes (is that true ?).

The index holds different meaning for different purposes. For instance, if minting policies are involved in a transaction, index for a particular minting policy would be it's position in lexicographic ordering of the involved minting policies. For more information, see indexOf function in Alonzo ledger documentation. So, if you are only looking for indexes where purpose in response is set to spend then your understanding of tx_index is correct.
Now any output which is inside transaction_input then it is indeed getting consumed by the transaction (if it is of course successful), reference input(s) cannot be inside this transaction_input list. Provider's might mention it in input(s) but then they would also mention whether it's a reference input (in which case you can ignore it) or not. So, yes, your understanding on ignoring reference input(s) to determine for index is correct.


text:
Is it possible for clients to mint my nft collection on their own?
For eth:
Create smart contract minter

Deploy that contract into the blockchain

Make API calls on that deployed contract thru your website

Client will click mint button -> API mint interaction to smart contract

As for cardano this is seemingly complex, this is my understanding so far (are they correct?)
Cardano node must be running on your machine

Interact with node using cardano cli, start minting at this point

Get all minted token and start distributing it to people

With this I am the one minting all of the tokens and distribute it to people, is there a way to do it like in eth?

You don't need to run your own node, if you don't want to. You can always use an API service like Blockfrost to interact with the blockchain instead. This is also how light wallets like MetaMask, Nami wallet etc. read on-chain data and submit transactions. You can use such a service on your own backend, too.
As for minting and distributing there are many ways you can go about. Cardano is special in that you don't even need smart contracts for minting, which makes it much easier.
You also don't need to pre-mint; you can mint on-demand. So without using smart contracts, but with your own backend service running, a setup could look like this:
When the buyer hits the buy button:

Generate a minting transaction that needs to be signed by both, you (your backend service) and the buyer (eg using this lib: https://github.com/Emurgo/cardano-serialization-lib/blob/4f1d87524be5e792baabb038d15ca60cd2d39edb/doc/getting-started/minting-nfts.md)
Once the buyer signs the transaction (eg via Nami wallet), have it passed to your backend for verification, signing and submission to the network (eg via Blockfrost)

Within that single transaction you can have:

User mint NFT into their own wallet
User pays you amount x for the NFT
User pays for network fee

(You can of course also use smart contracts for minting / distributin of your NFTs; the articles in this answer might help you get started: https://cardano.stackexchange.com/a/4426/4627)

It seems that blockfrost doesn't have any apis for minting. https://cardano.stackexchange.com/questions/3726/minting-a-nft-collection-with-blockfrost

You mint a token by submitting a „minting transaction“ through the  tx submit endpoint. That transaction needs to be created either in the browser or in your backend beforehand.

I am not sure, why you need the NFT creation to be signed by your backend. The NFT belongs to the person who is minting and hence being signed by him should be enough or not ? Or else we are centralising the whole thing and adds extra unnecessary work. Pls correct me ... with arguments.

The question is about an "nft collection" owned by the op, and such a collection usually shares the same minting policy, so you can verify authenticity (check which nft really belongs to this original collection). This policy would usually restrict who can mint nfts that belong to this collection and hence you'd likely have a central authority providing this signature (the key for this should be kept safely on the backend). Technically though you're right in that you can mint nfts also in the wild without any such measure.

But is imposible to add random characters image with this right? since user can see tha transaction that they are signing... unless using some source of randomless... wich i currently do not know any...

Yea that’s right. Depending on your use case one idea to solve for randomness could be to sell a „random“ lottery ticket token first and have that secretly tied to an NFT that the user can claim in a second transaction


text:
Possible to run cardano-node on marlowe pioneer testnet using docker-compose
I wanted to run the cardano-node, marlowe pioneer testnet on Ubuntu using docker.
wget https://raw.githubusercontent.com/input-output-hk/cardano-wallet/master/docker-compose.yml
NETWORK=???????? docker-compose up -d

Anyone know what NETWORK we can use to access the pioneer testnet ?
I only know mainnet, testnet
this could imply that we use some sort of private testnet ?
sidenote:
I would like to know if we can do all these course material using mainnet too perhaps,
that would lean close towards the real use of smart-contracts deployment and utilization ?

In the context of this marlowe pioneer program this question is irrelevant.
There is a nix-shell environment that you can use instead.
setup your Ubuntu OS
sudo apt update && sudo apt upgrade -y
sudo apt install curl xz-utils -y

sh <(curl -L https://nixos.org/nix/install) --daemon
nix-shell -p nix-info --run "nix-info -m"
nix-env --version

sudo vi /etc/nix/nix.conf
# add the following content to the end of the file and save

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

sudo systemctl restart nix-daemon.service

download and startup nix-shell with marlowe tools
git clone https://github.com/input-output-hk/marlowe-cardano.git
cd marlowe-cardano
git checkout marlowe-pioneers
nix-shell
start-marlowe-run

Notice you now have a tmux multiple windows system syncing, wait for it to finish
You can find the node.socket with
sudo find / -name '*node.socket'

then setup with
export CARDANO_NODE_SOCKET_PATH=/tmp/node.socket
export CARDANO_TESTNET_MAGIC=1567

My advice is that the docker-compose solution is only working for a specific set of networks only: mainnet or testnet
These only include cardano-cli and cardano-wallet
Then you can use the binary executable files from the proper nix-shell paths that can be found here:
sudo find /nix/store -wholename '*/bin/cardano-cli'
sudo find /nix/store -wholename '*/bin/marlowe-cli'
sudo find /nix/store -wholename '*/bin/cardano-wallet'

I assume you're looking for marlowe-pioneers (reference here ).
I am not a big fan of docker/nix myself (for not so "micro" services) - so not testing it out beforehand, but that should be the right ID. If you'd want to look at configs/genesis/topology files yourself, you can find them here.

owh interesting
I tried but get this
service "cardano-node" refers to undefined volume node-marlowe-pioneers-db: invalid compose project```
owh ok I see the docker compose file is not including the marlowe-pioneers db

Ye - shouldn't be too difficult to customise to other networks, can update those configs/genesis mounts seperately

NETWORK=???
Get's translated, to the "magic-id" parameter in the cardano-cli.
The number you are looking for is 1567
And we will look at it in more detail in Lecture 7 "marlowe-cli"

Marlowe CLI requires access to a Cardano node,
I don't want to use Daedalus but use a docker-compose hosted cardano-node and cardano-wallet on mainnet and marlowe-pioneer testnet in order to manipulate transactions and wallets using python. It works on python for the mainnet, but I don't know how to get it to work on any other testnet ?
Your response as far as setting up a mart contract is probably correct but not in line with my current problem

[myVM01:cardano.node.DnsSubscription:Warning:53] [2022-06-08 17:03:28.32 UTC] Domain: "relays.marlowe-pioneers.dev.cardano.org" Failed to start all required subscriptions
[myVM01:cardano.node.DnsSubscription:Debug:53] [2022-06-08 17:03:29.33 UTC] Domain: "relays.marlowe-pioneers.dev.cardano.org" Restarting Subscription after 1.26569077s desired valency 2 current valency 0
[myVM01:cardano.node.DnsSubscription:Debug:53] [2022-06-08 17:03:38.06 UTC] Domain: "relays.marlowe-pioneers.dev.cardano.org" Starting Subscription Worker, valency 2

Let's try to edit the code below for it to work perhaps
original docker-compose from github copied below for editing
(problem is that the docker image does not have the config file)
[STATUS: editing, not yet working]
version: "3.5"

services:
  cardano-node:
    image: inputoutput/cardano-node:1.34.1
    environment:
      NETWORK:
    volumes:
      - node-${NETWORK}-db:/data
      - node-ipc:/ipc
    restart: on-failure
    logging:
      driver: "json-file"
      options:
        compress: "true"
        max-file: "10"
        max-size: "50m"

  cardano-wallet:
    image: inputoutput/cardano-wallet:2022.5.27
    volumes:
      - wallet-${NETWORK}-db:/wallet-db
      - node-ipc:/ipc
    ports:
      - 8090:8090
    entrypoint: []
    command: bash -c "
        ([[ $$NETWORK == \"mainnet\" ]] && $$CMD --mainnet) ||
        ([[ $$NETWORK == \"marlowe-pioneers\" ]] && $$CMD --testnet /config/${NETWORK}/marlowe-pioneers-byron-genesis.json) ||
        ($$CMD --testnet /config/${NETWORK}/genesis-byron.json)
      "
    environment:
      CMD: "cardano-wallet serve --node-socket /ipc/node.socket --database /wallet-db --listen-address 0.0.0.0"
      NETWORK:
    restart: on-failure
    logging:
      driver: "json-file"
      options:
        compress: "true"
        max-file: "10"
        max-size: "50m"

volumes:
  node-mainnet-db:
  node-testnet-db:
  node-alonzo-purple-db:
  node-marlowe-pioneers-db:
  wallet-mainnet-db:
  wallet-testnet-db:
  wallet-alonzo-purple-db:
  wallet-marlowe-pioneers-db:
  node-ipc:
  node-config:

cardano-cardano-node-1    | [Error] Managed configuration for network marlowe-pioneers does not exist

cardano-cardano-wallet-1  | [cardano-wallet.main:Error:4] [2022-06-07 12:25:19.71 UTC] Failed to parse Byron genesis configuration. You may want to check the filepath given via --genesis and make sure it points to a  valid JSON Byron genesis file. The genesis file must be Byron, not Shelley as it used to feed the wallet with the initial blockchain parameters. Here's (perhaps) some helpful hint: GenesisDataIOError /config/marlowe-pioneers/genesis-byron.json: openBinaryFile: does not exist (No such file or directory)

Hello, Due to the nature of StackExchange (posting possible answers to questions and fixes to the problem) the current state of your response it not suitable to this site. Its more of a github issue post conversation or a blog type post. I would suggest submitting it to one of those sites or changing it to highlight that the reason you don't belive its possible is the lack of the config file. Also if this is made during the time your still working on an answer please finish testing things locally and update the post to include all the result and be written in the form of an direct answer.

I agree, I will think about cleaning up this question, since I have been playing with nix-shell instead, you can only use this docker-compose file for mainnet and public testnet nothing else. And trying to get the marlowe-pioneer node running fails because the topology file has a wrong relay hostname.
https://hydra.iohk.io/build/14528927/download/1/index.html
docker run -p 127.0.0.1:3001:3001 --volume $PWD/configuration:/configuration inputoutput/cardano-node run --topology /configuration/marlowe-pioneers-topology.json --config /configuration/marlowe-pioneers-config.json


text:
PPViewHashesDon'tMatch Exception on submit transaction for Cardano serialization-lib version 10.0.x
On emurgo/cardano serialization versions 10.0.X receiving error on submit transaction that:
https://drive.google.com/file/d/1SNpM1LtEDPnZPMQXdz1X_Ujiy_FW9BJW/view?usp=sharing
Also, in emurgo/cardano-serialization version 10.2.0 there is a function in TransactionBulderConfigBuilder.ex_unit_prices() that takes ExUnitPrices Instance, what is the numerator and denominator in ExUnitPrices.new() function, how can one calculates them?

Hello, beacuse this is your first question I have been asked by the site to review it. It seems there are two questions here and they are not tightly related. In addition if the first question requires a lot to answer the second one might be drowned by the first. It might be better to separate the two into 2 questions.


text:
GraphQL syncing takes too much time
Hello everyone I did follow this guide to run GraphQL with docker-compose: https://github.com/input-output-hk/cardano-graphql
However, inputoutput/cardano-db-sync:12.0.0 is syncing super slow
CONTAINER ID   IMAGE                                                 COMMAND                  CREATED        STATUS                PORTS                                                                       NAMES
ad0aea43554e   inputoutput/cardano-db-sync:12.0.0                    "/nix/store/5ghw8rqx…"   28 hours ago   Up 28 hours                                                                                cardano-graphql_cardano-db-sync-extended_1
23ebbe6aeed1   inputoutput/cardano-graphql-hasura:6.2.0              "docker-entrypoint.s…"   5 days ago     Up 5 days             0.0.0.0:8090->8080/tcp, :::8090->8080/tcp                                   cardano-graphql_hasura_1
fb2d31b115f3   postgres:11.5-alpine                                  "docker-entrypoint.s…"   5 days ago     Up 5 days             0.0.0.0:5432->5432/tcp, :::5432->5432/tcp                                   cardano-graphql_postgres_1
537147f0d16a   inputoutput/cardano-graphql:6.2.0-mainnet             "node index.js"          5 days ago     Up 28 hours           0.0.0.0:3100->3100/tcp, :::3100->3100/tcp                                   cardano-graphql_cardano-graphql_1
7c47cba2732c   cardanosolutions/cardano-node-ogmios:v5.1.0-mainnet   "/root/cardano-node-…"   5 days ago     Up 5 days (healthy)   3000/tcp, 12788/tcp, 0.0.0.0:1337->1337/tcp, :::1337->1337/tcp, 12798/tcp   cardano-graphql_cardano-node-ogmios_1

I did check the CPU and Memory usage CPUs are at 30% usage and RAM is 27.7/32GB.
After 28 hours it's still at 36.65% and gets slower (it was going faster at the beginning).
{
    "data": {
        "cardanoDbMeta": {
            "initialized": false,
            "syncPercentage": 36.65
        }
    }
}

This is how I start docker I was getting errors so removed RESTORE_SNAPSHOT parameter to retrieve it from the genesis. (I don't know whether the problem is related with it or not).
export NETWORK=mainnet &&\
docker pull inputoutput/cardano-graphql:6.2.0-${NETWORK} &&\
docker pull inputoutput/cardano-graphql-hasura:6.2.0 &&\
docker pull cardanosolutions/cardano-node-ogmios:v5.1.0-${NETWORK} &&\
docker-compose up -d &&\
docker-compose logs -f

The typical question for this would have been, what is your node and dbsync status, has it gone through a crash recently, etc. But use of < 6 GB out of 32 sounds like your node itself is not yet in sync , atleast as of the time you created the post.
Thus, the question instead would be - What are your baseline expectations for time it'd take to sync node and then dbsync? I'd expect it to take more than a day (perhaps 1.5-2.5) to sync node alone, and then depending on your IO throughput (check db sync sys requirements ), it could take further. The time taken for a particular epoch may be longer gradually as the chain adoption and use cases increase.
Furthermore, if you have restarts/crash during the sync process, it can make your experience substantially worse.
Lastly, when using Snapshots before, you were downloading an already synched to recent epoch snapshot of underlying Postgres DB, but if your node is behind DBSync by few epochs, this could also end up rolling back your DB instead of synching further.

The node is in sync right now but after 47 hours db is still at 39.66% I mean yesterday it came from 0 to 34 in 24 hours but now 5% in 23 hours. Is there anything I can do? Should I try to start with restore snapshots? Thank you for your assistance sir.

You can start by checking DBSync logs, uptime of pod/containers (if there was a restart, you'd be adding more hours every time), measure actual IOPs - if it matches upstream.
To be sure, you mean your node wasnt in sync yesterday, but has caught up now - is that correct?
Assuming the tip % is calculated in slots, for the first 34% you were actually in Byron era - which had 21600 slots per epoch (5 days), and much simpler. With shelley, you have 432000 slots per epoch, thus % distribution (besides, gradually staking, assets, scripts got unlocked) - so sync would be much slower from there on.

The node is in sync for 5 days. Is there any difference in terms of speed for Byron and Shelley? or is it just the epoch size that makes it look way slower?

Here is the logs of db-sync: https://imgur.com/jGVX1Ha

node is in sync for 5 days
The resource consumption in OP suggests otherwise.

the epoch size that makes it look way slower
Tip based % is slower as explained in previous reply.

Logs: Last extract of dbsync image is not exactly helpful.
Also, parts of initial reply (eg: actual IOPs requirements) are still to be answered.
We often see docker users hit such issues w/resource sizing or gaining app ops experience to troubleshooting individual components - usually more suitable candidates for discord/tg platforms instead of SE (which works for Q&A/discussion formats).

Sir it's been 3 days since db is syncing and it's still at 52.16% it was 55.20% yesterday. It's moving super slow and lags behind instead of going forward. How long will it take? Will it get faster after some point? I really didn't understand whats the problem.

Just waiting without addressing the other points mentioned in replies above will likely not help you much


text:
Running db-sync via CLI
While running the db-sync what to pass as a parameters is unclear.
PGPASSFILE=config/pgpass-mainnet cabal run cardano-db-sync -- \
    --config config/mainnet-config.yaml \
    --socket-path /home/ubuntu/cardano/cardano-src/cardano-node/data/node.socket \
    --state-dir /home/ubuntu/cardano/cardano-src/cardano-node/data/ledger \
    --schema-dir schema/ \
    --disable-ledger

What should I pass to --state-dir? I did pass ledger folder where my node stores data.
I'm going to subscribe blocks to read information such as from & to addresses, amount etc. If I pass --disable-ledger would it be a problem?
While running db-sync I'd like to pass the latest snapshot in here how do I pass it? (https://update-cardano-mainnet.iohk.io/cardano-db-sync/index.html#13/)
How do I pass port which db-sync runs? When I was running it via docker it was 3100 by default.

Thanks in advance!

What should I pass to --state-dir? I did pass ledger folder where my node stores data.

This should not be the same as any directory the node uses. Its for db-sync and related programs only.

I'm going to subscribe blocks to read information such as from & to addresses, amount etc. If I pass --disable-ledger would it be a problem?

This is documented. --disable-ledger means you will get all on-chain data but you don't get reward payments from the reward account associated with each address (until after they have been withdrawn), you don't get the epoch stake distribution and a couple of other minor things.

While running db-sync I'd like to pass the latest snapshot in here how do I pass it?

Its documented. You make sure db-sync is not running, restore the snapshot, then you run db-sync.

How do I pass port which db-sync runs?

Port for what? The PostgreSQL port for accessing the database? That is set by the PostgreSQL configuration.


text:
Syncing from genesis instead of snapshot
I start the docker as followed in the guide:
export NETWORK=mainnet &&\
docker pull inputoutput/cardano-graphql:6.2.0-${NETWORK} &&\
docker pull inputoutput/cardano-graphql-hasura:6.2.0 &&\
docker pull cardanosolutions/cardano-node-ogmios:v5.1.0-${NETWORK} &&\
RESTORE_SNAPSHOT=https://update-cardano-mainnet.iohk.io/cardano-db-sync/13/db-sync-snapshot-schema-13-block-7519843-x86_64.tgz \
docker-compose up -d &&\
docker-compose logs -f

However, db-sync didn't start from a point where I passed as a RESTORE_SNAPSHOT parameter instead started at 0 to sync from genesis which takes too much time to get sync. Any recommendations? If I keep waiting to make it sync via genesis probably will last 2-3 weeks.

Rolling back to genesis like this can be due to 3 reasons: the node is not synced, the node and db-sync are running on different networks or wrong/missing ledger state directory.

What you mean by node is not Ogmios right? I mean my node and db-sync are running on same computer in different screens and it's sync. However, I did not pass any parameter while starting db-sync about the ledger path.

On the db-sync command line there is a --state-dir parameter. That specifies the directory where the ledger state is expected.

If the state directory is empty then it will roll back to genesis.

One common issue when using snapshots is that the ledger state part of the snapshot is restored to one place and db-sync expects it in another.

Do you mind sending the link where I pass the parameter while starting db-sync? I did follow the guide and I don't know how to pass --state-dir parameter when running via docker compose.

Documentation is at https://github.com/input-output-hk/cardano-db-sync/blob/master/doc/building-running.md . The --state-dir parameter should point to the directory where the db-sync should store its ledge state data (assuming you are syncing from genesis) or where db-sync will find the ledger state data from the snapshot.

The snapshot will only be applied if cardano-node is synced past the snapshot point, since the benefit of using it would be eliminated given cardano-db-sync rolls back to genesis under these conditions. For best results, ensure the node is close to the network tip prior to upgrading.


text:
Connecting Node and DB-Sync
I'm running Cardano Node and Cardano GraphQL on the same network/computer. This is how I started the node:
 cardano-node run \
   --topology /home/ubuntu/cardano/cardano-src/cardano-node/mainnet-topology.json \
   --database-path /home/ubuntu/cardano/cardano-src/cardano-node/data \
   --socket-path /home/ubuntu/cardano/cardano-src/cardano-node/data/node.socket \
   --host-addr xxx.xxx.xxx.xxx \
   --port 1911 \
   --config /home/ubuntu/cardano/cardano-src/cardano-node/mainnet-config.json

Wallet Start:
cardano-wallet serve \
      --port 1919 \
      --node-socket /home/ubuntu/cardano/cardano-src/cardano-node/data/node.socket \
      --mainnet \
      --database /home/ubuntu/cardano/cardano-src/cardano-node/data \
      --listen-address 0.0.0.0 \

Docker, GraphQL:
export NETWORK=mainnet &&\
docker pull inputoutput/cardano-graphql:6.2.0-${NETWORK} &&\
docker pull inputoutput/cardano-graphql-hasura:6.2.0 &&\
docker pull cardanosolutions/cardano-node-ogmios:v5.1.0-${NETWORK} &&\
RESTORE_SNAPSHOT=https://update-cardano-mainnet.iohk.io/cardano-db-sync/13/db-sync-snapshot-schema-13-block-7519843-x86_64.tgz \
docker-compose up -d &&\
docker-compose logs -f

How db-sync and node will communicate I did not pass any path of node data directory. I feel like Ogmios is pulling the same data as node did before and I'm storing the same data twice.

The Ogmios image you're using has it's own node instance. From https://ogmios.dev/getting-started/docker :

Ogmios docker images come in two flavours: cardano-node-ogmios and ogmios. The former is used to run a single container that bundles both a Cardano-node and an Ogmios server running side-by-side. It is likely the easiest way to get started. The latter is a standalone Ogmios server, and you’ll need to run that container in orchestration with a cardano-node; this is made relatively easy with Docker compose.


text:
How to get PublicKey from PrivateKey
I want to retrieve the public key from a private key created via a mnemonic key.
const { mnemonicToEntropy } = require('bip39');
const CardanoWasm = require('@emurgo/cardano-serialization-lib-nodejs')

const { WalletServer, Seed } = require("cardano-wallet-js");

const entropy = mnemonicToEntropy(
  [ "test", "walk", "nut", "penalty", "hip", "pave", "soap", "entry", "language", "right", "filter", "choice" ].join(' ')
);

const rootKey = CardanoWasm.Bip32PrivateKey.from_bip39_entropy(
    Buffer.from(entropy, 'hex'),
    Buffer.from(''),
  );

let privateKey = Seed.deriveKey(rootKey, ['1852H','1815H','0H','0','0']).to_raw_key();
console.log(privateKey.to_bech32());

How do I get a proper public key format like "addr..."?

You can follow the instructions here to derive different addresses from the rootKey you've already created:
https://github.com/Emurgo/cardano-serialization-lib/blob/master/doc/getting-started/generating-keys.md#use-in-addresses
You'll probably want to 1) create the accountKey + utxoPubKey + stakeKey, then 2) create the baseAddress, like so:
  const CardanoWasm = require("@emurgo/cardano-serialization-lib-nodejs");

  const harden = (num: number): number => {
    return 0x80000000 + num;
  }

  const rootKey = CardanoWasm.Bip32PrivateKey.generate_ed25519_bip32();

  // Start from here

  const accountKey = rootKey
    .derive(harden(1852)) // purpose
    .derive(harden(1815)) // coin type
    .derive(harden(0)); // account #0

  const utxoPubKey = accountKey
    .derive(0) // external
    .derive(0)
    .to_public();

  const stakeKey = accountKey
    .derive(2) // chimeric
    .derive(0)
    .to_public();

  // base address with staking key
  const baseAddress = CardanoWasm.BaseAddress.new(
    CardanoWasm.NetworkInfo.mainnet().network_id(),
    CardanoWasm.StakeCredential.from_keyhash(utxoPubKey.to_raw_key().hash()),
    CardanoWasm.StakeCredential.from_keyhash(stakeKey.to_raw_key().hash()),
  );

  const address = baseAddress.to_address();

  console.log(address.to_bech32()) // "addr..."

Edit:
Since you seem to be using your own cardano-wallet backend with this cardano-wallet-js client, the above is not needed. You create your wallet from the seed phrase via walletServer.createOrRestoreShelleyWallet() (see here) and list wallets (and their IDs) via walletServer.wallets(). The wallet id here is just something that this particular tool creates to let you distinguish between multiple wallets that you create with it; not something required by the network or derived from the private key. To get the addresses of a wallet you can use getAddresses() or getUnusedAddresses(), see https://github.com/tango-crypto/cardano-wallet-js#wallet-addresses

Thank you! Is it possible to retrieve the wallet id via private key? I'd like to send a transaction but it seems not possible without using the wallet id :/

Edited the answer to include the info on the wallet id. Basically there's many ways to create wallets & transactions and submit them to the network. When using the  cardano-wallet backend, you don't need to think about how to derive payment addresses from private keys and that sort. The wallet id is just a wallet references created by this particular tool for convenience.

Yes, but I cannot create a wallet with only one address in it. What I want is for each user needs to have a unique identifier like a private key but I cannot send transactions by using only the PK, a wallet id is required in each doc that I see.

Not exactly sure what you mean, but using cardano-wallet, why not give every user a wallet with a "wallet id"? You shouldn't need to touch any private keys. It handles those for you.

Regarding your first point: Every wallet can have multiple addresses, but you don't technically have to use them, if you don't want to. You can also use a single address per wallet.