text:
Why my cardano-node is now running a strange loop after an upgrade to a higher version?
Lately, after a node upgrade to a higher version (1.30.1), my Block-Producing (BP) node will "stay" in the "start" phase for about 45 minutes making a strange loop by switching to synchronization mode and then immediately going back to the "start" phase.
[2021-09-30 03:17:34.14 UTC] Replayed block: slot SlotNo 40283991 of At (SlotNo 40321032)
[2021-09-30 03:17:37.33 UTC] block replay progress (%) = 100.0
[2021-09-30 03:17:37.72 UTC] before next, messages elided = 40284006
[2021-09-30 03:17:37.72 UTC] Replayed block: slot SlotNo 40305522 of At (SlotNo 40321032)
[2021-09-30 03:17:37.72 UTC] Replayed block: slot SlotNo 40305529 of At (SlotNo 40321032)
[2021-09-30 03:17:40.52 UTC] block replay progress (%) = 100.0
[2021-09-30 03:17:40.58 UTC] before next, messages elided = 40305616
[2021-09-30 03:17:40.58 UTC] Replayed block: slot SlotNo 40321032 of At (SlotNo 40321032)
[2021-09-30 03:17:40.58 UTC] Opened lgr db

I'm running my node on a 8GB RAM Ubuntu LTS with 4 vCPUs. Any thought anyone?

Some SPOs in the community have reported that since version 1.29.x of cardano-node it requires at least 10GB of RAM to function properly. If your node has 8GB of RAM, maybe you should try adding swap (2GB or 4GB).
Assuming that you don't have any swap partition configured yet (Check it by running this command, if there is nothing back at the output, it means you currently don't have any swap space).
sudo swapon --show

STEP 1 - Create your swap file
sudo fallocate -l 2G /swapfile

Verify that the correct amount of space was reserved:
ls -lh /swapfile

you should see:
-rw-r--r-- 1 root root 2.0G Sep 30 22:59 /swapfile
STEP 2 - Enable the swap file
sudo chmod 600 /swapfile
sudo mkswap /swapfile
sudo swapon /swapfile

Verify that the swap is now available
sudo swapon --show

the output should be:
NAME      TYPE  SIZE USED PRIO
/swapfile file 2048M   0B   -2

STEP 3 - Add it to fstab to make it permanent at startup
echo '/swapfile none swap sw 0 0' | sudo tee -a /etc/fstab

Interesting, I was also thinking about the mem. Will try and let you know

It got better with decent swap space. Thx


text:
How to return funds from a smart contract
If I have assets (can be just ADA for simplicity) locked in a contract, how can I release the funds to the previous owners most efficiently?
Some more context regarding the question.
I created a pay endpoint (for the PAB), where different parties pay the same amount of ADA into a smart contract. Once a certain condition is met, the script can be consumed as an UTXO by another party (= getting paid some ADA). Until that condition is met, I want the parties that pay funds into the contract to essentially cancel the contract (= creating more appropriate UTXOs). In simple terms, the parties get their money back.
I have some code that solves this on a per-party basis, but I would like to get to the point where all parties get "reimbursed".

The best illustration of Plutus' capabilities in this case would be a Crowdfunding Contract.
Smart contracts are immutable, so the script must be triple-checked.

I want to create that moment. I thought tagging this questions with the appropriate tags would provide that context. I added more info.

Matthias, I've updated my answer.

I assume you have a redeemer that helps you understand when to run the "return founds" logic.
there are two options I can think you could implement, depending by how you expect the smart contract to be used
Use the Datum to keep track of the parties

you could store a PubKeyHash list ([PubKeyHash]) in the smart contract Datum and update the list for each new party.
if ever the "return founds" logic gets called you check that at least half the parties (or all of them if you prefer) have signed the transaction by checking the txInfoSignatories field

Important: due to the limited tx size you should use this approach if you expect not to have a lot of partecipants.

use tokens to identify parties

when someone decides to take part in the found you could mint some tokens to distribute proportionally to their contribution to the total found, and keep track of the total supply in the Datum
when the "return founds" logic is called you check for the input (or burned if you prefer) tokens to be at least half the total supply (or all of them if you prefer)
this approach should work also for a large number of participants since now the datum only stores an integer, no matter how many parties there are

source: Stack Exchange

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

sort: votes


text:
Could BTC migrate to Cardano?
According to research by the University of Cambridge, the Bitcoin network currently consumes around 100 terawatt-hours of electricity annually, enough to run a country such as Sweden.
The second largest crypto-currency, Ethereum, suffers from similar energy problems.
Given Cardano's amazingly low energy consumption, coupled with the recent success of making the blockchain carbon neutral (see Cardano forest), would it be possible to move $BTC to the Cardano network and, if so, what would be the exact process?
Also, putting aside the interests of Bitcoin miners, what impacts would Bitcoin users experience and how could these be minimalised?
(I'm exploring these questions, and more, at https://twitter.com/cardanoclimate)

Potentially yes, but practically it doesn't make any sense.
This is a controversial question. Everyone has their own opinion on this matter.
Cardano has been using the Proof-of-Stake consensus mechanism starting from its birth. In PoS network validators use staking for earning money. PoS does not consume such a monstrous computational power required to mine blocks - which is why Bitcoin and Ethereum eat so much electricity. Miners perform calculations according to the Proof-of-Work (PoW) consensus mechanism. By the way, Ethereum developers are currently engaged in changing the network consensus to PoS – it'll take a lot of time.
I don't know if Bitcoin holders will be interested in the transition to PoS - I think not. Staking earnings (up to 5% per year) cannot be compared to mining earnings. After all, no one will deny that the price of Bitcoin is determined by the cost of ASIC mining equipment and the cost of consumed electricity.

Do you have a reference for "the price of Bitcoin is determined by the cost of ASIC mining equipment and the cost of consumed electricity"? My understanding is that the price is solely determined by the demand for a fixed supply of BTC, regardless of the underlying network, and that the $BTC could exist as a token on a different blockchain.

No link is required here, this is a common logic. When mining gold, don't you take into account the cost of equipment and wages? So in the case of bitcoin - equipment and electricity are expensive, and these are obvious expenditures.

I'd have to agree, common knowledge is that the price of BTC must always be sufficient to pay the miners who mine it, otherwise, the network will fail. Cardano has its own mechanisms to secure the network which is different to PoW and so, we will see PoS coins will not always grow as fast as BTC.

These are complicated topics. It may just be me, but I need more than claims of things being 'common logic' in order to learn. Andy - we could stop mining gold and the value would be determined by the markets. @Patrick you seem to be saying that assets on PoW blockchains will grow faster than those on PoS chains. If that is the claim, could you provide some evidence?

Hi @immutablemind! I totally agree, these are complicated topics. However, unlike the gold mining industry, when Bitcoin mining stops, the network will crash and the asset value drops to 0. This is why Bitcoin mining will always be wasteful. But Cardano, in its turn, initially positioned itself as an eco-friendly network, and the founders of Cardano are unlikely to decide to change their basic principles – I mean the integration of Bitcoin as a side-chain. That's my humble opinion...

But the question is about achieving the cessation of mining  the uninterrupted continuation of $BTC by migrating all $BTC from the Bitcoin PoW blockchain to the Cardano PoS blockchain, thus retaining the value of $BTC as a store of value (with similar tokenomics). Somewhat similar to Ethereum's move from PoW to PoS -- but a lot simpler, because $BTC would just be a token on Cardano.

Well, I expressed my opinion. It would be interesting to hear the opinions of other members of the community.

This is half joke, and I'm neither an expert in BTC neither in Cardano, but the minting of BTC could be controlled in cardano by a kind of virtual Proof of work, in which miners would register asics with serial numbers by means of authorized oracles. By assign a computing power for each asic model, the virtual PoW could set the minting rates of each miner according with the computing power that they have bought, without even running such computing power.

Perhaps it's not that crazy. There's a long history of entities being paid to not perform certain activities that they provably otherwise could. It all comes down to financial incentives.

What would be the exact process?
Beware: I'm not certain this answer is correct (specifically whether an ouroboros sidechain could have $BTC as a UIA and the specifics of how the Bitcoin network would migrate across to using it).
Looking into this, Bitcoin could exist on Cardano as a sidechain with $BTC as a User Issued Asset (UIA). The nice thing about using Cardano sidechains is that transaction fees could still be in $BTC (instead of $ADA).
As to the exact process for achieving a migration, the answer lies with Ethereum's move to proof of stake and "the merge".

Image credit: consensys.net
The transition process would require the consent of client developers and exchanges in order to accept the changes. Consent of miners does not appear to be required.
However, Ethereum only exists due to Bitcoin's inability to evolve and make substantial changes. Unless something very significant changes in the Bitcoin world, it seems extremely unlikely that Bitcoin would attempt to chart a similar course. In addition, with so much money invest in equipment, mining would undoubtedly continue on a fork (similar to Ethereum Classic) raising the question of what would really be achieved.

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


text:
Plutus Pioneer lecture 3 homework 1 vesting logic
I'm having some trouble figuring out the vesting logic in homework 1 of the Plutus pioneer program lecture. I eventually gave up and looked at the solution which seems to be exhibiting the same "bug" (I put bug in quotes because clearly I'm misunderstanding something).
As I understand the logic of the transaction construction, the giver (or beneficiary2) can claim the gift anytime after the deadline while the recipient (or beneficiary1) can claim the gift anytime before the deadline (inclusive). Is that correct?
If so, I'm having trouble understanding why the following simulation seems to succeed. I'll provide screenshots and then go through my understanding of it. Here are the values entered for the simulation that seems buggy to me:

and here the final state of the blockchain:

In this simulation, Wallet 1 is giving 10 ADA to 39f713d0a644253f04529421b9f51b9b08979d08295959c4f3990ee617f5139f which is the hash of Wallet 2 (this can be confirmed by looking at the hash of the wallets in the final state screenshot). This gift has a deadline of 1596059101000 which is slot 10 based on:
Prelude Ledger Wallet.Emulator Data.Default Ledger.TimeSlot Week03.Homework2> posixTimeToEnclosingSlot def 1596059101000
Slot {getSlot = 10}

and
Prelude Ledger Wallet.Emulator Data.Default Ledger.TimeSlot Week03.Homework2> slotToBeginPOSIXTime de
f 10
POSIXTime {getPOSIXTime = 1596059101000}

Curiously, it seems that Wallet 2 can grab the gift at slot 11 which is after the deadline. It's very possible that my understanding of the transaction logic is incorrect. To double check, I also ran the same code with the following simulation (the only difference is that the second step of the simulation waits until slot 5 instead of slot 11) and it also succeeded which confuses me even more. I expect that one of these simulations should fail but can't figure out why.

Is there a bug with the solution for homework 1 in lecture 3? Am I misunderstanding something about the logic of the solution?
EDIT: here's another interesting point, with the suggested solution I can't seem to get Wallet 1 to grab the gift it provides. I've tried waiting for 1 block after the gift, waiting until slot 5 and waiting until slot 15 before attempting for Wallet 1 to grab it's gift and in all cases it fails - the "grab" transaction never reaches the blockchain and seems to fail client side with found 0 gift(s) to grab.

