1

I'm trying to get the chain_id of the current chain evaluating a transaction or containing the smart contract with smartPy, but I got always error in init and in entrypoints when I try to affect the chainId to a ver in storage, can you anyone give us a small example on how to get the chain_id in the smart contract? or how to initiate a var in storage with the chain_id where the contract is deployed?

2

Looking at https://smartpy.io/dev/reference.html#_chain_id, you can see that you can basically currently do three things in SmartPy:

  1. Define chain_id constants with things like sp.chain_id_cst("0x9caecab9").

  2. Get the current chain_id for your chain sp.chain_id.

  3. Verify that they match with sp.verify_equal.

There are no helper lists of chain_id constants that I know of, which would be helpful.

| improve this answer | |
  • Thank you for answering, I saw the docs and tried to apply in samrt contract but my problem is that I got errors when I want to get the current chain_id, for example when I want to initiante a var in storage with sp.chai_id I got, Error: Error in Scenario Missing environment (sp.chain_id : sp.TChainId) Compute storage Traceback (most recent call last): So if you can give us an example on how to use it. – Daly Feb 25 at 10:53
  • In the storage, you put constants so you need to use sp.chain_id_cst. – FFF Feb 25 at 10:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.