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?
1 Answer
Looking at https://smartpy.io/dev/reference.html#_chain_id, you can see that you can basically currently do three things in SmartPy:
Define chain_id constants with things like
sp.chain_id_cst("0x9caecab9")
.Get the current chain_id for your chain
sp.chain_id
.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.
-
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.– DalyFeb 25, 2020 at 10:53
-