On first glance, I don't see any flaws in your logic. Could be a bug in the Playground? I don't have time rn to dig in further. I'll try to come back to it.

ah yeah, could be a bug in the playground. I'm running the playground on commit ea0ca4e9f9821a9dbfc5255fa0f42b6f2b3887c4 but now I'm realizing that the required plutus commit changes from week to week. ea0ca4e9f9821a9dbfc5255fa0f42b6f2b3887c4 is from week 1 while week 3 requires 219992289c6615e197069d022735cb4059d43229.

Changing the commit of the local plutus repo to 219992289c6615e197069d022735cb4059d43229 doesn't fix this unfortunately

It was a long shot. I don't use the Playground at all, I just use the Emulator Trace: https://github.com/input-output-hk/plutus-pioneer-program/blob/9c83322743e393427acdc24525b04dfc1c49084d/code/week05/src/Week05/NFT.hs#L87 It might be easier to debug your code using that (but that's jumping ahead in the progam).

Oops, checking out commit 219992289c6615e197069d022735cb4059d43229 does solve the problem, I must have fat fingered something in the earlier comment which said it doesn't. Commit ea0ca4e9f9821a9dbfc5255fa0f42b6f2b3887c4 seems to have a broken notion of time: https://cardano.stackexchange.com/questions/3997/plutus-playground-server-sense-of-time-is-incorrect/3998#3998

Haha. Good to hear.

Turns out I wasn't using the correct checkout of plutus. More details can be found at the following Cardano StackExchange answer: plutus-playground-server sense of time is incorrect


text:
What does it mean that Ouroboros is formally verified?
I was talking with some friends about Cardano the other day and I brought up the fact that Ouroboros is formally verified. One of my friends asked me to explain what that means and why it's significant. I did my best but I realized I wasn't confident with my grasp of the concept. Here's how I explained it:

Formal verification has 2 aspects:

the algorithm is described in a mathematical way explaining assumptions and outcomes (like the threat model). Proofs and lemmas are provided which provide a theoretical baseline for the algorithm's properties. Then this mathematical description is transcribed into a computer language specifically designed for proof evaluation to make sure the humans who wrote the proof didn't forget/miss anything.
Once the theoretical model has been validated it needs to be implemented in code and this implementation leaves a lot of room for error. After the developers are finished implementing the protocol in their language of choice (in this case Haskell?) the implementation is run through another piece of software (something like static analysis) which somehow evaluates all possible code paths (in a general heuristic sense, maybe not literally) and compares those code paths with the computer model created in step 1.

If the implementation matches the theoretical model, then we can say the code is formally verified.

Is this explanation correct? How accurate is my explanation? What's missing? How can I improve it?

According to Wikipedia a Formal Verification is:

In the context of hardware and software systems, formal verification is the act of proving or disproving the correctness of intended algorithms underlying a system with respect to a certain formal specification or property, using formal methods of mathematics.

Thus, the principles on which the operation of the Ouroboros protocol is built have been mathematically proven, or formally verified. As we all know, Cardano is based on peer-reviewed academic research. You are absolutely right.
For details on Ouroboros, read this IOHK paper.


text:
What's the difference between programmable validators and smart contracts?
Charles Hoskinson indicated in this tweet that he favors the term "programmable validator" to the term "smart contract" with regard to Cardano.
Quoting the tweet Charles Hoskinson is responding to, "In Cardano, "smart-contracts" tend to refer to the combination of the on-chain validator(s) and the off-chain code that's driving it / them."
Here's what I've gathered so far.  (This is speculation.  Please do not believe it and please do correct it in the answers and comments.)
All operations (and data) necessary for Cardano to function are executed (and stored) on 3rd party-owned compute resources known as "validation nodes" (with the caveat that Cardano itself owns a number of "validation nodes").  The results returned by these 3rd parties can be trusted, statically speaking, thanks to redundancy -- each operation is performed by all nodes in a random sample of validation nodes, and results are checked against each other.
This also describes code running "on-chain" and AFAIK is similar to how contracts execute on Ethereum.
All blockchains have "off-chain" code driving the miners or validators.
Are all these statements correct?  If not please correct me and if so, what's the big difference between Cardano contracts and contracts on other chains alluded to in the above tweets?

You are asking a few questions here, so I'll try my best to point you in the right direction. I feel like KtorZ did a great job explaining it, but it doesn't hurt to put it into different words.

Terminology
Validator or Validator Script: (not to be confused with validation nodes) Code used to say "yes" or "no" to transactions spending UTxOs at the script address
Minting Policy: Code used to say "yes" or "no" to transactions forging tokens from the policy address
On-Chain Code: Validator Scripts and Minting Policies (for the most part). This code is run by the validation nodes in conjunction with relevant transactions.
Off-Chain Code: Code for building and submitting transactions. Typically referring to wallet code, but technically the Cardano CLI can fulfill the same role to some extent

Background
A common misconception about Cardano "smart contracts" is that the "on-chain" code is a program. That you send some "smart contract" to live on the blockchain and it "runs" or "executes" like a normal program with processes and state.
This is wrong.
In reality, the "on-chain" code is just used passively to validate transactions. It just says "yes" or "no".
So, "off-chain" you can build whatever transaction you want: mint a million stable coins or take all the liquidity of a DEX for your own. The "on-chain" Minting Policies and Validator Scripts are what keep you from doing that. The "on-chain" code doesn't do anything, it just keeps you from doing bad things.

Answer
This is the distinction I think people are trying to make.

What's the difference between programmable validators and smart contracts?

Smart contracts on other chains are pieces of code that have shared, mutable state and imperative logic to change that state. More similar to programs people are used to writing.
On Cardano, state may be stored on chain, but the logic of how to change state lives off-chain and the on-chain code just validates your transaction. It will never produce anything or change state for you.
One might call other chains' model "smart contracts" and Cardano's model "programmable validators". What's important is that they achieve the same goal with different paradigms.

Sorry this is so long.

