text:
Attaching Datum Value with CSL 10.x
I generate my datum like so:
// Build datum
const sellerAddressPKH = changeAddressValue.slice(2,58);
const datumFields = CSL.PlutusList.new();
datumFields.add(CSL.PlutusData.new_integer(CSL.BigInt.from_str( ... )));
const datumConstr = CSL.ConstrPlutusData.new(
    CSL.BigNum.from_str('0'),
    datumFields
);
const datum = CSL.PlutusData.new_constr_plutus_data(datumConstr);
const datumHash = CSL.hash_plutus_data(datum);

Part of the output where I am sending native asset into a smart contract, I am attaching the datum hash like so:
txBuilder.add_output(
    CSL.TransactionOutputBuilder
        .new()
        .with_address(scriptAddress)
        .with_data_hash(datumHash)
        .next()
        .with_asset_and_min_required_coin(
            multiAsset,
            CSL.BigNum.from_str(protocolParameters.costPerWord.toString())
        )
        .build()
);

This only appears to be attaching the datum hash, and I cannot easily see how you would attach the datum value with the above output.
Any ideas?

So I am able to get the lib to include values in cbor now with witnesses.set_plutus_data(datumFields); however that doesn't get included in add_change_if_needed and when I try txBuilder.set_plutus_data(datumFields) I get function doesn't exist. witnesses = CardanoWasm.TransactionWitnessSet.new();

You call set_plutus_data on the transaction witness set not the txBuilder.

Yes, you're correct. When creating an output for a transaction, by default you only need to provide the datum hash. The consumer of that output is by default required to provide the datum that matches that hash.
If you want to provide the datum nonetheless for an output that you're creating in order to do assertions on it inside your spending validator you can do so like this:
const scripts = PlutusScripts.new();
scripts.add(PlutusScript.from_bytes(Buffer.from(<your script contract cborHex>, 'hex')));

const datumFields = CSL.PlutusList.new();
datumFields.add(CSL.PlutusData.new_integer(CSL.BigInt.from_str( ... )));
const datumConstr = CSL.ConstrPlutusData.new(
    CSL.BigNum.from_str('0'),
    datumFields
);
const datum = CSL.PlutusData.new_constr_plutus_data(datumConstr);

const transactionWitnessSet = CSL.TransactionWitnessSet.new();
transactionWitnessSet.set_plutus_scripts(scripts);
transactionWitnessSet.set_plutus_data(datum);
transactionWitnessSet.set_redeemers(...);

txBody.set_script_data_hash(hash_script_data(..., getCostModels(), datum));

{...}

export const COST_MODEL = [197209, 0, 1, 1, 396231, 621, 0, 1, 150000, 1000, 0, 1, 150000, 32, 2477736, 29175, 4, 29773, 100, 29773, 100, 29773, 100, 29773, 100, 29773, 100, 29773, 100, 100, 100, 29773, 100, 150000, 32, 150000, 32, 150000, 32, 150000, 1000, 0, 1, 150000, 32, 150000, 1000, 0, 8, 148000, 425507, 118, 0, 1, 1, 150000, 1000, 0, 8, 150000, 112536, 247, 1, 150000, 10000, 1, 136542, 1326, 1, 1000, 150000, 1000, 1, 150000, 32, 150000, 32, 150000, 32, 1, 1, 150000, 1, 150000, 4, 103599, 248, 1, 103599, 248, 1, 145276, 1366, 1, 179690, 497, 1, 150000, 32, 150000, 32, 150000, 32, 150000, 32, 150000, 32, 150000, 32, 148000, 425507, 118, 0, 1, 1, 61516, 11218, 0, 1, 150000, 32, 148000, 425507, 118, 0, 1, 1, 148000, 425507, 118, 0, 1, 1, 2477736, 29175, 4, 0, 82363, 4, 150000, 5000, 0, 1, 150000, 32, 197209, 0, 1, 1, 150000, 32, 150000, 32, 150000, 32, 150000, 32, 150000, 32, 150000, 32, 150000, 32, 3345831, 1, 1];
export const getCostModel = () => {
  const costModel = CostModel.new();
  COST_MODEL.forEach((x, i) => costModel.set(i, Int.new_i32(x)));
  const costModels = Costmdls.new();
  costModels.insert(Language.new_plutus_v1(), costModel);
  return costModels;
}

For more examples I recommend the following resources:
DApp Connector Examples
SpaceBudz Datum Creation

I am running into similar issue reported by bakon (from the reply to my question). It appears the CSL is not accounting for the datum in the output, so the fee is being miscalculated.


text:
How to run testnet node and mainnet node on background at the same time?
After searching for a while, didn’t find any post regarding this.
I know running node for testnet and mainnet use different configuring files, and on the cardano developer portal, they are showing the same port. But can I run both testnet and mainnet relay node on background (I assume I’d need to change the port number)?
Do I need to make two different cardano-run process?
In that case, it is ok when I run cardano-cli commands just change different network, like testnet-magic ***/–mainnet? Is the rest command the same?
I currently run the testnet as a systemd service, I can definitely just go ahead and run a mainnet node as another service on the background, but I want to ask before head, in case I would messed up the configurations on my server.

Yes, you would need two separate cardano-node processes, each with their own configuration and their own disk storage directory.
When using cardano-cli  you will need to connect to the correct local domain socket for the network you want to connect to.
Eg for mainnet:
export CARDANO_NODE_SOCKET_PATH=/path/to/mainnet/db/node.socket
cardano-cli ....

or for testnet:
export CARDANO_NODE_SOCKET_PATH=/path/to/testnet/db/node.socket
cardano-cli ....

Thanks for your answer!
If I do that, every time I switch between testnet and mainnet, I need to update this socket variable CARDANO_NODE_SOCKET_PATH, it there a way that it can be done automatically?
I see some others suggest use two different linux accounts, it's essentially the same as changing this socket environment variable to me.

You can write two trivial bash scripts, with -mainnet and -testnet in the names and setting the CARDANO_NODE_SOCKET_PATH.

source: Stack Exchange

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

sort: votes


text:
Can someone help to understand how to use handleChainIndexClient?
I'm not guru with Eff system under Haskell.
What i got that method could contains the constraints for monad that should be used with.
module ChainIndexHelper
where

import Plutus.ChainIndex.Client
import Plutus.ChainIndex.Effects (ChainIndexQueryEffect (..))
import Control.Monad.Freer.Reader
import Control.Monad.Freer
import Control.Monad.Freer.Error

-- import Control.Monad.IO.Class
import Control.Monad.Trans

import Plutus.V1.Ledger.Scripts (DatumHash, Datum)
import Data.Function ((&))

import Network.HTTP.Client (newManager, defaultManagerSettings)

import Servant.API
import Servant.Client

