1

I am learning to use polkadotjs api, I am trying to send a system.remarkWithEvent and then get the event that this created and decode de output to verify that the remark is there.

The sending of the extrinsic is pretty straight forward:

let remark = new TextEncoder().encode('this is a test to encode something#5');
api.tx.system.remarkWithEvent(remark).signAndSend(account, { nonce: nextSudoNonce });

but then when I try to get the event data for this remark object the data is the following:

{
  sender: '0xf24FF3a9CF04c71Dbc94D0b566f7A27B94566cac',
  hash_: '0x2652d1ebf54bb7143af7548273e4f51c960fb743d2f99e945eb00b6ef141abbb'
}

Where hash_ is the remark, how can I decode this data to get the original string?

1 Answer 1

2

The extrinsic remarkWithEvent (remark_with_event) does a Hash of the data that you send as a parameter and it sends you this hash in the event.

let hash = T::Hashing::hash(&remark[..]);
Self::deposit_event(Event::Remarked { sender: who, hash });

It depends of the Configuration of the network you are which hashing algorithm is using, but the process of hashing is normally one-way.

You can see for example that the default is BlakeTwo256:

type Hashing = sp_runtime::traits::BlakeTwo256;

So I don't think you can get the original value, what you can do in with PolkadotJS is hash it locally with the same method is using onchain and compare that the values are the same.

See the documentation and some examples of the hashing algorithms exposed in the util-crypto package: HashData

1

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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