Thanks @mitchell-turner!  So in summary, on Cardano, contracts that execute on-chain can only function to accept or reject transactions (submitted to that contract's address), as opposed to on other chains where smart contracts can create transactions.  Is that right?

That's close. I think you're using "transaction" slightly wrong. On Cardano, a transaction is literally the proposed state change, and it must be validated to be executed. Whereas on other chains, a transaction is telling a smart contract what you want, and it tries to perform the state changes for you. If that makes sense.

That does make sense.  Thanks again @MitchelTurner!


text:
Is there any platform to read the Mempool?
I want to see the queued transactions in the mempool, where can I see that?
Thank you.

Is there any Update on that issue as of today? So is there any chance to read (historic) cardano mempool transactions?

Please see this API: https://docs.blockfrost.io/#tag/Cardano-Mempool
Also note that a mempool is a local viewpoint, and other nodes might have a different mempool at the same time. It's a local measurement of an individual node.

Cardano doesn't have a mempool in traditional sense, due to the fact that you have only 20 second interval between previous block and a current one. It is rather a kind of stack that stores an average of 60-90 transactions. And someone hardly needs an API that reads a 20 second stack.

But I'd like to add that it is possible. Open whatever process you need as a child of a process you are in control of. You'll now have access to the memory buffers. It will take forever to figure out what is what and is deffs hacking but can be done if the need is truly strong enough

A protocol to interface with the local mempool was merged recently in the context of a larger piece of work to increase network throughput. It can now be accessed from Ogmios.
Even though, unfortunately it does not provide access to transactions received from peers - only to those submitted locally.

You should follow the referencing guidelines when referring to external sources.  Your answer may not work well if the external sources move or change.


text:
plutus-playground-server sense of time is incorrect
I think my plutus-playground-server has an incorrect notion of time. I'm working on the homework for lecture 3 and keep running into issues with the simulator.
Here's a screenshot of what I'm simulating for homework 2 of week 3:

I've verified that, according to the cabal repl, 1596059101000 is slot 10.
Prelude Ledger Wallet.Emulator Data.Default Ledger.TimeSlot Week03.Homework2> slotToBeginPOSIXTime de
f 10
POSIXTime {getPOSIXTime = 1596059101000}

Note that in the example simulation I Wait Until Slot 11.
I've changed the following line when constructing transactions clientside to show now: https://github.com/paymog/plutus-pioneer-program/commit/4098f73bef4191ebc976fb8c2c3d46ee53f97b5e#diff-7fd9bde64b988d6aa9520167ed285990ed737f5dbda967ac19c786ff4160bb36R105
Interesting, when I execute the above simulation, I see the following output:
Add slot 11
Contract instance for wallet 2: (ReceiveEndpointCall (EndpointDescription { getEndpointDescription: "grab" }) (RawJson "{\"contents\":[{\"getEndpointDescription\":\"grab\"},{\"unEndpointValue\":[]}],\"tag\":\"ExposeEndpointResp\"}"))
Contract instance for wallet 2: (ContractLog (RawJson "no gifts available at time POSIXTime {getPOSIXTime = 1596059102}"))

Note that the value of now is 1596059102 which is missing three trailing zeroes compared to 1596059101000. If I check the posix time of slot 11 in the cabal repl I see
Prelude Ledger.TimeSlot Data.Default Week03.Homework1> slotToBeginPOSIXTime def 11
POSIXTime {getPOSIXTime = 1596059102000}

which is the value reported by the simulation with 3 extra trailing zeroes.
Does my instance of the plutus-playground-server have a "incorrect" notion of time?

As is typical, I figured out what's wrong almost immediately after posting the question. I was on the wrong commit for my local checkout of the plutus repo. I was using commit ea0ca4e9f9821a9dbfc5255fa0f42b6f2b3887c4 which comes from the week 1 cabal.project file.
The week 3 cabal.project file requires plutus at commit 219992289c6615e197069d022735cb4059d43229. After I made that change, the issue resolved itself.


text:
Sync DB mainnet stuck
I used the great guidance on https://developers.cardano.org/docs/get-started/running-cardano to step by step sync with the Cardano mainnet.
Everything went fine and i was almost done untill 2 weekish ago when synching slowed down dramatically (practically halted) on Epoch 289.
Any idea what i can do to resume the final epochs to fully sync with the mainnet?
Thanks
[LAPTOP-0:cardano.node.DnsSubscription:Error:254524] [2021-10-02 21:22:51.50 UTC] Domain: "relays-new.cardano-mainnet.iohk.io" Application Exception: 18.159.65.82:3001 MuxError MuxBearerClosed "<socket: 45> closed when reading data, waiting on next header True"
[LAPTOP-0:cardano.node.ErrorPolicy:Warning:108] [2021-10-02 21:22:51.50 UTC] IP 18.159.65.82:3001 ErrorPolicySuspendPeer (Just (ApplicationExceptionTrace (MuxError MuxBearerClosed "<socket: 45> closed when reading data, waiting on next header True"))) 20s 20s
[LAPTOP-0:cardano.node.DnsSubscription:Error:254541] [2021-10-02 21:22:51.59 UTC] Domain: "relays-new.cardano-mainnet.iohk.io" Application Exception: 3.127.133.53:3001 MuxError MuxBearerClosed "<socket: 49> closed when reading data, waiting on next header True"
[LAPTOP-0:cardano.node.ErrorPolicy:Warning:108] [2021-10-02 21:22:51.59 UTC] IP 3.127.133.53:3001 ErrorPolicySuspendPeer (Just (ApplicationExceptionTrace (MuxError MuxBearerClosed "<socket: 49> closed when reading data, waiting on next header True"))) 20s 20s

Thanks @Patrick - much appreciated. I'm indeed on 1.27. i followed the guidance on https://developers.cardano.org/docs/get-started/installing-cardano-node - any chance you can direct me to guidance how to update to 1.29 as you mentioned in your answer?

Hmm have you looked into your firewall settings? Has anything changed on your local machine?
The timing of the issue would tell me it's a version issue but the instructions you followed would suggest otherwise. Run:
cardano-cli --version
Should be atleast 1.29 to proceed. Also check the version of DB sync as protocol has been extended post-Alonzo.

Hi I also had the same issue weeks ago,
it got fixed by following this guide: https://forum.cardano.org/t/solving-the-cardano-node-huge-memory-usage-done/67032
Another thing I also noticed is that it can also be fixed by increasing your swap mem.
However, now I am also having problems with epoch 299 from my db sync.
Upon further inspection it has 570k transactions, which is worse than the epoch you have.
Edit: or it could be your version, since there was the alonzo hardfork as patrick mentioned.

Sometimes errors like this can occur when you put the computer to sleep while the node is syncing, if you have a laptop this can occur more frequently due to different methods between deep sleep & light sleep. Laptops are designed to be super power efficient some even turn off the network card depending on which OS & which sleep mode you have enabled. That could very easily cause this sync hang.
Also I see you have followed the Cardano developer docs which take you through the process of running a node as a executable on your machine; I'd recommend running a Docker container since it's easier to use if you get configuration messed up.
Here are some steps I'd take to remedy this since I've seen some Odd things when the following occurs while a Node is running.

Check if the Partition (could be your main drive on your laptop) you are installing this on has enough space to keep syncing the mainnet, mainnet's can be rather large in size so make sure you have enough space.
Make sure the syncing process isn't exceeding the memory limit you have. When I was deploying a node on a low tier server a while back save money I had your issue simply because I didn't have enough memory & the machine was killing background resources until it crash.
Wi-Fi can be spotty so try a hardwired connection.

Other than the following, I don't know what else to tell you, you could always try Docker & see your result their.


text:
How can I derive an address from a private key?
Checking the official documentation from cardano-wallet I can see that there are options to get wallets from mnemonics and extended public keys, but not private keys.
Even public libs don't have that option. And as far as I know it's not possible to restore a wallet from a private key in Daedalus or Yoroi.
It's a somewhat simple functionality that I can't find any info about!

A robust way to do that is to use cardano-wallet CLI.
First of all, run cardano-wallet serve and cardano-node.
Root Key
The command that helps us writing a root private key into a file should look like this:
cardano-wallet recovery-phrase generate --size 18 \
    | cardano-wallet key from-recovery-phrase Shelley > secretKey.prv

It results in private key creation that might look like this:
root_xsk1vrv54w0rpg6j9qz54ed48hjf99k0qt7p4wu5l3y55tlpk8684dphx6a8xw82u3vsgwcv6n8mdxwczhfhusy22eknmdpjn9lnyram0alqaa7mwjx4rg0eyh3ckv0el34j5vswquzhvrpaze6ju6s623fs4ylx346v

Derivation Path
m / purpose' / coin_type' / account_index' / role / address_index

If you tap a 20th receiving address in Daedalus wallet you'll see the following path:
m / 1852H / 1815H / 0H / 0 / 19

where 1852 is a hardened Shelley-era address type, and 1815 is hardened ADA's index.
Account Keys
According to this scheme let's create account private key and account public key:
cat secretKey.prv \
    | cardano-wallet key child 1852H/1815H/0H \
    | tee account.prv \
    | cardano-wallet key public --with-chain-code > account.pub

These results are:
acct_xsk10ra048lvz7le0y5pkmqmceuf492u64nv8edk9qsh3036jtz84dp3xqns35edmhag0nke3xmhm87368v8mtr5d2ryd3ucjgg6e5vjf7r8eu4ejhpyax2us59c73pt7sduvddy934k8p925xxsqvc2hh8nnug24fq6

...
acct_xvk1fpqtkwf8yy5rn3f79a4vr4fpd9rxxfheursjzqw8kgj0qf3q98ux0netn9wzf6v4epgt3azzhaqmcc66gtrtvwz24gvdqqes40w088c36lqsu

Create a wallet
cardano-wallet wallet create from-public-key < 128-bit hash of acct pub key >

Additional reading
If you need more details on Cardano CLI, please read my Medium stories:

Cardano 911 — Wallet Command Line Interface (Part One)
Cardano 911 — Wallet Command Line Interface (Part Two)

That's for sure helpful. So I'd just start from the second step since I already have the private key. However, the question was geared towards achieving the same result programmatically, without the necessity of running a node or bash commands.

It entirely depends on the framework for the language in which you are developing. Many frameworks are in development at the moment. I personally use Swift – there are no any Cardano libs for Swift, except this one: https://thecardanofund.com/product/cardano-swift-sdk/


text:
How do I parse multiple values stored in datum in Plutus
So I am storing multiple values in my datum but I don't know how to read them in Plutus code.
Also I am very new to Haskell so explain it in a simple way please.

Your question is not clear enough. It depends on how your datum is stored. Show relevant code. Not all your code, just the relevant part, where your datum is defined and where you are trying to use it.

Check out the free haskell resources:
You may want to learn about record syntax probably, among other things
Haskell and Crypto - Mongolia course by IOHK (Lars and Andres Löh)
https://github.com/iohkedu/haskell-2020
Learn you a Haskell free ebook (really good for quick reference)
Learnyouahaskell.com

you define your Datum in your smart contract, so you should show us how your datum is defined in order for us to help you
also if you are using the low-level BuiltinData ( the UPLC version of Data) keep in mind it is so defined in the PlutusTx module documentation
data Data
    =
    | Constr Integer [Data]
    | Map [(Data, Data)]
    | List [Data]
    | I Integer
    | B ByteString

in this case it strictly depends by the transaction that has been set to the smart contract that created the UTxO you are spending (which is from where the Datum comes).
Also, I strongly suggest you to learn the Haskell syntax before diving into smart contracts, here's a youtube playlist that helped me


text:
Pool Rewards distribution via SmartContract
For the Pool I run I would like to setup a SmartContract which automatically claims the rewards and sends a certain percentage to each of three organisation I support.
Is such a thing possible with smart contracts?
Can a SmartContract claim rewards?
Or do I have to claim the rewards "manually" and then send them to the Smart Contract to to it's work ?

Is there a reason your "three organizations" can't just stake from their own wallets and manage their own rewards?

I wan't to support three organisations via the rewards the PoolOwner (me) earns. The idea is to establish an automatic way to donate the pool owner rewards. The Rewards of "regular" delegators are not touched by this.

I think it would make more sense to write an off-chain script to do this for you. There is no trust involve (you already have access to your own spending key); there is no need to get the network to validate your transfers. And you are going to need a script/off-chain worker anyway to trigger the smart contract to send funds.

Ok thnx for the clarification, I thought about offline code initially, but like the fact that a Smart contract has the distribution written in code. I guess the best solution is then be to claim the rewards manually and send them to a smart contract address. Kind of an hybrid approach.

The funds from a smart contract can be delegated to a stake pool. So if you wanted to have all the staked funds live at the contract you could accomplish something similar to what you are proposing.
There isn't such thing as "automatically" for Plutus smart contracts. They are passive. That being said, it might still make sense for you to set it up in a way that anyone (usually you) could trigger the distribution of the rewards. Each of these transactions will cost a small fee of course.

Can you explain hat you mean by "smart pool" never heard that ?

Typo. Meant "stake pool." Woops. Fixed it.


text:
How to get balance of an address using Cardanosharp
I am trying to develop a simple program where I am able to generate an address successfully using a public key and a stake key. The network type is TestNet.
How can I check the balance of the generated address?
Code snippet is as follow:
var existingaddresses = _Addresses.Find(x => x.WalletId == wallet.Id).ToList().Count;
            var user = _users.Find(x => x.Id == wallet.UserId).FirstOrDefault();
            NetworkType net;
            if (IsMainNet)
            {
                net = NetworkType.Mainnet;
            }
            else
            {
                net = NetworkType.Testnet;
            }
            Mnemonic mnc = keyService.Restore(wallet.Words, WordLists.English);
            PrivateKey masterKey = mnc.GetRootKey(user.Password);
            string PaymentPath = $"m/1852'/1815'/0'/0/"+ existingaddresses;
            PrivateKey paymentPrv = masterKey.Derive(PaymentPath);
            PublicKey paymentPub = paymentPrv.GetPublicKey(false);
            string stakePath = $"m/1852'/1815'/0'/2/"+existingaddresses;
            PrivateKey stakePrv = masterKey.Derive(stakePath);
            PublicKey stakePub = stakePrv.GetPublicKey(false);

            Address address = addressService.GetAddress(paymentPub, stakePub, net, AddressType.Base);

Now I want to check the balance of the generated address.

You can use the Blockfrost.io API to get information about the address. I'd recommend using the blockfrost-dotnet package for this.

I have tried it but i am getting content not found exception which means this Address doesnot exist on test net. Isnt it? What can be the reason?

I think this happens if the address has never been used.

agreed. as address is never used. Any idea what can be done to activate the address on testnet?

Send some tADA to that address: https://testnets.cardano.org/en/testnets/cardano/tools/faucet/


text:
What are the best solutions for randomness in Cardano?
I would like to create a gambling Dapp and for this I need a provably fair RNG. What are the best solutions for provably fair randomness in Cardano
Will Cardano add Chainlink VRF in the future?

Thanks for asking a question @hanno! It is, though, on the edge of guidelines... 'wen' is almost never helpful question here.
If you rephrase to ask about the best solutions for randomness in Cardano, I think it will add more value. (And people will be more likely to respond, as that is more in scope).
PS-- I'll answer about how to stay informed in discord :)

Also, look into the ergo raffle dapp. I would assume they need verifiably fair randomness for that, and it's in EUTxO like Cardano.

Ergo does not use a provably fair RNG

Thanks for updating @hanno, and checking out my (ultimately disappointing) reference. Upvoted your question!

@MatthewCapps you are really great helper as you are trying hard to help. Great attitude
Ergo as I understood is taking randomness from the previous block header

as I did not get any answer to my question do I need to assume that there is no randomness solution for Cardano?

Have you checked genSeed function from Cardano.Crypto.VRF.Praos module?
This module is the Haskell implementation of libsodium, the library used by Algorand and Cardano to generate Verifiable Random Functions (VRF), which are key at the time of randomly choosing validators in both chains.

I don't think this can be compiled to Plutus in on-chain code

Can you please explain the reason? I'm just starting with Plutus and I understand that all Haskell code can be compiled to Plutus.

Not all Haskell code, we have some builtins and only they can be used inside validators. So you wound't be able to use any haskell function at all since they don't use those builtins, but we can use the plutus prelude which contains a bunch of equivalent functions

Thanks for clarifying!

For The Open Source Cardano Lottery, I have created a pseudo random number onchain validator that uses parts of a tx id for the source of a random number.  I am open to any feedback on this approach, but from what I have tested, I can't guess what the winner lotto ticket number will be in advance :)
https://github.com/lley154/cardano-lottery

But I guess you could "select" the result, since you you can use any of the N UTxOs you have and each UTxO has a different tx id

To clarify @Mateus, the lottery number is chosen by players before the final close tx is created.  Only after the window to choose a winning number is closed is another transaction created that is used to derive the winning numbers.   So someone would have to predict in advance what a tx id will be - which I believe is not possible.

I see, so the tx id of the script it self is used?

yes, but only after the window to choose a winning number is closed.   I created a state machine smart contract that ensures that only when the lotto is in the correct state that a winning number can be chosen from a UTXO (that must inclue the lottery thread token).

It is not possible to generate random numbers on-chain. In your lottery, you set the winner with the closing transaction. The party doing this will inevitably have the power to chose the winner freely. There is no way to effectively prevent this. using the tx-id does not help. You can fine-tune your UTxO to get the tx-id you need.

Hi Jey, thanks for your feedback!   The lottery uses a state machine which transitions from a state that players can buy a ticket to a state that players cannot buy a ticket.  It is during this "player can't buy a lottery ticket" that a transaction is created by the lotto admin to draw the winning number.   The winning number is derived by the transaction id locked at the lotto script address which was created by transitioning the to "player can't buy" state.   By using a thread token design pattern, only the lotto admin and only during the proper state can a specific UTXO be used .

Hi lley154, what mechanism do you think prevents the lottery admin to pick the winning number freely (i.e. setting the tx-id of his choice when transitioning to the state "player can't buy") ?

Hi Jey,  in order to submit the close transaction, the UTXO must contain the thread token.  So, this prevents the lotto admin from choosing any arbitrary UTXO.  This thread token can only be spent (and then be part of a UTXO) after the lotto numbers have been chosen.   I really need to write up a diagram on this, but really appreciate the questions to see if there are any holes.  I created a youtube video of going throug the lottery process, but not sure (and don't expect) if you'll have time to look at that.  https://www.youtube.com/watch?v=q55nU9mwZYg&t=105s

I quickly went over the video. You draw your winner from the tx-id. You treat your tx-id as if it was a source of randomness. But it is not. Maybe explain why you think that your lottery has the following 2 properties: i) the party behind the admin cannot steel the pot (through a combination of acting as admin and as a buyer), ii) the winner ticket is not known in advance (i.e. cannot be computed by looking at the blockchain).