testGetDatum :: DatumHash -> IO (Maybe Datum)
testGetDatum dh = do
    manager' <- newManager defaultManagerSettings
    let
        reqDatum = DatumFromHash dh
    mbDatum <- runM
               $ runError
               $ runReader (mkClientEnv manager' (BaseUrl Http "localhost" 9083 ""))
               $ handleChainIndexClient reqDatum
    return mbDatum -- Might be post processing stmts

For scripts I have to get Datum of previous UTxO so I want to use Chain Index server and call client code. Then I'm constructing pure Cardano Tx. Signing should be on the client side.

A little dummy. Can be improved
{-# LANGUAGE TypeOperators              #-}
{-# LANGUAGE DataKinds                  #-}

...

runClientError :: Eff (Error ClientError ': r) a -> Eff r (Either ClientError a)
runClientError = runError

runHandleChainIndexClient :: DatumHash -> IO (Maybe Datum)
runHandleChainIndexClient dh = do
   manager' <- newManager defaultManagerSettings
   let
      clientEnv = mkClientEnv manager' (BaseUrl Http "localhost" 9083 "")
      reqDatum = DatumFromHash dh
   mbDatum <- runM
              -- $ runError
              $ runClientError
              $ runReader clientEnv
              $ handleChainIndexClient reqDatum
   case mbDatum of
       Left _ -> return Nothing
       Right d -> return d

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


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?


text:
find text from transaction message with blockfrost or koios
small (maybe) easy question.
i want to find with blockfrost a "message" on a transaction.
can someone help me a bit for this? i dont find currently anything.
thank you in advanced.
TTS17

By "message" on a transaction do you mean finding transaction metadata given a transaction hash? There is this Blockfrost resource or this Koios resource.

i think we speak for the same.
https://developers.cardano.org/docs/governance/cardano-improvement-proposals/cip-0020/
i think it is the ""Handling ill-formed 674 metadata""
thank i will do some test with real transactions and message.
i want to ask people to text something specific and when i find transaction with this message, to do something else

perfect, i found one transaction with msg in cardanoscan and execute this command.  ----- curl -H 'project_id: mainnetID' https://cardano-mainnet.blockfrost.io/api/v0/txs/77486ddc3235ee4097890a99d6bb2cf4d891b86829e860d4a2f3b5f8bd059a24/metadata

Good to know! I have added an answer after your clarification so feel free to mark it as answered. Don't hesitate to comment asking for more details if you need more info too

Given the message in your context is the CIP 20: Transaction message/comment metadata, you can query this Blockfrost resource or this Koios resource to retrieve the metadata of a transaction given its hash, specifically retrieving the details under the 674 label.

thank you mate, is something i have found with combination of your answer and my research. you have verify and then i test it. is so great what all is possible :)

Glad to be of help. Don't hesitate to add a comment if you have any further related questions.

thank you,
i will try to use this with BASH and collect a number from there, and then compare it with the APOCH number :)


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

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


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

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

  const protocolParams = await blockfrost.fetchParameters();

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

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

  txBuilder.set_ttl(protocolParams.slot + 10000);

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

  txBuilder.add_output(txOut);

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

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

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

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

  // ...
}

function getTxBuilderConfig(protocolParams: ProtocolParameters): TransactionBuilderConfig {

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

}


text:
How to transfer ADA in stake pool wallet?
I'm trying to use cntools to send ADA from my stake pool wallet to a Ledger wallet (sending "all" to address) and I've been getting:
Command failed: transaction submit  Error: Error while submitting tx: ShelleyTxValidationError ShelleyBasedEraAlonzo (ApplyTxError [UtxowFailure (WrappedShelleyEraFailure (UtxoFailure (ValueNotConservedUTxO (Value 0 (fromList [])) (Value 2097417169 (fromList []))))),UtxowFailure (WrappedShelleyEraFailure (UtxoFailure (BadInputsUTxO (fromList [TxInCompact (TxId {_unTxId = SafeHash "f448b7e933fbc2bd70ee6d2dbd9bf5e4ab181cde05ee99eb3889fba48d88109b"}) 0]))))])
I had submitted it before, but it took a long time and then said that 600 seconds for creating a block had timed out.

how do I see where the transaction is, and what is wrong with it?
is this on the blockchain or only a transaction stored to my server?
how do I get my ADA out of here so I can decommission my stake pool (I'm paying $200/month and haven't gotten any rewards in almost a year, time to let go of it)

If during transaction submission you get an error like the one above, the TX has not been submitted and therefore isn't "anywhere". Error messages usually give a hint as to what's wrong with it.
Since TX submission threw back an error, it is not on chain in your mempool. It is simply an invalid and unsubmitted transaction.

Judging from the ValueNotConservedUTxO error message, there may be an issue where the transaction's inputs are not matching the outputs (minus the fee). Also, if the TX is submitted with a small TTL, it may expire prior to being included in a block. Both of these may or may not be due to a misconfiguration in CNTools. I am not familiar enough with CNTools to advise how to get it to work, but:

Since your needs are relatively simple (emptying a wallet containing a single UTXO and deregistering a pool), I recommend using raw cardano-cli commands for a fine, low-level control over your workflow. This way, you can customize the TTL, as well as exactly which assets you're sending to the new wallet and where the fees will be paid from. You can also create and submit a pool deregistration certificate with cardano-cli.

Let me know if you need further clarification on how to do all this with cardano-cli. CoinCashew's Guide is an excellent resource for this if you need help.

Literally the first command: "Command failed: query protocol-parameters   Error: /params.json: /params.json: openBinaryFile: permission denied (Permission denied)"

(I keep having problems with anything related to Cardano, not sure why it's so difficult)

No worries! Its almost always the obvious and most silliest of things!


text:
A Script With Multiple Different Datum Types
I have 4 different Datum Data Types in my script because for 4 different use cases in my script.
data FundCreationDatum = FundCreationDatum
  { vFundOwner :: PaymentPubKeyHash,
    vPrizeAmount :: Integer,
    vProjectLabel :: [BuiltinByteString],
    vPrizeDistributionRatio :: [Integer]
  }

data ProjectSubmitDatum = ProjectSubmitDatum
  { vProjectOwner :: PaymentPubKeyHash,
    vProjectRegistrationFee :: Integer,
    vProjectCategory :: BuiltinByteString,
    vFundPayIdentifier :: PaymentPubKeyHash
  }

data VotingActionDatum = VotingActionDatum
  { vProjectToVote :: PaymentPubKeyHash,
    vVoterPayAddress :: PaymentPubKeyHash,
    vAdaLovelaceValue :: Integer,
    vVoteFundIdentifier :: PaymentPubKeyHash,
    vActionName :: BuiltinByteString
  }
  deriving (Show)

data ConToMatchPool = ConToMatchPool
  { vFundAddress :: PaymentPubKeyHash,
    vPrizeFund :: Integer
  }
  deriving (Show)

I then bundled the 4 data types into a single data type with the Maybe monad.
data QuadraDatum = QuadraDatum
  { qCreateFund :: (Maybe FundCreationDatum),
    qVoting :: (Maybe VotingActionDatum),
    qSubProject :: (Maybe ProjectSubmitDatum),
    qContrPool :: (Maybe ConToMatchPool)
  }

I am trying to send a utxo with datum attached like this.
start cp = do
  let dat = QuadraDatum qContrPool
            {vFundOwner = cpFundOwner cp
            ,vPrizeAmount = cpPrizeAmount cp
            ,vProjectLabel = cpProjectLabel cp
            ,vPrizeDistributionRatio = cpPrizeDistributionRatio cp
            }
      tx = Constraints.mustPayToTheScript dat $ Ada.lovelaceValueOf $ (cpPrizeAmount cp)
  ledgerTx <- submitTxConstraints typedValidator tx
  void $ awaitTxConfirmed $ getCardanoTxId ledgerTx

I am getting the following error
 error:
    • Couldn't match expected type ‘Maybe FundCreationDatum’
                  with actual type ‘FundCreationDatum’

let's say we have a Maybe Integer type, then the value must be assigned as either Just 3 or Nothing.
Directly assigning  it as 3 won't work.
So your QuadraDatum should be   created as
  let dat = QuadraDatum
              (Just qContrPool)
              (Just {vFundOwner = cpFundOwner cp
                  ,vPrizeAmount = cpPrizeAmount cp
                  ,vProjectLabel = cpProjectLabel cp
                  ,vPrizeDistributionRatio = cpPrizeDistributionRatio cp
               })
               Nothing
               Nothing

Also, better approach is to use multiple constructors something like this
data QuadraDatum = FundCreationDatum
  {
    vPrizeAmount :: Integer,
    ...
  }|
  ProjectSubmitDatum
    {
      vProjectRegistrationFee :: Integer,
      ...
    }
  deriving (Show)


text:
Plutus Starter nix-shell build errors on MacOS Monterey M1 - ghc-cabal: Encountered missing or private dependencies
MacOS Monterey, Apple M1
Installed latest GHC via https://www.haskell.org/ghcup/ but not Stack.
Installed nix 2.8.0 multiuser
Set Cache in /etc/nix/nix.conf as below:
UPDATE: I have since updated nix.conf file for M1. See bottom of question for latest nix.conf and corresponding error message
             sandbox = false
             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=

Steps to reproduce:
git clone https://github.com/input-output-hk/plutus-starter

cd plutus-starter

nix-shell

Result: Note see Update below. This might have been due to nix.conf not setup properly for M1.
       > Configuring mtl-2.2.2...
   > "/nix/store/jjjbvzpal4b7n6hmnychrq07w36jnzjw-ghc-8.10.7/bin/ghc-pkg" update -v0 --force --package-db=libraries/bootstrapping.conf libraries/mtl/dist-boot/inplace-pkg-config
   > "inplace/bin/ghc-cabal" configure libraries/hpc dist-boot --with-ghc="/nix/store/jjjbvzpal4b7n6hmnychrq07w36jnzjw-ghc-8.10.7/bin/ghc" --with-ghc-pkg="/nix/store/jjjbvzpal4b7n6hmnychrq07w36jnzjw-ghc-8.10.7/bin/ghc-pkg"  --package-db=/private/tmp/nix-build-ghc-8.8.4.drv-1/ghc-8.8.4-configured-src/libraries/bootstrapping.conf --disable-library-for-ghci --enable-library-vanilla --enable-library-for-ghci --disable-library-profiling --disable-shared --with-hscolour="/nix/store/v35zbnmxnxh1axccw5agmplam8nbr0b8-hscolour-exe-HsColour-1.24.4/bin/HsColour" --configure-option=CFLAGS="-Wall    -Wno-unknown-pragmas" --configure-option=LDFLAGS="  " --configure-option=CPPFLAGS="   " --gcc-options="-Wall    -Wno-unknown-pragmas   " --configure-option=--with-iconv-includes="/nix/store/cg81y8mlrvd3crly089xy6xd63nvzm4w-libiconv-50/include" --configure-option=--with-iconv-libraries="/nix/store/cg81y8mlrvd3crly089xy6xd63nvzm4w-libiconv-50/lib" --configure-option=--with-gmp-includes="/nix/store/nwfxg1dpzpkq9w2awp4zs5jawn4fvyb0-gmp-6.2.1-dev/include" --configure-option=--with-gmp-libraries="/nix/store/j75k7na64g7xly1gxrkz44sby1gdc0sa-gmp-6.2.1/lib" --configure-option=--with-curses-libraries="/nix/store/bs7hpi27xc0y2qynvx4n1zpnv3s5bnkx-ncurses-6.2/lib"   --constraint "binary == 0.8.7.0"   --constraint "transformers == 0.5.6.2"   --constraint "mtl == 2.2.2"   --constraint "hpc == 0.6.0.3"   --constraint "ghc-boot-th == 8.8.4"   --constraint "ghc-boot == 8.8.4"   --constraint "template-haskell == 2.15.0.0"   --constraint "text == 1.2.4.0"   --constraint "parsec == 3.1.14.0"   --constraint "Cabal == 3.0.1.0"   --constraint "ghc-heap == 8.8.4"   --constraint "ghci == 8.8.4"   --constraint "terminfo == 0.4.1.4" --with-gcc="clang" --with-ld="ld" --with-ar="ar" --with-alex="/nix/store/x1qgmqksr03kvdslwakbn4qbi4f5h3bs-alex-exe-alex-3.2.4/bin/alex" --with-happy="/nix/store/ic7q31ff5n34k0x1x1xm8jldzh88c58s-happy-exe-happy-1.19.12/bin/happy"
   > Configuring hpc-0.6.0.3...
   > ghc-cabal: Encountered missing or private dependencies:
   > base >=4.4.1 && <4.14
   >
   > libraries/hpc/ghc.mk:3: libraries/hpc/dist-boot/package-data.mk: No such file or directory
   > make[1]: *** [libraries/hpc/ghc.mk:3: libraries/hpc/dist-boot/package-data.mk]        Error 1
   > make: *** [Makefile:124: all] Error 2
   For full logs, run 'nix log /nix/store/40hp5wypw0djadrrcb1346hk2y0ridf2-ghc-8.8.4.drv'.
    error: 1 dependencies of derivation '/nix/store/qgyzqd5v4yn32fgns4vqwcr3qrqgy8ii-ghc-8.10.4.20210212-configured-src.drv' failed to build
    error: 1 dependencies of derivation '/nix/store/3i1f6vn82wg07dwvr24dm26l45jzx3sw-ghc-8.10.4.20210212.drv' failed to build
    error: 1 dependencies of derivation '/nix/store/irws4cdrncz0gdg5m68blqj3h0p86ivx-Cabal-lib-Cabal-3.4.1.0-config.drv' failed to build
    error: 1 dependencies of derivation '/nix/store/xrwzqagrirvim8bs8kpiqxikqf78qn30-Cabal-lib-Cabal-3.6.2.0-config.drv' failed to build

Also earlier in the nix-shell log I saw the following:
    [217 of 285] Compiling Distribution.Simple.Program.GHC ( libraries/Cabal/Cabal/Distribution/Simple/Program/GHC.hs, bootstrapping/Distribution/Simple/Program/GHC.o )
    'apple-a7' is not a recognized processor for this target (ignoring processor)

Things I have tried:
Search for all nix.conf file and add the cache entries as above.
run as root: sudo nix-shell
sudo nix-build etc.
I am not familiar with nix and I might have missed some steps to be done prior to running nix-shell
PS. Also would like to clean the nix caches? So I can try again with clean cache. Is it the following?
  rm $HOME/.cache/nix/binary-cache-v*.sqlite*

or is there a nix command for this?
And the nix log command for further details did not work either:
  nix log /nix/store/40hp5wypw0djadrrcb1346hk2y0ridf2-ghc-8.8.4.drv
  error: experimental Nix feature 'nix-command' is disabled; use '--extra-experimental-features nix-command' to override

using --extra-experimental-features indicates log is not recognized nix command.
UPDATE: Per suggestion I have updated the nix.conf per https://github.com/renzwo/cardano-plutus-apps-install-m1/blob/main/README.md
And my exact nix.conf file is now:
 sandbox = false
 system = x86_64-darwin
 extra-platforms = x86_64-darwin aarch64-darwin
 experimental-features = nix-command
 extra-experimental-features = flakes
 extra-sandbox-paths = /System/Library/Frameworks /System/Library/PrivateFrameworks /usr/lib /private/tmp /private/var/tmp /usr/bin/env
 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=

However, I now see a different error message:
 copying path '/nix/store/v3bzn8kiwxaip81hbdv9q3jhkxcmqrhk-git-2.32.0' from 'https://hydra.iohk.io'...
 building '/nix/store/zcv0q6cmd39zr580w9sq0z1wbkak0mqk-git-ls-files.drv'...

 ErrorErrorxexecuting '/nix/store/715y5lnw12vdcc3hh9sc9vbkdi6c83x6-bash-4.4-p23/bin/bash': Bad file descriptor
 error (ignored): error: end of string reached
 error: builder for '/nix/store/zcv0q6cmd39zr580w9sq0z1wbkak0mqk-git-ls-files.drv' failed with exit code 1;
   last 2 log lines:
   >
   > ErrorErrorxexecuting '/nix/store/715y5lnw12vdcc3hh9sc9vbkdi6c83x6-bash-4.4-p23/bin/bash': Bad file descriptor
   For full logs, run 'nix log /nix/store/zcv0q6cmd39zr580w9sq0z1wbkak0mqk-git-ls-files.drv'.
 (use '--show-trace' to show detailed location information)

I see this running under both both bash and zsh shells
Here is full trace:
 sudo nix-shell --show-trace
 building '/nix/store/zcv0q6cmd39zr580w9sq0z1wbkak0mqk-git-ls- files.drv'...

 ErrorErrorxexecuting '/nix/store/715y5lnw12vdcc3hh9sc9vbkdi6c83x6-bash-4.4-p23/bin/bash': Bad file descriptor
 error: builder for '/nix/store/zcv0q6cmd39zr580w9sq0z1wbkak0mqk-git-ls-files.drv'   failed with exit code 1

   … while realising the context of path '/nix/store/g0769lx8bm7lna4gsdchiayk6n7gdcx5-git-ls-files/files'

   at /nix/store/bvynxhgsxhp6ds11ak1wnjx5h8avmfwf-source/lib/clean-git.nix:146:26:

      145|           submoduleDirs = lines (readFile (files + "/submoduleDirs"));
      146|           files = lines (readFile (files + "/files"));
         |                          ^
      147|         };

   … while evaluating 'lines'

   at /nix/store/bvynxhgsxhp6ds11ak1wnjx5h8avmfwf-source/lib/clean-git.nix:33:11:

perhaps it has something to do with this issue that mentions both bad file descriptors and too many open file descriptors? https://github.com/NixOS/nixpkgs/issues/101459

The following git repo has the latest information on setting up your environment in Mac M1. I personally followed this tutorial and worked perfectly. I suggest you delete everything you have done before and start from scratch following this link. https://github.com/renzwo/cardano-plutus-apps-install-m1/blob/main/README.md

Ok, did you get try this with plutus-starter project?

I did update with your suggestion for M1 based nix.conf file but used the cache suggested for the Plutus Starter. See updated logs above

I also see file descriptor error when running nix-build on Plutus-Apps

I dont think you should use the plutus-start-project for now , the repo they have on github is not updated , and you have to do a lot of things to fix it to make it run right now.

Well I followed the instructions for M1 above for Plutus-Apps and reinstalled nix as well. However, I am still seeing the invalid file descriptor errors as indicated in my update above.

I did install ghc before so perhaps that might be having an effect. I think with nix this should not be a factor however

I dont really know what exact error you are getting , hit me up on my email shanyuzhang123@gmail.com. We can hop on a zoom or google meet call. I can try to help you set up from there,

actually we can meet on discord if you want Shan#7955

Sounds good, I will send you email and hop on discord as well

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:
Derive public key hash from bech32 address using python
I know that this is possible in javascript using the cardano serialization lib, as follows:
function toHex(bytes){
    return Buffer.from(bytes).toString("hex");
}

function addrToPubKeyHash(bech32Addr) {
  const pkh = Loader.Cardano.BaseAddress.from_address(
    Loader.Cardano.Address.from_bech32(bech32Addr)
  )
    .payment_cred()
    .to_keyhash();

  return toHex(pkh.to_bytes());
}

How would I do the same in python?

Check out pycardano.
Class Address has a class method from_primitive that can read and decode a bech32 address. Then you can directly read field payment_part, which is the public key hash of the payment credential from the address object. You can find the API documentation here.
Example:
>>> from pycardano import Address
>>> addr = Address.from_primitive("addr_test1vzv89dr7v69enywx0t7sqcyxshcmnlv9q43lhpg7ecfhjjsjcdsza")
>>> addr.payment_part
VerificationKeyHash(hex='9872b47e668b9991c67afd00608685f1b9fd850563fb851ece13794a')


text:
new cardano wallet takes time to sync, not able to get balance of wallet
i am using docker compose for running cardano server,
and using cardano-wallet-js package for interacting.
my issue is whenever i create new wallet, the wallet sync form 0 and it takes too much time
to create wallet
const genwallet = async () => {
  try {
    let parameters = await cardano.Seed.generateRecoveryPhrase()
    let words = cardano.Seed.toMnemonicList(parameters);

    let passphrase = 'tangoCrypto';
    let name = 'wallet';

    let wallet = await walletServer.createOrRestoreShelleyWallet(name, words, passphrase);
    console.log(wallet);

  } catch (e) {
    console.log(e);
  }
}
genwallet()

get wallet info
  id: '344e120866c28fd706b2eff539da61b02282a3df',
  address_pool_gap: 20,
  balance: {
    total: { quantity: 0, unit: 'lovelace' },
    available: { quantity: 0, unit: 'lovelace' },
    reward: { quantity: 0, unit: 'lovelace' }
  },
  assets: { total: [], available: [] },
  delegation: { next: [], active: { status: 'not_delegating' } },
  name: 'wallet',
  passphrase: { last_updated_at: '2022-04-26T11:21:24.396104055Z' },
  state: { status: 'syncing', progress: { quantity: 0, unit: 'percent' } },
  tip: {
    height: { quantity: 0, unit: 'block' },
    epoch_number: 0,
    time: '2017-09-23T21:44:51Z',
    absolute_slot_number: 0,
    slot_number: 0
  },

in this state syncing progress start from 0 for every new wallet, i can't use this wallet till it sync.

What do the logs of cardano-node say? I personally find it easier hosting the node as-is (i.e. outside of a container) and there is a simple guide on how to do it.

no logs only 200 ok

it is creating full node wallet. A full-node wallet basically means that it has to synchronize and download the complete blockchain for every new wallets you create then only you can able to send transactions and interact with the wallet.
ref - https://developers.cardano.org/docs/integrate-cardano/creating-wallet-faucet/#cardano-wallets


text:
Bad File Descriptor on nix-build of Plutus-Apps on Mac M1
I am seeing an error building Plutus-Apps on Mac M1.
After precisely following
https://github.com/renzwo/cardano-plutus-apps-install-m1/blob/main/README.md
UPDATE: This did resolve. These errors appears to be due to corrupted cache in nix store from download on in the cache itself.
as recommended here:
Building Plutus-apps on Mac M1
I get an Invalid File Descriptor error. Here are the logs
 copying path '/nix/store/lkbwcc0zyq9jzz8mk149rmfxw6ycl627-curl-7.81.0-dev' from  'https://hydra.iohk.io'...
 building '/nix/store/9z2bhjz6slfphlm4xbpkh9c0hzll46kh-source.drv'...

 ErrorErrorxexecuting '/nix/store/067f780bk90ghn7yhz914d5fykmll7a4-bash-5.1-p16/bin/bash': Bad file descriptor
 error: builder for '/nix/store/9z2bhjz6slfphlm4xbpkh9c0hzll46kh-source.drv' failed with exit code 1;
   last 2 log lines:
   >
   > ErrorErrorxexecuting '/nix/store/067f780bk90ghn7yhz914d5fykmll7a4-bash-5.1-p16/bin/bash': Bad file descriptor
   For full logs, run 'nix log /nix/store/9z2bhjz6slfphlm4xbpkh9c0hzll46kh-source.drv'.
 (use '--show-trace' to show detailed location information)

here is full logs:
    nix log /nix/store/9z2bhjz6slfphlm4xbpkh9c0hzll46kh-source.drv
 ^A
 ^E^@^@^@^@^@^@^@Error^@^@^@^@^@^@^@^@^@^@^@^E^@^@^@^@^@^@^@Error^@^@^@x^@^@^@^@^@^@^@executing '/nix/store/067f780bk90ghn7yhz914d5fyk>
lines 1-2/2 (END)

Here is logs with full trace:
 deano@Ds-MacBook-Pro plutus-apps % nix-build --show-trace -A plutus- playground.server
 building '/nix/store/9z2bhjz6slfphlm4xbpkh9c0hzll46kh-source.drv'...

 ErrorErrorxexecuting '/nix/store/067f780bk90ghn7yhz914d5fykmll7a4-bash-5.1-p16/bin/bash': Bad file descriptor
 error: builder for '/nix/store/9z2bhjz6slfphlm4xbpkh9c0hzll46kh-source.drv' failed  with exit code 1;
   last 2 log lines:
   >
   > ErrorErrorxexecuting '/nix/store/067f780bk90ghn7yhz914d5fykmll7a4-bash-5.1- p16/bin/bash': Bad file descriptor
   For full logs, run 'nix log /nix/store/9z2bhjz6slfphlm4xbpkh9c0hzll46kh-source.drv'.

    … while realising the context of path  '/nix/store/dv269kw7fp6y81n0k20w9s4a05s2z4f7-source'

   at /Users/deano/plutus/plutus-apps/default.nix:13:16:

       12| , sources ? import ./nix/sources.nix { inherit system; } //  sourcesOverride
       13| , haskellNix ? import sources.haskell-nix {
         |                ^
       14|     pkgs = import sources.nixpkgs { inherit system; };

   … while evaluating 'throwIfNot'

   at /nix/store/m2vv0bxfchzrjngx8wi0i7dhzb9q2g50-source/lib/trivial.nix:379:22:

      378|   */
      379|   throwIfNot = cond: msg: if cond then x: x else throw msg;
         |                      ^
      380|

   … from call site

   at /nix/store/m2vv0bxfchzrjngx8wi0i7dhzb9q2g50-source/pkgs/top-  level/default.nix:55:5:

       54|   checked =
       55|     throwIfNot (lib.isList overlays) "The overlays argument to nixpkgs   must be a list."
         |     ^
       56|     lib.foldr (x: throwIfNot (lib.isFunction x) "All overlays passed to nixpkgs must be functions.") (r: r) overlays

   … while evaluating anonymous lambda

   at /nix/store/m2vv0bxfchzrjngx8wi0i7dhzb9q2g50-source/pkgs/top-level/default.nix:19:1:

       18|
       19| { # The system packages will be built on. See the manual for the
         | ^
       20|   # subtle division of labor between these two `*System`s and the three

   … from call site

   at /nix/store/m2vv0bxfchzrjngx8wi0i7dhzb9q2g50-source/pkgs/top-   level/impure.nix:82:1:

       81|
       82| import ./. (builtins.removeAttrs args [ "system" ] // {
         | ^
       83|   inherit config overlays localSystem;

   … while evaluating anonymous lambda

   at /nix/store/m2vv0bxfchzrjngx8wi0i7dhzb9q2g50-source/pkgs/top- level/impure.nix:14:1:

       13|
       14| { # We put legacy `system` into `localSystem`, if `localSystem` was not   passed.
         | ^
       15|   # If neither is passed, assume we are building packages on the current

   … from call site

   at /Users/deano/plutus/plutus-apps/nix/default.nix:30:10:

       29|
       30|   pkgs = import sources.nixpkgs {
         |          ^
       31|     inherit crossSystem;

   … while evaluating the attribute 'pkgs'

   at /Users/deano/plutus/plutus-apps/nix/default.nix:44:10:

       43| {
       44|   inherit pkgs plutus-apps sources;
         |          ^
       45| }

And here is 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=

 system = x86_64-darwin
 extra-platforms = x86_64-darwin aarch64-darwin

 sandbox = false
 extra-sandbox-paths = /System/Library/Frameworks /System/Library/PrivateFrameworks /usr/lib /private/tmp /private/var/tmp /usr/bin/env
 experimental-features = nix-command
 extra-experimental-features = flakes

I tried increasing file limits ..
launchctl limit maxfiles
maxfiles    200000         200000

But still get the error.

I did install GCH separately before but I don't think that should be a factor in running nix-shell or nix build

No it does not affect at all because GHC comes with Nix. When you enter a in a shell you already have access to all plutus dependencies.

[60 of 60] Compiling Blockfrost.API   ( src/Blockfrost/API.hs, dist/build/Blockfrost/API.o, dist/build/Blockfrost/API.dyn_o )
error: builder for '/nix/store/zx91r06dgsdddrmd1gzpx2ckiaw9qf29-blockfrost-api-lib-blockfrost-api-0.3.1.0.drv' failed with exit code 1;
last 10 log lines:

[51 of 60] Compiling Blockfrost.API.Cardano.Assets ( src/Blockfrost/API/Cardano/Assets.hs, dist/build/Blockfrost/API/Cardano/Assets.o, dist/build/Blockfrost/API/Cardano/Assets.dyn_o )

both  server and client compile ok now. I suspect that was corrupted download of cache or corrupted cache.  But now I get above error during nix-shell run

I think these errors are from corrupt download of cache but not sure.

I ran nix-shell again but keep getting the compile error with Blockfront API

detail logs shows: location info>: error: : dlopen(/nix/store/3g1j67mmalbr40mryf53a67ip3kj17i3-blockfrost-api-lib-blockfrost-api-0.3.1.0-config/lib/links/libHScontainers-0.6.2.1-ghc8.10.4.20210212.dylib, 0x0005): cannot dlopen > [43 of 60] Compiling Blockfrost.Util.Pagination

ok, got passed this error of dlopen by rerunning nix-shell in another terminal

You may want to try to follow the guide for Mac M1 here:
https://plutus-community.readthedocs.io/en/latest/#Environment/Build/Mac_M1/

I am following that. And the errors above are not now appearing.  The nix-build of server and client worked ok after rerunning a few times. However the step of running nix-shell is now giving an error.

error is [60 of 60] Compiling Blockfrost.API   ( src/Blockfrost/API.hs, dist/build/Blockfrost/API.o, dist/build/Blockfrost/API.dyn_o )
error: builder for '/nix/store/zx91r06dgsdddrmd1gzpx2ckiaw9qf29-blockfrost-api-lib-blockfrost-api-0.3.1.0.drv' failed with exit code 1;
last 10 log lines:

[51 of 60] Compiling Blockfrost.API.Cardano.Assets ( src/Blockfrost/API/Cardano/Assets.hs, dist/build/Blockfrost/API/Cardano/Assets.o, dist/build/Blockfrost/API/Cardano/Assets.dyn_o )

The previous errors with file descriptors I suspect are from corrupt download of cache or corrupt cache.

60 of 60] Compiling Blockfrost.API   ( src/Blockfrost/API.hs, dist/build/Blockfrost/API.o, dist/build/Blockfrost/API.dyn_o )
error: builder for '/nix/store/zx91r06dgsdddrmd1gzpx2ckiaw9qf29-blockfrost-api-lib-blockfrost-api-0.3.1.0.drv' failed with exit code 1;
last 10 log lines:

[60 of 60] Compiling Blockfrost.API   ( src/Blockfrost/API.hs, dist/build/Blockfrost/API.o, dist/build/Blockfrost/API.dyn_o )
For full logs, run 'nix log /nix/store/zx91r06dgsdddrmd1gzpx2ckiaw9qf29-blockfrost-api-lib-blockfrost-api-0.3.1.0.drv'.
error: 1 dependencies of derivation '/nix/store/a45kgfid8c37ika0bx6f6dy6hrlya168-blockfrost-client-core-lib-blockfrost-client-core-0.2.0.0-config.drv' failed to build
error: 1 dependencies of derivation '/nix/store/j7rszs8r90643v61cv430fp21z8n9456-blockfrost-client-core-lib-blockfrost-client-core-0.2.0.0.drv' failed to build

sorry to post log here but I could not update the question at this time.

detail logs shows: location info>: error:
: dlopen(/nix/store/3g1j67mmalbr40mryf53a67ip3kj17i3-blockfrost-api-lib-blockfrost-api-0.3.1.0-config/lib/links/libHScontainers-0.6.2.1-ghc8.10.4.20210212.dylib, 0x0005): cannot dlopen >
[43 of 60] Compiling Blockfrost.Util.Pagination ( src/Blockfrost/Util/Pagination.hs, dist/build/Blockfrost/Util/Pagination.o, dist/build/Blockfrost/Util/Pagination.dyn_o )
[44 of 60] Compiling Blockfrost.Util.Sorting ( src/Blockfrost/Util/Sorting.hs, dist/build/Blockfrost/Util/Sorting.o, dist/build/Blockfrost/Util/Sorting.dyn_o )

I tried running nix-shell again but same result. Any suggestions for this?

got passed this error by rerunning nix-shell in another terminal. It must have been a resource limit of some type.


text:
LightWallet: Empty array for (await api.getUsedAddresses() || await api.getUnusedAddresses() || [])
I am working on a light wallet integration. The recommended way of integrating with wallets is defined in CIP30.
When I select Nami and call:
(await api.getUsedAddresses() || await api.getUnusedAddresses() || [])
everything works fine and I receive at least one wallet address - a non empty array. But using the same code for eternl/ ccvault I always receive an empty array.
Is this a missing implementation error on their end or a mistake on my end?
getChangeAddress() works fine for both wallets.
Here some code snippets for more context:
export const isBrowser = () => typeof window !== "undefined";
export type Cardano = {
  [key: string]: {
    name: string;
    icon: string;
    version: string;
    api?: WalletApi,
    enable: () => Promise<WalletApi>;
    isEnabled: () => Promise<boolean>;
  };
};

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

and then later in the app:
async (actions, target, { getStoreActions }) => {
      const walletName: string = target.payload;
      const cardano = getCardano()!;
      const api = await cardano[walletName]!.enable();
      const addresses = (await api.getUsedAddresses()
                      || await api.getUnusedAddresses()
                      || []);
{...}

Thanks to Marcel - founder of eternl I've found my mistake.
await api.getUsedAddresses() actually returns an empty array - I thought both calls return undefined and it defaults to [].
After calling await api.getUsedAddresses() and await api.getUnusedAddresses() separately they both work as expected since my test wallet currently does not have used addresses.


text:
Is it possible to not compile data constructors with plutus-tx?
I'm having a newtype VerificationKey = HydraVerificationKey (VerKeyDSIGN Ed25519DSIGN) and I would love to be able to use that type directly in our plutus scripts. While I can implement PlutusTx.ToData et al for it and satisfy ghc, I get runtime errors like
Benchmark tx-cost: RUNNING...
tx-cost: Error: Unsupported feature: Kind: GHC.Types.Nat
Context: Compiling definition of: Hydra.Contract.HeadTokens.validateTokensMinting
Context: Compiling definition of: Hydra.Contract.HeadTokens.validate
Context: Compiling expr at "hydra-plutus-0.5.0-inplace:Hydra.Contract.HeadTokens:(120,8)-(120,101)"

Likely because the VerKeyDSIGN (from Cardano.Crypto.Class) is implemented using some reflection on key size using Nat, as it's defined:
newtype VerKeyDSIGN Ed25519DSIGN = VerKeyEd25519DSIGN (PinnedSizedBytes (SizeVerKeyDSIGN Ed25519DSIGN))

newtype PinnedSizedBytes (n :: Nat) = PSB ByteArray

But we would not want to be using HydraVerificationKey nor the underlying VerKeyEd25519DSIGN data constructors, but only functions
dealing with the newtype VerificationKey . Is this even possible?
Right now we are converting our off-chain keys to another, simpler type newtype Party = UnsafeParty {vkey :: BuiltinByteString}, but thought we could avoid that conversion.

I think you must be using the datatype in some way if you're doing anything with this type.
However, perhaps you just don't care about the Nat index. It would be nice to be able to ignore this, but how would you communicate this to the compiler? You really want to say "don't use this definition of the type, use this other definition of the type that doesn't have this parameter". But the simplest way to do that is just to: use the other definition of the type, which is what you're doing.
Possibly we could ignore phantom type parameters in general, but we'd have to be very careful that this didn't result in ill-typed Plutus IR. Generally throwing away bits of type information and hoping it will be okay is risky!

Okay. Exchanging types sounds not pretty and a takeaway would be to use less-fancy types if we want to re-use them in plutus. We will stay with the conversion or move to a simpler type which we could re-use between off- and on-chain. Thanks.


text:
Error with installing cardano-wallet on Ubuntu
I'm using Ubuntu 20.04 and trying to install cardano-wallet with this guide.
I tried a few times and every time I got this error:
ouroboros-consensus-byron        > Registering library for ouroboros-consensus-byron-0.1.0.0..
Progress 461/475

--  While building package plutus-tx-0.1.0.0 (scroll up to its section to see the error) using:
      /root/.stack/setup-exe-cache/x86_64-linux-tinfo6/Cabal-simple_mPHDZzAJ_3.2.1.0_ghc-8.10.7 --builddir=.stack-work/dist/x86_64-linux-tinfo6/Cabal-3.2.1.0 configure --with-ghc=/root/.stack/programs/x86_64-linux/ghc-tinfo6-8.10.7/bin/ghc-8.10.7 --with-ghc-pkg=/root/.stack/programs/x86_64-linux/ghc-tinfo6-8.10.7/bin/ghc-pkg-8.10.7 --user --package-db=clear --package-db=global --package-db=/root/.stack/snapshots/x86_64-linux-tinfo6/7d9a5133e73e69eafb80db950076b4ec70696c4137ef4c6e05d111373f4a3891/8.10.7/pkgdb --libdir=/root/.stack/snapshots/x86_64-linux-tinfo6/7d9a5133e73e69eafb80db950076b4ec70696c4137ef4c6e05d111373f4a3891/8.10.7/lib --bindir=/root/.stack/snapshots/x86_64-linux-tinfo6/7d9a5133e73e69eafb80db950076b4ec70696c4137ef4c6e05d111373f4a3891/8.10.7/bin --datadir=/root/.stack/snapshots/x86_64-linux-tinfo6/7d9a5133e73e69eafb80db950076b4ec70696c4137ef4c6e05d111373f4a3891/8.10.7/share --libexecdir=/root/.stack/snapshots/x86_64-linux-tinfo6/7d9a5133e73e69eafb80db950076b4ec70696c4137ef4c6e05d111373f4a3891/8.10.7/libexec --sysconfdir=/root/.stack/snapshots/x86_64-linux-tinfo6/7d9a5133e73e69eafb80db950076b4ec70696c4137ef4c6e05d111373f4a3891/8.10.7/etc --docdir=/root/.stack/snapshots/x86_64-linux-tinfo6/7d9a5133e73e69eafb80db950076b4ec70696c4137ef4c6e05d111373f4a3891/8.10.7/doc/plutus-tx-0.1.0.0 --htmldir=/root/.stack/snapshots/x86_64-linux-tinfo6/7d9a5133e73e69eafb80db950076b4ec70696c4137ef4c6e05d111373f4a3891/8.10.7/doc/plutus-tx-0.1.0.0 --haddockdir=/root/.stack/snapshots/x86_64-linux-tinfo6/7d9a5133e73e69eafb80db950076b4ec70696c4137ef4c6e05d111373f4a3891/8.10.7/doc/plutus-tx-0.1.0.0 --dependency=aeson=aeson-1.5.6.0-63wWHA3GHE0Isomy9OHMEw --dependency=base=base-4.14.3.0 --dependency=bytestring=bytestring-0.10.12.0 --dependency=containers=containers-0.6.4.1-D3v2li2ijuF82lK0hW01Nr --dependency=deepseq=deepseq-1.4.4.0 --dependency=filepath=filepath-1.4.2.1 --dependency=flat=flat-0.4.5-4g0HMvnhh6wwWCZXBuoYZ --dependency=ghc-prim=ghc-prim-0.6.1 --dependency=hashable=hashable-1.3.0.0-IsmIrOikObW5VAtLT8nz0o --dependency=lens=lens-4.19.2-jJTa5AeuDm5NTBTeWMq3U --dependency=memory=memory-0.15.0-12G9mJuoNajBX4ohDjVYqb --dependency=mtl=mtl-2.2.2 --dependency=plutus-core=plutus-core-0.1.0.0-HQxTtycJGU52DKsUbNhuCn --dependency=prettyprinter=prettyprinter-1.7.1-89YQ13YwDjX8F1jciVrjTL --dependency=serialise=serialise-0.2.4.0-DiNk09iYdO3InRp0kGWlZg --dependency=tagged=tagged-0.8.6.1-HAjNeIkiYpIE28bnkAmrHX --dependency=tasty=tasty-1.4.2.1-B5isyoZJH1FIanpsobqwTE --dependency=template-haskell=template-haskell-2.16.0.0 --dependency=text=text-1.2.4.0-8O4eYxmKONuI5wWkW4xxj2 --dependency=th-abstraction=th-abstraction-0.4.3.0-EPNdba1m5DICfgheXpc0BJ --dependency=th-compat=th-compat-0.1.3-5V8hDdHCkmaDnfC7yeUenV --exact-configuration --ghc-option=-fhide-source-paths
    Process exited with code: ExitFailure 1

How can I fix it?

Are there any more useful messages above what you have posted?

You might be on an old version of Cabal, I noticed 'Cabal-3.2.1.0' in your error message. cardano-node wants version 3.6.2.0, wallet might be similar.
Did you also build cardano-node as per the wallet guide suggestion? If so that will confirm that cabal etc is ok.
cardano-node setup link (if needed): https://developers.cardano.org/docs/get-started/installing-cardano-node/

@MC_Brisbane Thank you for replying. Sure I built cardano-node and have needed versions.
cardano-node 1.34.1 - linux-x86_64 - ghc-8.10,
git rev 73f9a746362695dc2cb63ba757fbcabb81733d23,
cabal-install version 3.6.2.0,
compiled using version 3.6.2.0 of the Cabal library

Scroll up a few lines from the error message to get more details relating to 'plutus-tx'. Also, are you running as the same user that built the cardano-node? Could be some shared objects. PlanB - if you're in a hurry you could grab the binary instead of building it.

Working only under root, here is the full error.

I was able to reproduce your error on my Ubuntu 20.04.4 LTS (with 8GB RAM, no other Cardano code was on this machine).
Initially it failed at a different spot 'Progress 445/475' and re-running the build ended up like your situation eg:
plutus-tx                      > Configuring plutus-tx-0.1.0.0...
plutus-tx                      > Cabal-simple_mPHDZzAJ_3.2.1.0_ghc-8.10.7: Encountered missing or private     [<--- NOTE]
plutus-tx                      > dependencies:
plutus-tx                      > plutus-core:{plutus-core, plutus-core-testlib} ==0.1.0.0
plutus-tx                      >
Progress 7/21

--  While building package plutus-tx-0.1.0.0 (scroll up to its section to see the error) using:
    ...
    Process exited with code: ExitFailure 1

Note the missing dependencies lines.
I decided to use the previous wallet version (not the latest), in case it was more stable ie v2022-01-18.
The below is what worked for me to get it to build ok:

Stop some other processes to free up RAM if you only have 8GB like me.

I installed libsodium, you probably won't need this step if you have built cardano-node successfully

Start the whole download/build process over again in a new directory but this time use the previous stable code release eg git checkout v2022-01-18

Run the build, it should complete eg stack build --test --no-run-tests

I don't have cardano-node on this machine so can not run the wallet as intended but cardano-wallet version looks ok:

cardano-wallet version
v2022-01-18 (git revision: a5085acbd2670c24251cf8d76a4e83c77a2679ba)

git checkout v2022-01-18 is really working for me. Great thanx!

Great, am pleased to hear it. I'm not sure of the actual root cause, but we might find that as other code in the repo gets updated over then next few days/weeks that it all comes right and plays together nicely again.


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

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

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

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

Thank you in advance for your help.

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

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

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

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

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

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


text:
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:
Compatible Plutonomy cabal.project for plutus-apps
I want to use Plutonomy , but it only (currently) works with two Plutus versions as per https://github.com/well-typed/plutonomy#flags.
How can I get a compatible cabal.project -- especially one that also works with plutus-apps ?


text:
Plutus-Starter Starter PAB backend server does not return wallet id
Server seems to have built ok:
[nix-shell:~/plutus/plutus-starter]$ cabal build plutus-starter-pab
Resolving dependencies...
Up to date

I am using Plutus-Starter project on Macbook Monterey M1 but have not been able to generate the wallet Ids or confirm that the server fully started. It seems to just say "[INFO] Starting PAB backend server on port 9080" full log is below. Is there a verbose mode for starting the server?
[nix-shell:~/plutus/plutus-starter]$ cabal exec -- plutus-starter-pab
[INFO] Slot 0: TxnValidate 08111487e032e647e23e6e6866665ab726a4c92532e9589f9e670f2585e35807
[INFO] Starting plutus-starter PAB webserver on port 9080. Press enter to exit.
[INFO] W[2]: Balancing an unbalanced transaction:
               Tx:
                 Tx 318797441458154cf284463902d8e152cc240ab65a58fff5287b0a1f5d5de3a1:
                   {inputs:
                   collateral inputs:
                   outputs:
                     - Value (Map [(,Map [("",10000000000)])]) addressed to
                       PubKeyCredential: bb22a3608c50bdb141d2f1255836a7f4fc829a47d801c985746cfca6 (no staking credential)
                   mint: Value (Map [])
                   fee: Value (Map [])
                   mps:
                   signatures:
                   validity range: Interval {ivFrom = LowerBound NegInf True, ivTo = UpperBound PosInf True}
                   data:}
               Requires signatures:
               Utxo index:
               Validity range:
                 (-∞ , +∞)
[INFO] W[2]: Finished balancing:
               Tx e5581a9ec85d0525e8aee67e8ec2e453b6e098121aa29fab8698ff091ebd3bd6:
                 {inputs:
                    - 08111487e032e647e23e6e6866665ab726a4c92532e9589f9e670f2585e35807!20

                    - 08111487e032e647e23e6e6866665ab726a4c92532e9589f9e670f2585e35807!21

                 collateral inputs:
                   - 08111487e032e647e23e6e6866665ab726a4c92532e9589f9e670f2585e35807!20

                 outputs:
                   - Value (Map [(,Map [("",9999999489)])]) addressed to
                     PubKeyCredential: 80a4f45b56b88d1139da23bc4c3c75ec6d32943c087f250b86193ca7 (no staking credential)
                   - Value (Map [(,Map [("",10000000000)])]) addressed to
                     PubKeyCredential: bb22a3608c50bdb141d2f1255836a7f4fc829a47d801c985746cfca6 (no staking credential)
                 mint: Value (Map [])
                 fee: Value (Map [(,Map [("",511)])])
                 mps:
                 signatures:
                 validity range: Interval {ivFrom = LowerBound NegInf True, ivTo = UpperBound PosInf True}
                 data:}
[INFO] W[2]: Signing tx: e5581a9ec85d0525e8aee67e8ec2e453b6e098121aa29fab8698ff091ebd3bd6
[INFO] W[2]: Submitting tx: e5581a9ec85d0525e8aee67e8ec2e453b6e098121aa29fab8698ff091ebd3bd6
[INFO] Slot 1: TxnValidate e5581a9ec85d0525e8aee67e8ec2e453b6e098121aa29fab8698ff091ebd3bd6
[INFO] Starting PAB backend server on port 9080

I don't see confirmation that it fully started but there is a response to service definition request:
 % curl -s http://localhost:9080/api/contract/definitions | jq
[
  {
    "csrSchemas": [
      {
        "argument": {
          "contents": [
            [
              "guessWord",
              {
                "tag": "FormSchemaString"
              }
            ]
          ],
          "tag": "FormSchemaObject"
        },
        "endpointDescription": {
          "getEndpointDescription": "guess"
        }
      },
      {
        "argument": {
          "contents": [
            [
              "secretWord",
              {
                "tag": "FormSchemaString"
              }
            ],
            [
              "amount",
              {
                "tag": "FormSchemaValue"
              }
            ]
          ],
          "tag": "FormSchemaObject"
        },
        "endpointDescription": {
          "getEndpointDescription": "lock"
        }
      }
    ],
    "csrDefinition": "GameContract"
  }
]

This does not seem to include enough endpoint information.
And the Wallet Creation request returns empty
deano@Ds-MacBook-Pro ~ % curl -s -d '' http://localhost:9080/wallet/create
deano@Ds-MacBook-Pro ~ %

Update: Digging into the source I see some instructions in a readme file related to starting the PAB backend server for a local cluster but I am not sure this is related.
cat ./dist-newstyle/src/plutus-ap_-cbcc5c6ab544aad6/plutus-pab-executables/README.md
#### Example

1. Build necessary components:

cabal build plutus-pab-local-cluster

2. Get config data:

  Clone <https://github.com/input-output-hk/cardano-wallet/> to $DIR and set the
  `SHELLEY_TEST_DATA` environment variable:

export SHELLEY_TEST_DATA=$DIR/lib/shelley/test/data/cardano-node-shelley

3. Run the local cluster:

cabal exec plutus-pab-local-cluster

4. Wait until the message `Starting PAB backend server on port 9080` appears.

5. Run the integration test:

curl -H "Content-Type: application/json" -v \
       -X POST \
       -d '{"caID":{"tag":"IntegrationTest"},"caWallet":{"getWalletId":"2d4cc31a4b3116ab86bfe529d30d9c362acd0b44"}}' \
       localhost:9080/api/contract/activate

A couple of log messages appear, the last one should say something like "Tx
confirmed. Integration test complete."

PAB Server starting message seems to be in PABLogMsg
I don't see there there is any message available within PABLogMsg to confirm a successful start.  I think there are no further messages about this. However there is some reason the PAB Server cannot create the walletId. Do I need to be running anything else for this to work?
[nix-shell:~/plutus/plutus-starter]$ cat ./dist-newstyle/src/plutus-ap_-cbcc5c6ab544aad6/plutus-pab/src/Plutus/PAB/Monitoring/PABLogMsg.hs
{-# LANGUAGE DataKinds            #-}
{-# LANGUAGE DeriveAnyClass       #-}
{-# LANGUAGE DeriveGeneric        #-}
{-# LANGUAGE DerivingVia          #-}
{-# LANGUAGE FlexibleContexts     #-}
{-# LANGUAGE LambdaCase           #-}
{-# LANGUAGE OverloadedStrings    #-}
{-# LANGUAGE TypeApplications     #-}
{-# LANGUAGE UndecidableInstances #-}

-- | PAB Log messages and instances
module Plutus.PAB.Monitoring.PABLogMsg(
    PABLogMsg(..),
    ChainIndexServerMsg,
    WalletMsg,
    PABServerLogMsg,
    AppMsg(..),
    CoreMsg(..),
    PABMultiAgentMsg(..),
    RequestSize(..),
    WalletClientMsg(..)
    ) where

import Cardano.Api qualified as C
import Cardano.BM.Data.Tracer (ToObject (toObject), TracingVerbosity (MaximalVerbosity))
import Cardano.BM.Data.Tracer.Extras (StructuredLog, Tagged (Tagged), mkObjectStr)
import Cardano.ChainIndex.Types (ChainIndexServerMsg)
import Cardano.Node.Types (PABServerConfig, PABServerLogMsg)
import Cardano.Wallet.Mock.Types (WalletMsg)
import Control.Monad.Freer.Extras.Beam (BeamLog)
import Data.Aeson (FromJSON, ToJSON, Value)
import Data.Aeson.Text (encodeToLazyText)
import Data.Text (Text)
import Data.Text qualified as T
import GHC.Generics (Generic)
import Plutus.Contract.Effects (PABReq, PABResp)
import Plutus.Contract.Resumable (Response)
import Plutus.Contract.State (ContractResponse)
import Plutus.PAB.Core.ContractInstance (ContractInstanceMsg)
import Plutus.PAB.Effects.Contract (PABContract (..))
import Plutus.PAB.Events.Contract (ContractInstanceId)
import Plutus.PAB.Instances ()
import Prettyprinter (Pretty (pretty), colon, line, viaShow, (<+>))
import Wallet.Emulator.LogMessages (TxBalanceMsg)
import Wallet.Emulator.MultiAgent (EmulatorEvent)
import Wallet.Emulator.Wallet (Wallet)

data WalletClientMsg =
    WalletClientError String
    | BalanceTxError String
    deriving stock (Eq, Show, Generic)
    deriving anyclass (ToJSON, FromJSON)

instance Pretty WalletClientMsg where
    pretty = viaShow

instance ToObject WalletClientMsg where
    toObject _ m = mkObjectStr (T.pack $ show m) ()

data AppMsg t =
    ActiveContractsMsg
    | ContractHistoryMsg
    | PABMsg (PABLogMsg t)
    | AvailableContract Text
    | ContractInstances (ContractDef t) [ContractInstanceId]
    | ContractHistoryItem ContractInstanceId (Response PABResp)
    deriving stock (Generic)

deriving stock instance (Show (ContractDef t)) => Show (AppMsg t)
deriving anyclass instance (ToJSON (ContractDef t)) => ToJSON (AppMsg t)
deriving anyclass instance (FromJSON (ContractDef t)) => FromJSON (AppMsg t)

instance (Pretty (ContractDef t)) => Pretty (AppMsg t) where
    pretty = \case
        ActiveContractsMsg               -> "Active contracts"
        ContractHistoryMsg               -> "Contract history"
        PABMsg m                         -> pretty m
        AvailableContract t              -> pretty t
        ContractInstances t s            -> pretty t <+> pretty s
        ContractHistoryItem instanceId s -> pretty instanceId <> colon <+> pretty (fmap encodeToLazyText s)

data PABLogMsg t =
    SCoreMsg (CoreMsg t)
    | SChainIndexServerMsg ChainIndexServerMsg
    | SWalletMsg WalletMsg
    | SMockserverLogMsg PABServerLogMsg
    | SMultiAgent (PABMultiAgentMsg t)
    deriving stock (Generic)

deriving stock instance (Show (ContractDef t)) => Show (PABLogMsg t)
deriving anyclass instance (ToJSON (ContractDef t)) => ToJSON (PABLogMsg t)
deriving anyclass instance (FromJSON (ContractDef t)) => FromJSON (PABLogMsg t)

instance Pretty (ContractDef t) => Pretty (PABLogMsg t) where
    pretty = \case
        SCoreMsg m             -> pretty m
        SChainIndexServerMsg m -> pretty m
        SWalletMsg m           -> pretty m
        SMockserverLogMsg m    -> pretty m
        SMultiAgent m          -> pretty m

{- ToObject instances

'ToObject.toObject' is very similar to 'ToJSON.toJSON' except that

* 'toObject' has an additional paramter for verbosity
* 'toObject' must always produce a JSON object (key-value map)

In the definitions below, every object produced by 'toObject' has a field
'string' with a friendly description of the message, similar to its
'Pretty' instance. Additional fields depend on the type of message.

-}

instance (ToJSON (ContractDef t), StructuredLog (ContractDef t)) => ToObject (AppMsg t) where
    toObject v = \case
        ActiveContractsMsg ->
            mkObjectStr "Listing active contract instances" ()
        ContractHistoryMsg ->
            mkObjectStr "Showing contract history" ()
        PABMsg m -> toObject v m
        AvailableContract t ->
            mkObjectStr "Available contract" t
        ContractInstances exe ids ->
            mkObjectStr
                "Active instances for contract"
                (exe, Tagged @"instances" ids)
        ContractHistoryItem i state ->
            mkObjectStr "Contract history item" $
                case v of
                    MaximalVerbosity -> Left (i, state)
                    _                -> Right i

instance (StructuredLog (ContractDef t), ToJSON (ContractDef t)) => ToObject (PABLogMsg t) where
    toObject v = \case
        SCoreMsg m             -> toObject v m
        SChainIndexServerMsg m -> toObject v m
        SWalletMsg m           -> toObject v m
        SMockserverLogMsg m    -> toObject v m
        SMultiAgent m          -> toObject v m

-- | FIXME: Redundant?
data PABMultiAgentMsg t =
    EmulatorMsg EmulatorEvent
    | ContractInstanceLog (ContractInstanceMsg t)
    | UserLog T.Text
    | BeamLogItem BeamLog
    | PABStateRestored Int
    | RestoringPABState
    | StartingPABBackendServer Int
    | WalletBalancingMsg Wallet TxBalanceMsg
    | WalletClient WalletClientMsg
    deriving stock Generic

instance (StructuredLog (ContractDef t), ToJSON (ContractDef t)) => ToObject (PABMultiAgentMsg t) where
    toObject v = \case
        EmulatorMsg e              -> mkObjectStr "emulator message" (Tagged @"payload" e)
        ContractInstanceLog m      -> toObject v m
        UserLog t                  -> toObject v t
        BeamLogItem b              -> toObject v b
        RestoringPABState          -> mkObjectStr "Restoring PAB state ..." ()
        PABStateRestored n         -> mkObjectStr ( "PAB state restored with "
                                                 <> T.pack (show n)
                                                 <> " contract instance(s)."
                                                  ) ()
        StartingPABBackendServer i -> mkObjectStr "starting backend server" (Tagged @"port" i)
        WalletBalancingMsg w m     -> mkObjectStr "balancing" (Tagged @"wallet" w, Tagged @"message" m)
        WalletClient m -> toObject v m

deriving stock instance (Show (ContractDef t)) => Show (PABMultiAgentMsg t)
deriving anyclass instance (ToJSON (ContractDef t)) => ToJSON (PABMultiAgentMsg t)
deriving anyclass instance (FromJSON (ContractDef t)) => FromJSON (PABMultiAgentMsg t)

instance Pretty (ContractDef t) => Pretty (PABMultiAgentMsg t) where
    pretty = \case
        EmulatorMsg m         -> pretty m
        ContractInstanceLog m -> pretty m
        UserLog m             -> pretty m
        BeamLogItem b         -> pretty b
        RestoringPABState     -> "Restoring PAB state ..."
        PABStateRestored 0    -> "No contract instance were restored in the PAB state."
        PABStateRestored 1    -> "PAB state restored with 1 contract instance."
        PABStateRestored n    -> "PAB state restored with"
                              <+> pretty n
                              <+> "contract instances."
        StartingPABBackendServer port ->
            "Starting PAB backend server on port" <+> pretty port
        WalletBalancingMsg w m -> pretty w <> colon <+> pretty m
        WalletClient m -> pretty m

data CoreMsg t =
    FindingContract ContractInstanceId
    | FoundContract (Maybe (ContractResponse Value Value PABResp PABReq))
    | ConnectingToAlonzoNode PABServerConfig C.SlotNo
    deriving stock Generic

deriving stock instance (Show (ContractDef t)) => Show (CoreMsg t)
deriving anyclass instance (ToJSON (ContractDef t)) => ToJSON (CoreMsg t)
deriving anyclass instance (FromJSON (ContractDef t)) => FromJSON (CoreMsg t)

instance Pretty (ContractDef t) => Pretty (CoreMsg t) where
    pretty = \case
        FindingContract i      -> "Finding contract" <+> pretty i
        FoundContract c        -> "Found contract" <+> viaShow c
        ConnectingToAlonzoNode config slotNo ->
                "Connecting to Alonzo node with config:"
            <>  line
            <>  pretty config
            <>  line
            <>  "The tip of the local node:"
            <+> viaShow slotNo

instance (StructuredLog (ContractDef t), ToJSON (ContractDef t)) => ToObject (CoreMsg t) where
    toObject v = \case
        FindingContract instanceID ->
            mkObjectStr "finding contract instance" instanceID
        FoundContract state ->
            mkObjectStr "found contract" $
                case v of
                    MaximalVerbosity -> Left (Tagged @"contract" state)
                    _                -> Right ()
        ConnectingToAlonzoNode _ _ -> mkObjectStr "Connecting to Alonzo node" ()

newtype RequestSize = RequestSize Int
    deriving stock (Show)
    deriving newtype (ToJSON, FromJSON)

instance Pretty RequestSize where
    pretty (RequestSize i) = pretty i <+> "bytes"

I realize that this doesn't directly answer your question, but I spent a lot of time (too much?) on getting the pab local cluster working.   The issue is that you will need to pivot away from the PAB when you get to the testnet because there are limitation using the pab on the testnet (shared wallet passwords, 3+ days for chain index synch, etc.) and not even possible using it on mainnet.  The PAB is awesome for development and using the simlutor, but it ends there.
So, in hindsight it is probably best to just focus on using a local devnet from cardano-node directly.  Then interact with your plutus scripts the way you will when you get to the testnet and mainnet.
I've just released The Open Source Cardano Lottery project and in that repository is working code and script examples for setting up & interacting with a local devnet and a testnet.   It has basic shell scripts for a PAB, but there are other options out there but I have not tried them (eg. PyCardano, cardano-serialization-lib
).
https://github.com/lley154/cardano-lottery
Hope this helps!


text:
How to get cardano-node to work with public systemd sockets?
I get no errors but no traffic and am at a loss. A couple of things:

I load a new service from file cardano-node.xml: firewall-cmd --permanent --new-service-from-file=/usr/lib64/firewalld/services/cardano-node.xml

I reload so it becomes runtime: firewall-cmd --reload

I see it in my default zone, allowing two ports, that match the TCP sockets handed by systemd. netstat -ap | grep <port> shows it, though as systemd. grep cardano shows something else:

    tcp6       0      0 [::]:29171              [::]:*                  LISTEN      1/systemd
    tcp        0      0 localhost:12788         0.0.0.0:*               LISTEN      4513/cardano-node

When inspecting with Wireshark, without passing sockets both an A and AAAA query is made, the former giving me an answer and my node starts downloading. When passing sockets only the AAAA query is made and the node does nothing.

I've set the scribe to JournalSK and debug level to info but there's nothing to go on. In fact, I remember more output using stderr/stdin with a simple cardano-node run, so I suspect something is off here too.
setupScribes:
  - scKind: JournalSK
    scName: journal
    scFormat: ScText
    scRotation: null

# For the Katip logging backend this specifies the default scribes that trace
# output is sent to if it is not configured to be sent to other scribes.
defaultScribes:
  - - JournalSK
    - journal

Is Katip and EKGViewBK something that needs to be installed separately or are they libraries used internally?

You're looking at firewall but socket activation is at systemd level. Can you share your unit files for the sockets and your node service?

Sure here you go: https://paste.ee/p/CJLcz
It's my understanding once the service gets started the sockets get passed to it. I assumed no traffic was getting out and thought firewall.

I did a little digging and it looks like an A query is never made when using the premade sockets so the node never gets it's peers and nothing happens!

I guess the lack of an answer section means relays-new.cardano-node.iohk.io doesn't support IPv6? Also, are the IP's in the IPv4 response relays or my closest peers? Sorry, I am learning as I go. Look forward to knowing what I'm doing wrong!


text:
Cardano - cardano-cli query utxo - get all utxo of an address
As the title, I've been wondering if cardano-cli has an ability to get all utxo based on given address.
I already tried
cardano-cli query utxo --address $(cat /path/to/addr) --testnet-magic 1097911063 --whole-utxo

But, it will return an error message
Invalid option '--whole-utxo'

I'm kinda confuse as on help it says, that --whole-utxo is available, but I do notice, that, it's like an option we choose between --whole-utxo or --address or --tx-in.

I tried to dig some documents / forum and even on official github, but I found no clue to do so.
Mostly it pointed to install db-sync etc, but, tbh, I'm not a fan to install or use other additional components outside cardano-cli (db-sync, blockfrost, etc).
I prefer to use the core itself rather than rely on outside of core.
Been wonder if I missed something.
Thanks & Cheers.

for the case you want to give an address instead of path of file of your wallet, and also you want to have output of a wallet in mainnet, please find below. cardano-cli query utxo --address addr1q898ttf4nk6u6qfdlgfkh4985740sdfghsgtlykxhjsd9y48u03pzezspr2drk --mainnet please replace the address with the one you want to see all the current UTXOs

Hi, thanks for your replies & sorry for late comments. I already try that way and as far as I notice, it only return with last utxo not whole / all utxo that occurred on that given address.

You can do it via cli omitting --whole-utxo
cardano-cli query utxo --address $(cat /path/to/addr) --testnet-magic 1097911063

Hi, thanks for your replies & sorry for late comments. I already done that way, but as far as I notice, it only give last utxo not whole / all utxo that occurred on that given address

Oh i see. I think cardano node or cli doesn't have this feature as far as I know we have to use dbsync or blockfrost for the same.

Ahh I see! seems yes, I've been search around and didn't found it. Thanks anyway for your replies & references! :)


text:
chain-index does not connect
I'm trying to run the cardano node, the cardano wallet and the chain index in three different docker images, but the chain index does not connect. The docker-compose file is below and the chain-index log is as follows:
chain-index_1     |
chain-index_1     | Command line config:
chain-index_1     | AppConfig {acLogConfigPath = Nothing, acMinLogLevel = Nothing, acConfigPath = Nothing, acCLIConfigOverrides = CLIConfigOverrides {ccSocketPath = Just "/ipc/node.socket", ccDbPath = Just "/chain-index.db", ccPort = Nothing, ccNetworkId = Just 1097911063}, acCommand = StartChainIndex}
chain-index_1     |
chain-index_1     | Logging config:
chain-index_1     | Representation {minSeverity = Info, rotation = Nothing, setupScribes = [ScribeDefinition {scKind = StdoutSK, scFormat = ScText, scName = "stdout", scPrivacy = ScPublic, scRotation = Nothing, scMinSev = Debug, scMaxSev = Emergency}], defaultScribes = [(StdoutSK,"stdout")], setupBackends = [KatipBK,AggregationBK,MonitoringBK,EKGViewBK], defaultBackends = [KatipBK,AggregationBK,EKGViewBK], hasEKG = Just (Endpoint ("localhost",12790)), hasGraylog = Nothing, hasPrometheus = Nothing, hasGUI = Nothing, traceForwardTo = Nothing, forwardDelay = Nothing, traceAcceptAt = Nothing, options = fromList []}
chain-index_1     |
chain-index_1     | Chain Index config:
chain-index_1     | Socket: /ipc/node.socket
chain-index_1     | Db: /chain-index.db
chain-index_1     | Port: 9083
chain-index_1     | Network Id: Testnet (NetworkMagic {unNetworkMagic = 1097911063})
chain-index_1     | Security Param: 2160
chain-index_1     | Store from: BlockNo 0

The docker-compose file:
version: "3.5"

services:
  cardano-node:
    image: inputoutput/cardano-node #:1.33.0
    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"
    ports:
      - 3001:3001

  cardano-wallet:
    image: inputoutput/cardano-wallet:2022.1.18
    volumes:
      - wallet-${NETWORK}-db:/wallet-db
      - node-ipc:/ipc
    ports:
      - 8090:8090
    entrypoint: []
    command: bash -c "
        ([[ $$NETWORK == \"mainnet\" ]] && $$CMD --mainnet) ||
        ($$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: testnet
    restart: on-failure
    logging:
      driver: "json-file"
      options:
        compress: "true"
        max-file: "10"
        max-size: "50m"

  chain-index:
    image: plutus-apps-dev
    volumes:
        - node-ipc:/ipc
        - chain-index.db:/mnt/chain-index.db
    ports:
        - 9083:9083
    entrypoint: []
    command: bash -c "cd /home/user/plutus-apps && ./dist-newstyle/build/x86_64-linux/ghc-8.10.4.20210212/plutus-chain-index-0.1.0.0/x/plutus-chain-index/build/plutus-chain-index/plutus-chain-index  --socket-path /ipc/node.socket --db-path /tmp/chain-index.db --network-id 1097911063 start-index"
    restart: on-failure
    logging:
      driver: "json-file"
      options:
        compress: "true"
        max-file: "10"
        max-size: "50m"

volumes:
  chain-index.db:
  node-mainnet-db:
  node-testnet-db:
  node-alonzo-purple-db:
  wallet-mainnet-db:
  wallet-testnet-db:
  wallet-alonzo-purple-db:
  node-ipc:
  node-config:

NOTE: I'm doing it in a single docker image following: https://github.com/input-output-hk/plutus-apps/blob/main/plutus-pab/test-node/README.md which seems to work. Also: https://www.youtube.com/watch?v=X6AyZIZ0vaE&list=PLNEK_Ejlx3x2sBWXHdFBRgkzPF6N-1LVi&index=10


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

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


text:
How to provide Datum value using serialization lib
I am consuming a script output and also create a new one at the same script address. The validator script requires the output producer to provide the datum value due to making assertions on it.
Therefore, I would like to know how can I provide a datum value for creating an output using the cardano serialization lib and not just the datum hash!
The only thing I saw was something called TransactionBuilder.set_auxiliary_data() but I am not sure whether that fits what I need.
Thanks for any advice in the right direction.
Currently I am doing something like this which obviously only provides the datum hash - not the value.
txBuilder.add_output(
    TransactionOutputBuilder.new()
        .with_address(scriptAddress)
        .with_data_hash(hash_plutus_data(myDatum))
        .next()
        .with_value(Value.new(amount))
        .build()
);

Thanks to Sebastien, there is an open issue for this.
Github Feature Request
Besides, one can attach the datum separately to the tx witness set, like so for example:
const datums = PlutusList.new();
datums.add(datumOfCurrentOutputToBeConsumed);
datums.add(datumOfNewOutputToBeCreated);

const transactionWitnessSet = TransactionWitnessSet.new();
transactionWitnessSet.set_plutus_data(datums);

I have the same issue and I write a comment in the cardano-serialization-lib repo. I hope it helps:
Reference: https://github.com/Emurgo/cardano-serialization-lib/issues/443#issuecomment-1195619916
There are two problems; first, the extra data isn't taken into account in the fee calculation and the second one is that you can't calculate automatically the script data hash with the tx builder if you are not calling a script redeemer.
For the fee calculation, I create a dummy WitnessSet and put the datums inside. When the witness set is ready, I use it to calculate the final length and I add this "extra fee" to the transaction builder configuration.
const plutusList = CSL.PlutusList.new()
selection.outputs.forEach(output => {
    if (output.plutusData) {
        plutusList.add(output.plutusData)
    }
})

const witness = CSL.TransactionWitnessSet.new()
witness.set_vkeys(CSL.Vkeywitnesses.new())
witness.set_plutus_data(plutusList)

const txBuilder = CSL.TransactionBuilder.new(CSL.TransactionBuilderConfigBuilder.new()
    .coins_per_utxo_word(CSL.BigNum.from_str(protocolParameters.coinsPerUtxoWord.toString()))
    .fee_algo(CSL.LinearFee.new(CSL.BigNum.from_str(protocolParameters.minFeeCoefficient.toString()),
        CSL.BigNum.from_str((protocolParameters.minFeeConstant + protocolParameters.minFeeCoefficient * witness.to_bytes().length).toString())))
    .key_deposit(CSL.BigNum.from_str(protocolParameters.stakeKeyDeposit.toString()))
    .max_tx_size(protocolParameters.maxTxSize)
    .max_value_size(protocolParameters.maxValueSize)
    .pool_deposit(CSL.BigNum.from_str(protocolParameters.poolDeposit.toString()))
    .build())

In the fee_algo method, I multiply wintess.to_bytes().length by minFeeCoefficient to add the extra fee necessary. The good part of this solution is that you can continue using the transaction builder as before.
The final step is to add the script data hash at the end just before calling buildTx(). The challenge is that you can't use the method calc_script_data_hash, so you have to calculate and set it. In my case, I use this lines:
if (plutusList.len() > 0 ) {
    const scriptDataHash = CSL.hash_script_data(CSL.Redeemers.new(), CSL.TxBuilderConstants.plutus_vasil_cost_models(), plutusList)
    txBuilder.set_script_data_hash(scriptDataHash)
}

txBuilder.add_change_if_needed(CSL.Address.from_bech32(address))

Remember to set the script data hash before calling add_change_if_needed, otherwise the hash will not be included in the fee.


text:
Any way to speed up cardano-node startup?
cardano-node is now taking around 50 minutes to start on my hardware, I dont do it often but its quite slow.  I think the issue is the process where it replays all the block chunks.
That seems to be pretty much a single threaded process, is there any way to parallelize it with more CPU cores?
Systemd service file:
[Unit]
Description=Cardano Node for mainnet
After=network.target

[Service]
Type=simple
RemainAfterExit=yes
ExecStart=/home/cardano/.local/bin/cardano-node run --database-path /home/cardano/cnode/db --socket-path /home/cardano/cnode/sockets/node.socket --port 3001 --config /home/cardano/cnode/config/mainnet-config.json  --topology /home/cardano/cnode/config/mainnet-topology.json
Restart=on-failure
RestartSec=60
User=cardano

[Install]
WantedBy=multi-user.target

Your node is starting slow because it was not stopped normally.
You can add more CPU Cores to the process, but this will still not start the cardano-node quick when it is stopped abnormally. But you can still make it start fast in this case by creating an empty file with the name "clean" in the db folder, while it is stopped, and then start it.
If you can post the systemd service file you use for the cardano-node service definition, I can tell you what to change so that the service is stopped normally.
EDIT: I updated your service file:
[Unit]
Description=Cardano Node for mainnet
After=network.target

[Service]
User=cardano
Type=simple
RemainAfterExit=yes
ExecStart=/home/cardano/.local/bin/cardano-node run +RTS -N -RTS --database-path /home/cardano/cnode/db --socket-path /home/cardano/cnode/sockets/node.socket --port 3001 --config /home/cardano/cnode/config/mainnet-config.json  --topology /home/cardano/cnode/config/mainnet-topology.json
Restart=on-failure
KillSignal= SIGINT
TimeoutStopSec=300
LimitNOFILE=32768
RestartSec=5

[Install]
WantedBy=multi-user.target

Thanks, I have asked about cleanly shutting down cardano-node before and never really got a good answer, question edited to include systemd file.  Also if more cores can be added, that would also be good, how can I do that please?

I edited my post with the required modifications to your service file.

Thanks, I didnt want the RTS flags but the other parts were useful

Hey George,
Initially, I got a sync error, so I deleted the files in 'chain' and 'wallets' from appdata Daedalus Mainnet folder and did a full resync. The issue is that it's been more than 24 hrs and it's at 78% synced.
Is there a way to speed up the Daedalus Mainnet sync process?
Thank you,
Florin


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

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


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

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

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

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

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

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

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

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

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


text:
How to read data from a Cardano node directly?
I know there are some tools out there that help reading historical data from the Cardano blockchain, such as IOHK's cardano-db-sync and blockfrost.io, but I would like to read directly from the a Cardano node I am running on my machine. I was trying to do this by using the cardano-cli, but it seems pretty limited, as it doesn't seem to have a way to get historical data from the blocks, like for example, what transactions got included into block X, or what are the inputs and outputs of transaction with the id 68f1f35323eada5601170011239c5e9b4dd15da559ceb9ad17cfd8eb7c317753 (random example).
I am probably lacking some knowledge here, but it seems to me such queries should be possible given the fact that in theory, I have all data from the Cardano blockchain directly in my machine.
Note: my cardano node comes from the Daedalus wallet.

No it's not possible with the current implementation of cardnao-node.
cardano-api (haskell API for interacting with cardano-node) doesn't have any method to query block or transaction from cardano-node
If you want to look at the queries that are possible, they are here.
cardano-api/src/Cardano/Api/Query.hs#L191

And if this is the case what type of data does PAB server/local cluster have access to from the local cardano-node? Is it best to setup PAB to access the local cardano node or would you recommend a different configuration for PAB during development and initial plutus script testing?

so tools like cardano-db-sync don't get their data from the cardano-node?

db-sync does get data from the node, via the local chain sync protocol, however that protocol is written in Haskell and uses CBOR encoding. Writing something to talk that protocol is totally doable but not trivial.

Such tools would have to be developed, either by IOG or other third party entities. Txpipe is working on such tools like Oura and Scrolls; both are still under development but are already a good step in the right direction. I'm sure there are others I am unaware of, but are mostly still WIP and lack a good UX.