The image below shows a decoded finalized transaction that deploys a flipper contract on my local substrate network. I am not sure what the data field represents here.
1 Answer
It is the data passed to the constructor of the contract.
-
1To expand, data is an encoded
message
orconstructor
selector (because you can have multiple constructors) with input for it (if needed). Commented Feb 15, 2023 at 9:32 -
Well in my case the function signature looks like this:
pub fn new(init_value: bool) -> Self
I believe I initialized it withfalse
. Can you elaborate what encoding or other mechanism led it to be0x9bae9d5e00
? Commented Feb 15, 2023 at 9:37 -
first 4 bytes is the selector (
9bae9d5e
) then you have the args (00 = false in your case) Commented Feb 16, 2023 at 9:17 -
I need to pass the data field through my code using polkadot-js/api library. So can you tell me how I can get the first 4 bytes i.e. the selector, given the function signature and the params passed during the contract instantiation? Commented Feb 20, 2023 at 8:13