Hi @Jey,  I realized that the tx-id is not a true random number, but I thought it might be sufficiently difficult to predict it several transactions out.  But after doing some more testing, you are correct and it is possible to predict each transaction in advance until you get to the close transaction. There is also nothing to stop the lotto admin from being a player, but this is by design, so the crux of the issue is to make the winning number truly random.  Looks like I will look at using an oracle to salt the winning number selection so it can’t be predicted in advance.  Thanks again!

Hi @lley154, you're welcome. In a hobby project, I implemented a lottery that combined (i) a root number committed through a hash at creation by the lottery admin with (ii) a number (either 0 or 1) that every ticket holder could add to he oracle. Thus, the admin would need to buy the whole lottery to pick a ticket at choice. And a normal ticket holder cannot do more than pick at random because he does not know the root number. I'm not sure this approach has no holes, but it looked promising to me.

Hi @Jey,  interesting approach and I like the idea that each ticket purchased provides entropy.  The only downside I see is that the oracle needs to be updated via ticket purchases and that it may be difficult to easily audit this openly.  Ideally it would be great if the oracle used some publicly known random value so at least there can be an open audit/review once the winning numbers are revealed.   This doesn't prevent the admin from rigging the system, but does allow everyone to know if the lottery was fair.   By using multisig there could be some checks and balances as well.

Hi @Jey,  I just realized that if you require the number of tickets purchased be greater than the total amount of Ada locked in the lotto contract, this will disincentive the lotto admin from buying all of the lotto tickets.   If you also require ½ of all purchased tickets to be revealed, this prevents predicting the winning number as well.  So, I prefer your approach.  I have submitted a draft proposal in Fund 9, please message me on catalyst if you would like to be a co-proposer and we can discuss level of involvement if interested.  https://cardano.ideascale.com/c/idea/415197

It depends on the use case, but nut.link has been submitting the League of Entropy randomness beacon.

Getting randomness into smart contracts is a bit difficult on Cardano due to it's deterministic nature. In some cases, committment schemes can be used: https://www.youtube.com/watch?v=JXKf1JwVAOE which rely on the one-way property of hash functions. In this example, it's applied to a game between two parties, which are real competitors, so neither of them wants to reveal their secret information to the other and the outcome is indeed random.
This doesn't work when the different parties might have some incentive to cooperate (e.g. against the operator)
One can also "collect entropy" from multiple parties as it was done here:
https://github.com/input-output-hk/lobster-challenge
One can use a RNG oracle, but still has to deal with the determinism. So even if it's a perfectly fair random number, the gambler might just decide not to play (=submit their tx) in case they would loose. Maybe one can overcome it with validity intervals for tx and penalties for not submitting a tx, but it has some obvious drawbacks.


text:
Hooks empty after calling endpoint
I'm finding it difficult figuring out the cause of this hiccup. When I create an instance of a contract, the hooks are populated, but after calling an endpoint, the hooks list becomes empty.
Status of Contract Instance before endpoint invocation:
{
    "cicCurrentState": {
        "observableState": null,
        "logs": [],
        "hooks": [
            {
                "rqID": 2,
                "itID": 1,
                "rqRequest": {
                    "aeMetadata": null,
                    "aeDescription": {
                        "getEndpointDescription": "cancel-ob"
                    }
                }
            },
            {
                "rqID": 1,
                "itID": 1,
                "rqRequest": {
                    "aeMetadata": null,
                    "aeDescription": {
                        "getEndpointDescription": "create-ob"
                    }
                }
            }
        ],
        "err": null,
        "lastLogs": []
    },
    "cicContract": {
        "unContractInstanceId": "a39797ac-bbb6-449b-a389-35b096882df6"
    },
    "cicDefinition": "OB",
    "cicWallet": {
        "getWallet": 2
    }
}

After endpoint invocation:
{
    "cicCurrentState": {
        "observableState": {
            "ttCurrencySymbol": {
                "unCurrencySymbol": "dffa71c3c512fe6ab8c0d72651a6122fb5d11042ef53d7131a47ca2c"
            },
            "ttOutRef": {
                "txOutRefIdx": 1,
                "txOutRefId": {
                    "getTxId": "b135806142f3d020fc68e9e72fa6e8e7c8fce34b2a0f17fd23b633641f58944a"
                }
            }
        },
        "logs": [
            {
                "_logMessageContent": "OB sent ",
                "_logLevel": "Info"
            }
        ],
        "hooks": [],
        "err": null,
        "lastLogs": []
    },
    "cicContract": {
        "unContractInstanceId": "a39797ac-bbb6-449b-a389-35b096882df6"
    },
    "cicDefinition": "OB",
    "cicWallet": {
        "getWallet": 2
    }
}

After calling the endpoint, a ThreadToken  is returned, but all hooks are gone, thereby rendering the instance useless.
Example of what happens when an endpoint is called:
EndpointCallError (EndpointNotAvailable (ContractInstanceId {unContractInstanceId = a39797ac-bbb6-449b-a389-35b096882df6}) (EndpointDescription {getEndpointDescription = "cancel-ob"}))

Endpoints will become unavailable for a given contract instance id when falling of the happy path (e.g. redeemer not validating). I see that you have no errors recorded though.
How do you have your endpoints hooked up and how did you test this behavior?

It turns out the contract being called from the ContractInstance has a delay that listens for change of state of a StateMachine until a certain deadline and hence hadn't completely executed the contract, which would consequently enable it publish the hooks and other details relating to the contract.
Calling an endpoint from the same ContractInstance led to the error.


text:
Is ada an asset, token, both, neither?
According to the docs, ADA is an asset and a token, but they also indicate that tokens are on-chain versions of some off-chain asset. They also compare ADA and tokens in ways to imply that they are not the same kind of thing.
So, what is it? what is it called?

The terms cryptocurrency, token and asset are not mutually exclusive.
However, there are specific definitions that show a subtle difference between these three terms:
Cryptocurrency

Cryptocurrency is a digital asset that circulates on the internet as a medium of exchange. It employs blockchain technology — a distributed ledger of transactions that is publicly available — and is secured by advanced cryptography. This revolutionary asset architecture allows for certainty that cryptocurrency coins and tokens cannot be double-spent even in the absence of a centralized intermediary. The first cryptocurrency to achieve mainstream success was Bitcoin which paved the way for the proliferation of many other cryptocurrencies.

Token

Within the context of blockchain technology, a token generally refers to a unit of value for a programmable asset that is managed by a smart contract and an underlying distributed ledger. Tokens are the primary means of transferring and storing value on a blockchain network [...]. Tokens can also be designed to be either fungible or non-fungible, depending on a network's specific needs. And while many tokens are primarily used for simple transactions, an increasing number of blockchain projects are designing tokens encoded with a variety of wide-ranging use cases, primarily in regards to on-chain governance and network maintenance.

Asset

An asset is anything of monetary value that can be owned or purchased. Within the context of investing, assets can refer to a variety of financial and physical instruments, from stocks to real estate to gold to dollars. A bitcoin is a particular form of crypto or digital asset.

these are definitions used in blockchain generally. Im asking specifically for cardano. the docs dont appear to be using the same definitions.

Hi @wolverineks! Cardano does not exist in isolation from reality. Everything that is inherent in other blockchains and networks, to a certain extent, is inherent in Cardano.

Ada is a digital token on the Cardano blockchain. Its currency symbol is the empty string - "".
It is similar to any other token that can be minted on the Cardano blockchain. However, there is a key difference.
A token are represented by a currency symbol which is the hash of the minting policy that is used to create it.
A minting policy describes how a token can be minted and burned, and no policy can mint or burn Ada, hence the empty string, which no policy can hash to.

"Ada is a digital token"
so, you're saying that ada is not an asset?

I think the terms are not mutually exclusive @wolverineks. Ada is a digital token, the native currency of Cardano, and it is an asset specified by those two properties I just named.
Tokens can also represent off chain assets; this valuable property is part of what makes those tokens assets-- that is, a valuable thing to own (rough def. of 'asset').
I could be wrong if I'm unfamiliar with some specific technical meanings of the terms, but that is how it appears to me, prima facie.

are all tokens digital? iow, are there non-digital tokens on cardano?
are all tokens currencies on cardano?
are there non-native currencies?
tokens can represent an asset, but do they have to?

I would probably go down the route of calling ADA a financial instrument. From a technical perspective, IT IS a token with no currency symbol. Thus, IT IS a native token, it just can't be minted or burnt (unless you take the PoB paper published by IOG and implement it - I have spent some time reading that paper and it seemed to me as though you could only accomplish PoB with P2PKH addresses - maybe if you flipped some bits in Byron addresses? - but you could just create an address and destroy/rm the private key and throw away the key derivation phrase, if you REALLY wanted to burn some ADA).


text:
How to run smart contracts in the Cardano Blockchain?
I know that since Alonzo was launched smart contracts can be published in the blockchain now, but I have no idea how to do it.
I have read some articles about the Plutus Application Backend though, it's a platform to work with Plutus scripts and provides an API to run those scripts via an endpoint that it's embedded in the script. But this means that smart contracts that run in Plutus are still off-chain in the local machine instead of being running on-chain. Is this true?
Or am I missing something like other library that works with the Plutus smart contracts and can interact with my web DApps?. Please if there is any suggestion I would appreciate it.

How to run smart contract in Cardano Blockchain?

PAB isn't available yet outside of development. The only way to submit and interact with smart contracts on-chain is with the cardano-cli. Here is a thorough tutorial on how to do that.

But it means that smartcontract that run in plutus still off-chain or running in local machine instead of running on blockchain. Is that true?

I'm not sure if this answers your question, but if you are curious where the smartcontracts live, my answer over here might help.

honestly, i would like to create a program for my thesis for achieving my bachelor. so mostly my dapps would be running in public testnet with PAB. is it possible?

I don’t understand, even Charles Hoskinson said the PAB is released. The GitHub page list a pre-release of the PAB. I thought it would be possible (even if at own risks) to connect to the mainnet with it.

You can run smart contracts with the cardano-serilization-lib and its js libraries. Check https://github.com/Berry-Pool/spacebudz to see an example. This allows you to host a web dApp where the user can connect with their Nami wallet, sign transactions that can contain datum, redeemer, everything needed to interact with smart contracts.


text:
Must spend UTxO constraint when minting NFT
I'm currently going through week 5 of the plutus piooner lectures, and I have some questions about the NFT process. Here is a reference with the complete code, but here are the important parts:
The on-chain part makes sense to me. We want our NFT to be unique, so we take as input a UTxO (always is unique) and check that we're minting only one token:
mkPolicy :: TxOutRef -> TokenName -> ScriptContext -> Bool
mkPolicy oref tn ctx = traceIfFalse "UTxO not consumed"   hasUTxO           &&
                       traceIfFalse "wrong amount minted" checkMintedAmount
    where
    ...

The off-chain part is what brings me some confusion, so let's lay down what we want to achieve:

We need to build a transaction that spends a specified UTxO and mints only one token.

The most relevant part of the off-chain code is this:
let val     = Value.singleton (curSymbol oref tn) tn 1
    lookups = Constraints.monetaryPolicy (policy oref tn) <> Constraints.unspentOutputs utxos
    tx      = Constraints.mustForgeValue val <> Constraints.mustSpendPubKeyOutput oref

I understand that mustSpendPubKeyOutput makes sure that the transaction to be built contains the necessary UTxO (oref) so that the on-chain policy passes. What happens behind the scenes? If the constraint is not specified Plutus will just use it's own logic to grab the UTxO used for building this transaction? If the constraint is not specified, is there still a chance that the right UTxO will be used?

What we need is to build a transaction that spends the required UTxO. One way of doing this is what we done before by specifying a constraint. But what if we only pass one UTxO to the lookup? Then transaction will be forced to be built with that UTxO right? There are no other options to be picked. Well, I tried that and it fails, this very clearly proves my understanding is wrong, why?

So far in the course we never had to pass UTxOs on the lookups and Plutus was able to find them automatically. Why it's only in this specific scenario that we need?

Actually in this code Value.singleton (curSymbol oref tn) tn 1 you are only specifying the Value to be minted. To be more precise: curSymbol oref tn is the currency symbol of your NFT to be minted with two parameters: oref and tn. For example, you can create a minting policy without any params (Free.hs in lesson 05) and mint using Value.singleton curSymbol tn 1. That's not related to Constraints.mustSpendPubKeyOutput.
Because if you remove mustSpendPubKeyOutput that means, you will not spend any UTxO and if you check the onchain code, there is a validation ensuring the use of the UTxO.
Purpose to use a UTxO to create an NFT, it's because an NFT should be unique. To ensure that, we have to specify something unique in the currency symbol and all UTxO are uniques, if you spend a UTxO, you can never use it again. It's the best way to identify our NFT.

Here some concepts to be clear on how this works:

tx: specifies the transaction to be built. In one transaction many things can be achieved at same time: mint values, pay to pubkeys, spend UTxO's (from PubKeys or scripts).
lookups: in order to successfully validate a transaction (from onchain code), there should be a "guide" to specify where those UTxO are. We do that, using lookups.

So, we say to our onchain code: validate this transaction (tx) using these UTxOs (lookups).
submitTxConstraintsWith @Void lookups tx

Your answer almost answers what I was trying to ask. I realized the question was not laid out very well, I edited my question to make it clearer and easier to follow, could you take a new look?


text:
Installing Cardano-node on an M1 Mac
I am trying to get a cardano node started on a Mac with the new M1 chip. Ive looked through the Installing a Cardano-node walk-through and found that they specify that the Mac install is for Intel chips only. They do say that they are working on a guide for the M1 chip, so this leads me to believe that it is possible. Does anybody have a lead or suggestions as to what the different steps might be?

@Srdjan - cardano.blue i'm getting an error using ln -s /Applications/Daedalus Testnet.app/Contents/MacOS/cardano-cli /usr/local/bin/cardano-cli  error says ln: /usr/local/bin/cardano-cli: No such file or directory How can I fix that?

I also do have Macbook with M1 chip and I use precompiled binaries that ship with Daedalus. It will save you a lot of trouble unless you really want to build it from source.
After you've installed your Daedalus you can sym link cardano-cli binary that comes with it and export CARDANO_NODE_SOCKET_PATH env variable and it should be ready to use.
For example if you want to sym link cardano-cli for testnet Daedauls you'd do this:
ln -s /Applications/Daedalus Testnet.app/Contents/MacOS/cardano-cli /usr/local/bin/cardano-cli

and to export CARDANO_NODE_SOCKET_PATH env variable you would do this:
export CARDANO_NODE_SOCKET_PATH=~/Library/Application\ Support/Daedalus\ Testnet/cardano-node.socket

Once you do this, and sync your node (by running you wallet) you should be ready to submit transactions and or query blockchain.

I think this is the most valid solution right now. Configuring the Testnet is just the same steps as it would be if you had built from the source. Good work around :)

It's now called Daedalus\ Preview just FYI

seems something simillar is necessary to do after cabal configure.... Mac doesn't have apt command, but I would assume you can get those libraries with homebrew
sudo apt install llvm-9
sudo apt install clang-9 libnuma-dev
sudo ln -s /usr/bin/llvm-config-9 /usr/bin/llvm-config
sudo ln -s /usr/bin/opt-9 /usr/bin/opt
sudo ln -s /usr/bin/llc-9 /usr/bin/llc
sudo ln -s /usr/bin/clang-9 /usr/bin/clang

source:
https://github.com/cardano-foundation/developer-portal/pull/437/commits/85f564177b773b63e4ee72428bda0768b427a05c#diff-0745839a94fa9b2a7c65f30e077253964dbbb6eb0811040d9f832cec3198a6d8

Edited 02-Jan-2022:
So I was able to compile cardano-node on M1, main trick to install llvm + add some cabal options, before building.
To install llvm you will need:
brew install llvm

Additionally you need to set cabal options after cabal configure --with-compiler=ghc-8.10.7
echo "package trace-dispatcher" >> cabal.project.local
echo "  ghc-options: -Wwarn" >> cabal.project.local
echo "" >> cabal.project.local

I got hint from here:
https://github.com/input-output-hk/cardano-node/issues/3395
Additionally I updated cardano-node instalation manual on https://developers.cardano.org/docs/get-started/installing-cardano-node, but it is not merged yet, here you can find full manual what I hope will be merged soon:
https://github.com/cardano-foundation/developer-portal/blob/56898031b9f55608521ccb6d7f616579856d52b7/docs/get-started/installing-cardano-node.md#macos

Try this guide. Worked for me using Debian in a VM
https://gist.github.com/d0n13/d286b36d630fa6820c40b534fb56986a
Unlike the Daedalus wallet these are arm64 binaries which are faster
cardano-cli:  ELF 64-bit LSB executable, ARM aarch64
cardano-node: ELF 64-bit LSB executable, ARM aarch64

I am able to confirm that the cardano-node that is packaged with the plutus-app git works find on an M1 apple.  Was able to mint tokens using the cli on the cardano testnet.  Cheers!

Though, did you tried installing the node anyway ? I've been trying and it stops at the cabal build all commands, here's the error :
    [3 of 3] Compiling Criterion.Measurement ( src/Criterion/Measurement.hs, dist/build/Criterion/Measurement.o, dist/build/Criterion/Measurement.dyn_o )

cbits/cycles.c:55:2: error:
     error: Unsupported OS/architecture/compiler!
   |
55 | #error Unsupported OS/architecture/compiler!
   |  ^
#error Unsupported OS/architecture/compiler!
 ^
1 error generated.
`gcc' failed in phase `C Compiler'. (Exit code: 1)
cabal: Failed to build criterion-measurement-0.1.2.0 (which is required by
test:cardano-api-test from cardano-api-1.30.1). See the build log above for
details.

Using Rosetta doesn't work either, an error occurs, not the same that without Rosetta :
/var/folders/w5/wm5j4z5s4s9ff4hmkm2bfb4m0000gn/T/ghc17359_0/ghc_1.s:15:2: error:
     error: unrecognized instruction mnemonic, did you mean: eret, ret?
            retq
            ^
   |
15 |         retq
   |  ^

<no location info>: error:
    Error running clang! you need clang installed to use the LLVM backend
    (or GHC tried to execute clang incorrectly)
`clang' failed in phase `Clang (Assembler)'. (Exit code: 1)

Although I have installed llvm... I am still trying to figure how to go through all this but I don't have plenty of times

I get a similar error to the build where you did not use Rosetta. Mine says this cabal: Failed to build plutus-core-0.1.0.0.  Some guy on the Cardano-node discord said he got it working when building from the source, so I don't know what to do.

Ive decided its not worth my time to figure this out when I can use a Linux Vm. Lemme know if you figure it out though :)

Well, i still find nothing about it, it looks like it is too soon haha. I managed to make cardano-node and cardano-cli usable through Daedalus App so i might be alright now ! :)

Oh hell yah dude! Im gonna do the same. Did you end up using rosetta as well?

I am using rosetta yes, well it's not really a problem, if anything needs to be done without it i'll just uncheck that checkbox in the Read informations page of the terminal

I have created an elegant solution where you can run cardano-cli from any network easily.
Firstly, download preview and pre-prod here:
https://docs.cardano.org/cardano-testnet/daedalus-testnet/
Download mainnet here:
https://daedaluswallet.io/en/download/
Once you have done this navigate to /usr/local/bin
Using sudo create 3 new files with the following names and shell script inside it.
cardano-cli-preview
#!/bin/sh

export CARDANO_NODE_SOCKET_PATH=~/Library/Application\ Support/Daedalus\ Preview/cardano-node.socket

/Applications/Daedalus\ Preview.app/Contents/MacOS/cardano-cli "$@"

cardano-cli-preprod
#!/bin/sh

export CARDANO_NODE_SOCKET_PATH=~/Library/Application\ Support/Daedalus\ Pre-Prod/cardano-node.socket

/Applications/Daedalus\ Pre-Prod.app/Contents/MacOS/cardano-cli "$@"

cardano-cli-mainnet
#!/bin/sh

export CARDANO_NODE_SOCKET_PATH=~/Library/Application\ Support/Daedalus\ Mainnet/cardano-node.socket

/Applications/Daedalus\ Mainnet.app/Contents/MacOS/cardano-cli "$@"

Note the "@" will take all the arguments passed to it and pass it onto the real cardano-cli.
Make sure to give them execution permissions
sudo chmod +x /usr/local/bin/cardano-cli-preview

sudo chmod +x /usr/local/bin/cardano-cli-preprod

sudo chmod +x /usr/local/bin/cardano-cli-mainnet

Now you can simply call cardano-cli-preview to connect to the preview network whenever you want, or call cardano-cli-preprod to connect to preproduction and cardano-cli-mainnet for the mainnet.
To test each of these you can run the following commands
cardano-cli-preview query tip --testnet-magic 2

cardano-cli-preprod query tip --testnet-magic 1

cardano-cli-mainnet query tip --mainnet


text:
localhost refuse to connect
I recently finish the whole pionner program video and try to do it by myself.
I used wsl2+debian to set up the enviroment, but after I build everything. it said I can access the playground through localhost:8009, I tried multiple times. always got refused.
anyone got the same issue?

Make sure you use https, not http.
https://localhost:8009

thank you.  I used https.. not sure why. I shutdown wsl2 and restarted it, it works...

if this solved your problem, please mark it as the answer


text:
What does it mean for a contract to "stop"?
I'm working through the week 4 homework for the Plutus Pioneer program. I've found an answer to the homework problem and now I'm trying to get a deeper understanding of the code. I've noticed that the payContract returns itself (I'm still learning Haskell so that terminology might not be correct).
I find that if I comment out this line of code, then the second invocation of callEndpoint doesn't do anything. I also notice that the logs of payTest1 say Contract Stopped:
Prelude Week04.Solution> payTest1
Slot 00000: TxnValidate 0636250aef275497b4f3807d661a299e34e53e5ad3bc1110e43d1f3420bc8fae
Slot 00000: SlotAdd Slot 1
Slot 00001: 00000000-0000-4000-8000-000000000000 {Contract instance for wallet 1}:
  Contract instance started
Slot 00001: 00000000-0000-4000-8000-000000000000 {Contract instance for wallet 1}:
  Receive endpoint call on 'pay' for Object (fromList [("contents",Array [Object (fromList [("getEndpointDescription",String "pay")]),Object (fromList [("unEndpointValue",Object (fromList [("ppLovelace",Number 1000000.0),("ppRecipient",Object (fromList [("getPubKeyHash",String "977efb35ab621d39dbeb7274ec7795a34708ff4d25a01a1df04c1f27")]))]))])]),("tag",String "ExposeEndpointResp")])
Slot 00001: W1: TxSubmit: 66b88e2673c2d50a5de7603fb28c71ac56963d88dda4c69dc529e2d26638b294
Slot 00001: 00000000-0000-4000-8000-000000000000 {Contract instance for wallet 1}:
  Contract instance stopped (no errors)
Slot 00001: TxnValidate 66b88e2673c2d50a5de7603fb28c71ac56963d88dda4c69dc529e2d26638b294
Slot 00001: SlotAdd Slot 2
Slot 00002: SlotAdd Slot 3
Slot 00003: SlotAdd Slot 4

I feel like I can intuit what Contract Stopped means but I'd like to understand on a more technical level what this means and under which conditions this happens.

The line of interest is:
pp <- endpoint @"pay"

Which is essentially blocking until someone hits the "pay" endpoint and then returning whatever PayParams the caller included (see PaySchema).
In the case where you include the recursive payContract function call, you are essentially saying, "after running payContract, wait for someone else to hit the "pay" endpoint."
In the case that the recursive payContract function call is removed, the Contract monad will exit, since it isn't blocked on any endpoints or anything.
Hope that helps :)


text:
Plutus Pioneer Program Week missing commit
The cabal.project file for Week 5 of the Plutus Pioneer program points to commit 8f1a47674a99ac9bc2aba3231375d8d6de0641d2 for the Plutus repo but that commit seems to not exist based on:
 2:22PM /Users/paymahn/plutus master ✱
 ❯❯❯ git checkout 8f1a47674a99ac9bc2aba3231375d8d6de0641d2
fatal: reference is not a tree: 8f1a47674a99ac9bc2aba3231375d8d6de0641d2

and this github search for the commit. Is this known? What's the correct Plutus commit for the week 5 homework? This is preventing cabal build and cabal repl from running successfully:
 2:24PM /Users/paymahn/plutus-pioneer-program/code/week05 (nix) main ✱ ◼
 ❯❯❯ cabal build
remote: Enumerating objects: 728, done.
remote: Counting objects: 100% (728/728), done.
remote: Compressing objects: 100% (285/285), done.
remote: Total 728 (delta 451), reused 666 (delta 400), pack-reused 0
Receiving objects: 100% (728/728), 184.31 KiB | 174.00 KiB/s, done.
Resolving deltas: 100% (451/451), completed with 138 local objects.
From https://github.com/input-output-hk/plutus
   daeb13477..c5083fce6  master                             -> origin/master
 * [new branch]          SCP-2858-chain-index-securityParam -> origin/SCP-2858-chain-index-securityParam
 + b63ecf5b2...4b94768e7 bezirg/costparams-test             -> origin/bezirg/costparams-test  (forced update)
 + 1d4eb1d72...4bd02c105 bezirg/retained-csv                -> origin/bezirg/retained-csv  (forced update)
 + 9441f7f66...971377a54 component-modules                  -> origin/component-modules  (forced update)
   7f77abdb3..a0258b9ba  hkm/ghcjs-cross                    -> origin/hkm/ghcjs-cross
 + 4f24c5258...a8be7ab68 hrajchert/scp-2779-fix-toast-when-reloading -> origin/hrajchert/scp-2779-fix-toast-when-reloading  (forced update)
   a1db411af..ed7e61160  jmchapman/ck-cek-eq                -> origin/jmchapman/ck-cek-eq
   b59aebf75..fec18d337  kwxm/list-sort-benchmarks          -> origin/kwxm/list-sort-benchmarks
 * [new branch]          merivale/marlowe-run-architecture  -> origin/merivale/marlowe-run-architecture
   ffb13a295..116d4d116  scp-1582-actus-quick-check         -> origin/scp-1582-actus-quick-check
 + 5a78a0736...879fed306 scp-2782-sqlite-in-freer-extras    -> origin/scp-2782-sqlite-in-freer-extras  (forced update)
 + 9b1ca49b0...d3fb79c45 scp-2783-chain-index-pagination    -> origin/scp-2783-chain-index-pagination  (forced update)
 + 8d679192d...0b8e46ead scp-2796-chain-index-query-utxo-currenty -> origin/scp-2796-chain-index-query-utxo-currenty  (forced update)
 * [new branch]          scp-2883-actus-derivative-contracts -> origin/scp-2883-actus-derivative-contracts
fatal: reference is not a tree: 8f1a47674a99ac9bc2aba3231375d8d6de0641d2

Turns out using the commit from Week06, 8a20664f00d8f396920385947903761a9a897fe0, is the cleanest solution (too bad it wasn't merged at the time of asking this question): https://github.com/input-output-hk/plutus-pioneer-program/pull/36
This commit doesn't require any changes to the endpoints or updating any imports.

You should be aware that plutus is changing constantly, so some commits aren't working anymore.
In this case, you can use this commit hash: 547e22a975d9b688ad2121f56e63691bead661cc (or this one 9ed85d6cc8e817270220f263a11e738135eb0ad3 as mentioned in following comment) but remember to update your cabal.project according to this, from Antonio Ibarra IOHK:

when you update the Plutus Hash in the cabal.project file, you will also need to update the hash of all source repositories. To do that you can go to the cabal.project original repository in the defined commit (in this case https://github.com/input-output-hk/plutus/blob/9ed85d6cc8e817270220f263a11e738135eb0ad3/cabal.project), copy from line 39 to the end of the file and then paste it in the cabal.project file of the week 10 replacing old source repositories below the note The following sections are copied from the 'plutus' repository

Also you should update the endpoints code, as it has changed (you can take for reference endpoints code from TokenSale.hs in Lesson 08). Consider that endpoint function returns a promise now.
endpoints :: Contract () FreeSchema Text ()
endpoints = forever
          $ handleError logError
          $ awaitPromise
          $ endpoint @"mint" $ mint

------------ UPDATE ---------
547e22a975d9b688ad2121f56e63691bead661cc
It's working for lessons 05, 08 and 10

Got it thanks. How did you arrive at the conclusion that 547e22a975d9b688ad2121f56e63691bead661cc is the appropriate commit? Is that documented somewhere or did you test out various commits until you found one that works?

Just tried it. It's working for lesson 05, 08 and 10.

Great! I'm seeing the compilation problem generally fixed too but I can't seem to figure out how to update the endpoints function to work. Any chance you can provide that too? I see that in the TokenSale of lesson 8 they use forever and awaitPromise but trying to use that code isn't very straightforward for me as a haskell novice.

Sorry for the delay, I took a few days off. Check my updated answer.

Much ❤ - thanks for the update


text:
Question about plutus-pab
I am trying to understand plutus-pab. I read in the documentation that PAB will give to a wallet an unsigned and unbalanced transaction, then the wallet will balance and sign it and then will send it to the blockchain.
Let's say if I have a frontend in a browser using RESTful API to interact with PAB in my server. The user is using Daedalus wallet (I know, this part might not be possible yet).
As my understanding, the user will either create or interact with a contract instance through the RESTful API. Here is the first question, after a transaction is formed, will PAB somehow give this transaction to my wallet to sign and balance? and what exactly means "to balance a transaction"? didn't we give the parameter for the transaction already when we made the call through the RESTful API?
The second question is about the process as a whole. I don't see when we send the validator on-chain. Does the validator show up on-chain the moment we first create the contract instance through PAB? (if this contract involves a script address). This interaction basically creates the script address and send the token there, does it also send the validator script there?
Thank you so much!


text:
Bech32 encoding stake address from Shelley address in JavaScript returning wrong value
I am trying to extract the bech32 stake address from a Shelly address using Javascript. I followed the example steps outlined in the answer another question (thanks for the help!) and put together the following code sample. The interim values are correct until the final step (bech32 encoding the stake portion of the hex-encoded address):
import { bech32 } from 'bech32';

// input Shelley address
const address = 'addr1qxdvcswn0exwc2vjfr6u6f6qndfhmk94xjrt5tztpelyk4yg83zn9d4vrrtzs98lcl5u5q6mv7ngmg829xxvy3g5ydls7c76wu';

// decode bech32 shelley address and convert to hex
const addressWords = bech32.decode(address, 1000);
const payload = bech32.fromWords(addressWords.words);
const addressDecoded = `${Buffer.from(payload).toString('hex')}`;
// ✅ should be 019acc41d37e4cec299248f5cd27409b537dd8b53486ba2c4b0e7e4b54883c4532b6ac18d62814ffc7e9ca035b67a68da0ea298cc24514237f

// stake part of the address is the last 56 bytes
const stakeAddressDecoded = addressDecoded.substr(addressDecoded.length - 56);
// ✅ should be 883c4532b6ac18d62814ffc7e9ca035b67a68da0ea298cc24514237f

// convert to bech32 to get stake address
const stakeAddress = bech32.encode(
  'stake',
  bech32.toWords(Uint8Array.from(Buffer.from(stakeAddressDecoded, 'hex'))),
  1000
);
// should be  : stake1uxyrc3fjk6kp343gznlu06w2qddk0f5d5r4znrxzg52zxlclk0hlq
// ❌ returns : stake13q7y2v4k4svdv2q5llr7njsrtdn6drdqag5cesj9zs3h7xjwn42

Am I missing a step before bech32 encoding the stake portion of the address? Thanks in advance.

You're missing the prefix, i.e. e1 in this case.

const stakeAddressDecoded = 'e1'+addressDecoded.substr(addressDecoded.length - 56);

You have to add e1 (or e0 in case of testnet) as prefix.
Check page 113-114 for more details on prefix specifications: https://hydra.iohk.io/build/7918420/download/1/ledger-spec.pdf

Yes, this was the issue. Accepted as the answer - thanks!


text:
Highly-available relay node (round robin & Ouroboros)
I'm thinking of adding multiple relay-node instances behind a load-balancer to avoid downtime during maintenance windows, updates, restarts, etc.
From the outside world (public network), this would be seen as a single relay (single IP address / single DNS record), but internally, each instance would be an independent node, performing its own sync procedure. There's a chance for these instances to be slightly out of sync between each other (eg: after a restart of one).
My question: is there any problem from the protocol perspective (Ouroboros, topology updater, etc) with having multiple round robin nodes answering as the same relay?

Do you have more details on how you plan on handling your topology inside the network?

This would be a cloud setup. Each relay-node instance would be connected to two subnets (1 public, 1 private). A single BP node would be running in the private subnet. Relay instances would point their topology config to the BP node + other peer relays downloaded from api.clio.one (cron job). The BP node would have a static topology file pointing only to the relay instances through the private subnet.

Short Answer: No there is not any technical limitations from the protocol or topology updater preventing you from doing this.
Considerations: Starting external and working in, we need to consider the DNS vs Public IP side of this. In my opinion a Public IP should be avoided because if it changes, you have to resubmit your stake-pool registration.
Excluding a public IP, we are left with DNS. There are 2 main ways you can setup the DNS: just an A Record or an SRV Record. It is worth noting that the SRV record doesn't know if a network is down/a-server-is-down, so it will not replace your load balancer for those type of services.
Either decision, the next step is your load balancer(s). I haven't actually set one of up for this use case but my initial thought would be this is where you run the topology-updater script. As well as, you know, balance the load. For the topology updater, make your valency equal to the number of relays you have (if using DNS, otherwise this won't work). Doing this allows more than one connection per peer. This is important because you are using a load balancer which could potentially create a situation where there are no incoming peers to a relay. You will still want to run a topology pull script to set your relay nodes' topology.
I hope this helps!


text:
Hash script data
I want to understand a bit better the hash-script-data functionality from cardano-cli. I checked the source code but had no luck in understanding how this hash is made.
From the examples, if we run:
cardano-cli transaction hash-script-data --script-data-value 42

We get the following hash:
9e1199a988ba72ffd6e9c269cadb3b53b5f360ff99f112d9b2ee30c4d74ad88b

However if we try to do a simple SHA256 hash of a 42 value we get:
73475cb40a568e8da8a045ced110137e159f890ac4da883b6b17dc651b3a8049

Also tried in the Plutus object format:
{
  "constructor": 0,
  "fields": [{
    "int": 42
  }]
}

but none of those match the hash generated by cardano-cli.
Also tried innumerous other alternatives but obviously I'm missing something, anyone knows what's the process for generating this hash?
Thank you!

The missing step would be converting the ScriptData into
CBOR prior to hashing.
In the case of ScriptDataNumber 42 the CBOR Hex is "182a" which is a bit simplified for Numbers vs more complex ScriptData. The CBOR Jump Table shows that 0x18 indicates unsigned integer (one-byte uint8_t follows) followed by 2a which is 42 in hex.
Or using Haskell:
let plutusData = PlutusCore.Data.I 42
print $ Base16.encode $ BSL.toStrict $ Codec.Serialise.serialise plutusData
-- "182a"
print $ Cardano.Api.hashScriptData $ Cardano.Api.Shelley.fromPlutusData plutusData
-- "9e1199a988ba72ffd6e9c269cadb3b53b5f360ff99f112d9b2ee30c4d74ad88b"

and using libsodiumjs as example to hash:
var libsodiumWrappers = require("libsodium-wrappers");
var _sodium = libsodiumWrappers;

(async () => {
  await _sodium.ready;
  const sodium = _sodium;
  var h = sodium.crypto_generichash(32, sodium.from_hex('182a'));
  console.log(sodium.to_hex(h));
})();

Thanks, that's exactly what I was looking for! Regarding objects/json files, are we supposed to also convert to CBOR? For example a datum object like {"constructor": 0,"fields": [{"int": 4}]}, I transform into CBOR: a24b636f6e7374727563746f7200466669656c647381a143696e7404 and when I hash it I get 5677bf1048dad6dce36483d2bec0fafc71f5dc9b01a2b1326c6443c2cd264b50, but if I do the same with cardano-cli I get 8bb54ceaee2f57731094a2e96b8ad87bcc8988b1fa838e8c833eb3b72eae29a1. Is there any additional step in this case?


text:
Errors while submitting txn from cardano-serialization-lib
I have a working transaction in cardano-cli, but I'm having trouble constructing the same one using the serialization-lib. Does anyone know what these errors mean?? I tried looking into the typescript definitions, but the documentation isn't great.
""transaction submit error ShelleyTxValidationError ShelleyBasedEraAlonzo (ApplyTxError [
UtxowFailure (NonOutputSupplimentaryDatums (fromList [SafeHash \"9cbcced629edb13ecef78c9c27adfe079a9acd77b62a6693eab0134920a595b9\"]) (fromList [])),
UtxowFailure (ExtraRedeemers [RdmrPtr Spend 1]),
UtxowFailure (WrappedShelleyEraFailure (MissingScriptWitnessesUTXOW (fromList [ScriptHash \"25da22dfd99bf874e59d74c304a1d28e921310327c3e4d6960123f2e\"]))),
UtxowFailure (WrappedShelleyEraFailure (UtxoFailure (UtxosFailure (CollectErrors [NoWitness (ScriptHash \"25da22dfd99bf874e59d74c304a1d28e921310327c3e4d6960123f2e\")]))))])""

See on Github

Did you find a solution to this? I have the exact same issue

I'm experiencing the same problem.

Trying removing the first 6 bytes from your plutus hex :)

how you've been building out your transaction? Have you tried using TransactionBuilder?
It seems like you haven't signed your transaction before you tried to send it to the network.
Here's a link to the cardano-serialization-lib doc where they describe how to build transaction using TransactionBuilder.
Also, you can take a look in the spacebudz repo in the initTx method where the TransactionBuilder is used.
Here's a link to the method


text:
How to split transaction into many different UTXOs?
Let's image I want to create a Plutus script, which takes Value as a parameter (ADA or any other coin with specific amount), and locks this value at script's output. How can I split this value into many different UTXOs of same/different amounts sitting at a script address?
on-chain validator script just says yes or no to the transaction. No help here.
off-chain scripts just instruct on what to do and has no influence under transaction output.
So basically this can only be achieved by building/balancing a transaction? By specifying inputs and outputs, and then submitting to blockchain for validation?
If yes, are there ANY programmable wallets which can do this? Daedalus is not an option, tried Yoroi, Nami, but those doesn't seem to have this functionality. Nami can only do simple transactions with JS.

off-chain scripts just instruct on what to do and has no influence under transaction output.

You should be able to specify multiple outputs going to the script address in your off-chain code. Just note that they will need to each have separate datums if you want to be able to spend them later. Something like
let a = Constraints.mustPayToTheScript datum_one value_one
let b = Constraints.mustPayToTheScript datum_two value_two
let tx = a <> b
...

I want to create a Plutus script, which takes Value as a parameter, and locks this value at script's output

on-chain validator script just says yes or no to the transaction. No help here.

If you are taking a value that already exists at the script address, you will want to make sure the validator checks that there are the two new datums added to the script address in the outputs. If the value is coming from you wallet, not validation is needed--you only validate when spending outputs from a script address.


text:
Is it possible to use a parameterised CurrencySymbol inside another validator script? Unsupported feature: Type constructor: GHC.Prim.ByteArray#
I am having trouble using a parameterised CurrencySymbol inside another validator script. It seems to work (not shown here) when the currency symbol is unparametrised but not otherwise:
GHC Core to PLC plugin: E042:Error: Unsupported feature: Type constructor: GHC.Prim.ByteArray#
Context: Compiling type: GHC.Prim.ByteArray#
Context: Compiling data constructor type: GHC.Integer.Type.BN#
Context: Compiling type: GHC.Integer.Type.BigNat
Context: Compiling data constructor type: GHC.Natural.NatJ#
Context: Compiling type: GHC.Natural.Natural
Context: Compiling data constructor type: PlutusCore.Core.Type.Version
Context: Compiling type: PlutusCore.Core.Type.Version ann
Context: Compiling data constructor type: UntypedPlutusCore.Core.Type.Program
Context: Compiling type: UntypedPlutusCore.Core.Type.Program
                           PlutusCore.DeBruijn.Internal.DeBruijn
                           PlutusCore.Default.Universe.DefaultUni
                           PlutusCore.Default.Builtins.DefaultFun
                           ()
Context: Compiling type: Plutus.V1.Ledger.Scripts.Script
Context: Compiling type: Plutus.V1.Ledger.Scripts.MintingPolicy
Context: Compiling type: Plutus.V1.Ledger.Scripts.MintingPolicy
                         -> Data.ByteString.Internal.ByteString
Context: Compiling definition of: Ledger.Scripts.mintingPolicyHash1
Context: Compiling expr: Ledger.Scripts.mintingPolicyHash1
Context: Compiling expr: Ledger.Scripts.mintingPolicyHash1
                           (TestContract.tokenPolicy oref nm)
Context: Compiling expr: \ (nm [Occ=Once]
                              :: Plutus.V1.Ledger.Value.TokenName) ->
                           Ledger.Scripts.mintingPolicyHash1
                             (TestContract.tokenPolicy oref nm)
Context: Compiling expr: \ (oref [Occ=Once] :: Plutus.V1.Ledger.Tx.TxOutRef)
                           (nm [Occ=Once] :: Plutus.V1.Ledger.Value.TokenName) ->
                           Ledger.Scripts.mintingPolicyHash1
                             (TestContract.tokenPolicy oref nm)
Context: Compiling expr: (\ (oref [Occ=Once]
                               :: Plutus.V1.Ledger.Tx.TxOutRef)
                            (nm [Occ=Once] :: Plutus.V1.Ledger.Value.TokenName) ->
                            Ledger.Scripts.mintingPolicyHash1
                              (TestContract.tokenPolicy oref nm))
                         `cast` (<Plutus.V1.Ledger.Tx.TxOutRef>_R
                                 ->_R <Plutus.V1.Ledger.Value.TokenName>_R
                                 ->_R Sym (PlutusTx.Builtins.Internal.N:BuiltinByteString[0]) ; Sym (Plutus.V1.Ledger.Value.N:CurrencySymbol[0])
                                 :: GHC.Types.Coercible
                                      (Plutus.V1.Ledger.Tx.TxOutRef
                                       -> Plutus.V1.Ledger.Value.TokenName
                                       -> Data.ByteString.Internal.ByteString)
                                      (Plutus.V1.Ledger.Tx.TxOutRef
                                       -> Plutus.V1.Ledger.Value.TokenName
                                       -> Plutus.V1.Ledger.Value.CurrencySymbol))
Context: Compiling definition of: TestContract.tokenSymbol
Context: Compiling expr: TestContract.tokenSymbol
Context: Compiling expr: TestContract.tokenSymbol oref'_a3cNp
Context: Compiling expr: TestContract.tokenSymbol
                           oref'_a3cNp tn'_a3cNq
Context: Compiling expr: TestContract.mkTestValidator
                           (TestContract.tokenSymbol oref'_a3cNp tn'_a3cNq)
Context: Compiling expr: \ (tn'_a3cNq
                              :: Plutus.V1.Ledger.Value.TokenName) ->
                           TestContract.mkTestValidator
                             (TestContract.tokenSymbol oref'_a3cNp tn'_a3cNq)
Context: Compiling expr: \ (oref'_a3cNp :: Plutus.V1.Ledger.Tx.TxOutRef)
                           (tn'_a3cNq :: Plutus.V1.Ledger.Value.TokenName) ->
                           TestContract.mkTestValidator
                             (TestContract.tokenSymbol oref'_a3cNp tn'_a3cNq)
Context: Compiling expr at "test-contract-0.1.0.0-inplace:TestContract:(116,9)-(116,94)"

Here are my imports:
{-# LANGUAGE DeriveAnyClass #-}
{-# LANGUAGE PartialTypeSignatures #-}
{-# LANGUAGE StandaloneKindSignatures #-}
{-# LANGUAGE TemplateHaskell #-}
{-# LANGUAGE TypeFamilies #-}
{-# OPTIONS_GHC -Wno-partial-type-signatures #-}
{-# OPTIONS_GHC -w #-}
-- {-# OPTIONS_GHC -fno-specialise #-}
-- {-# OPTIONS_GHC -fno-strictness #-}
-- {-# OPTIONS_GHC -fno-ignore-interface-pragmas #-}
-- {-# OPTIONS_GHC -fno-omit-interface-pragmas #-}
-- {-# OPTIONS_GHC -fobject-code #-}

module TestContract where

import Data.Kind (Type)
import Ledger.Interval qualified as Interval
import Ledger.Contexts qualified as Context
import Ledger.Crypto qualified as Crypto
import Ledger.Scripts qualified as Scripts
import Ledger.Typed.Scripts qualified as Scripts
import Ledger.Typed.Scripts.Validators qualified as Validator
import Ledger.Tx qualified as Tx
import Plutus.V1.Ledger.Ada qualified as Ada
import Plutus.V1.Ledger.Api qualified as Api
import Plutus.V1.Ledger.Address qualified as Address
import Plutus.V1.Ledger.Time qualified as Time
import Plutus.V1.Ledger.Value qualified as Value
import PlutusTx qualified
import PlutusTx.AssocMap qualified as Assoc
import PlutusTx.Prelude ((&&), (<=))
import PlutusTx.Prelude qualified as Plutus
import PlutusTx.TH qualified as PlutusTx
import Prelude (undefined, ($), (.))

Below, I've defined a policy that always returns True, the real logic is more complicated but the error message is the same. It's essentially identical to the NFT minting policy from Plutus Pioneers lecture 5 - hence TxOutRef and TokenName as inputs. As mentioned earlier, removing these 2 parameters is fine for compilation (deleting any necessary lifting).
{-# Inlineable mkTokenPolicy #-}
mkTokenPolicy :: Tx.TxOutRef
              -> Value.TokenName
              -> ()
              -> Context.ScriptContext
              -> Plutus.Bool
mkTokenPolicy oref nm ()
  scriptContext@Context.ScriptContext {scriptContextTxInfo = scriptContextTxInfo} =
    Plutus.True

tokenPolicy :: Tx.TxOutRef -> Value.TokenName -> Scripts.MintingPolicy
tokenPolicy oref nm =
  Scripts.mkMintingPolicyScript
    ($$(PlutusTx.compile [|| \oref' tn' -> Scripts.wrapMintingPolicy (mkTokenPolicy oref' tn') ||])
      `PlutusTx.applyCode`
    PlutusTx.liftCode oref
      `PlutusTx.applyCode`
    PlutusTx.liftCode nm)

{-# Inlineable tokenSymbol #-}
tokenSymbol :: Tx.TxOutRef -> Value.TokenName -> Value.CurrencySymbol
tokenSymbol oref nm =
  Context.scriptCurrencySymbol (tokenPolicy oref nm)

The tokenSymbol is just a parametrised CurrencySymbol of the NFT. The problematic code appears to be below when I try to compile this.
{-# Inlineable typedValidator #-}
typedValidator :: Tx.TxOutRef -> Value.TokenName -> Scripts.TypedValidator TestData
typedValidator oref nm =
  Scripts.mkTypedValidator @TestData
    ($$(PlutusTx.compile [|| \oref' tn' -> mkTestValidator (tokenSymbol oref' tn') ||])
       `PlutusTx.applyCode`
       PlutusTx.liftCode oref
       `PlutusTx.applyCode`
       PlutusTx.liftCode nm)
    $$(PlutusTx.compile [|| wrap ||])
  where
    wrap = Scripts.wrapValidator

The last line of the error:
Context: Compiling expr at "test-contract-0.1.0.0-inplace:TestContract:(116,9)-(116,94)"

is complaining about this line:
$$(PlutusTx.compile [|| \oref' tn' -> mkTestValidator (tokenSymbol oref' tn') ||])

I am defining TestData slightly differently, hence the absent type application in wrap. Prior to this bug, when my currency symbol was unparametrised, the below definition worked.
type (:--:) :: Type -> Type -> Type -> Type
newtype (redeemer :--: datum) a = Foo a

instance Scripts.ValidatorTypes ((redeemer :--: datum) a) where
  type RedeemerType ((redeemer :--: datum) a) = redeemer
  type DatumType ((redeemer :--: datum) a) = datum

data TestData
  deriving
    (Scripts.ValidatorTypes)
    via (TestAction :--: TestDatum) TestData

although this is equivalent to (with type application in wrap):
-- data TestData
-- instance Scripts.ValidatorTypes TestData where
--   type RedeemerType TestData = TestAction
--   type DatumType    TestData = TestDatum

I didn't provide any detail on mkTestValidator, nor my redeemer or datum. The reason being I only had issues after parameterising.
The error message seems to suggest the prohibited use of Natural. I'm not aware of direct usage in my code, but in https://alpha.marlowe.iohkdev.io/doc/haddock/plutus-core/html/UntypedPlutusCore-Core-Type.html Version is defined to use Natural, and Version is contained in Program. Is there a restriction on PLC when using a validator script defined above?
Plutus tag: 9879b31579d0deb863f3cdf27f93419deec3b4bb


text:
Plutus devcontainer build fails with 'devcontainer' not found
I cloned the current plutus repo
git clone https://github.com/input-output-hk/plutus

And i'm on the current commit
3f8c1e22292d68d92f01f9a62a60621df01cdd4e

But building the dev container does not work (before some weeks it worked on the same machine)
wutze@wutze-pc:~/workspace/plutus$ sudo docker load < $(nix-build default.nix -A devcontainer)
error: attribute 'devcontainer' in selection path 'devcontainer' not found
-bash: $(nix-build default.nix -A devcontainer): ambiguous redirect

Any ideas what's wrong?

The devcontainer is existing in this git commit
c801b70016856b320a0deaab1f35f7b1ca9efa27

They have moved the devcontainer to The Plutus Application Framework
As per the README in the plutus repository. This repository used to contain the code for the Plutus Application Framework and Marlowe. These have now moved:
Plutus Application Framework

Marlowe

thanks didn't notice that it was moved to a different repo


text:
Does deregister of the staking key take effect immediately?
I'm participating a Token sale and in order to participate the Token sale, I need to have an undelegated ADA(because the system will take a snapshot of undelegated ADA, only the undelegated ADA will be qualify) but all of my wallet are staked. The sale is coming within 2 days before the end of the current epoch. My question is Does deregister of the staking key take effect immediately? or I need to wait until the end of epoch for it to take an effect? What if I create a new undelegated wallet and transfer $ada from my staking wallet to the undelegated wallet? the transferred $ada in the new undelegated wallet will be count as undelegated immediately right?

If you un-delegate a wallet this will happen immediately and you will get your 2 Ada staking deposit refunded as well as the current rewards sitting in your rewards sub-account.
IMPORTANTLY:  You will however also miss out on pending payments of staking rewards which have already been accrued but not yet paid.  These rewards are due to be paid over the next 2 epochs.  This is because rewards are calculated each epoch but not paid until 2 epochs later.
In other words, it is not a good idea to un-delegate your wallet if you have a significant amount of Ada staked because you will miss out on some of your accrued rewards.
On the other hand, if you send some Ada to a newly created wallet, then this sent Ada will be un-delegated in the new wallet (until you choose to delegate it).  Any residual Ada in your original wallet will continue to earn staking rewards and you will also still get paid your accrued staking rewards that had been calculated in previous epochs, but not yet paid.
If you have a large amount of Ada sitting in a wallet and you want to send it all to a new wallet then you are better off to follow these steps:

Send most of your Ada to a new wallet but leave say 10 Ada in the old wallet.

Leave this 10 Ada in your old wallet staked for another 2-3 epochs so that your accrued staking rewards can continue to be paid.

Each epoch transfer the earned rewards to your new wallet but continue to leave the 10 Ada balance.

After 2-3 epochs, your rewards will drop to dust.

Finally un-delegate your old wallet to get your 2 Ada deposit back and send the residual 10 + 2 Ada + dust rewards to your new wallet.

This way you won't miss out on some of your staking rewards.
By the way, if you do just un-delegate a staked wallet without following the steps above, then your rewards don't disappear.  They just get sent to the treasury instead which is like a donation to benefit the ecosystem.

I can't be sure as I can't find any documentation about it, but it should be immediate, given the time to propagate through the blockchain.