5

hello is there a way to decode this kind of extrinsic on substrate side without polkadotJs :

extrinsics: [0402000b935b2a697f01, 84003c2eb55ba53099bea9031b4a30c9a553c29f7c4a3a9f266d6208954268aa8825014031ae12b4edb8b6f49e407b88f21022460e523d57337b70a46ce23765d4b645cd4f05fefaf77be348994429492d1c923ce1a3bbe00a5397e809fbac72864d8dc5031000050000d43593c715fdd31c61141abd04a99fd6822c8558854ccde39a5684e7a56da27d02093d00]

?

I think that 0402000b935b2a697f01 is "set timestamp" for example.

2
  • Which network is it for by the way? What is genesis hash? Commented Mar 17, 2022 at 21:00
  • we use our own substrate blockchain, genesis hash is 0x7253b2c4dcbdd53e3aae5372006d4bcd8a587428ad8f487ddfa116ca2b6d8d9f
    – cibou
    Commented Mar 18, 2022 at 8:41

2 Answers 2

3

Yes, all the information you need to decode those extrinsic blobs can be found using the Runtime Metadata.

The first two bytes of any extrinsic will tell you which pallet and call is being made:

vv pallet
0402000b935b2a697f01
  ^^ call

So you want to look at your runtime metadata, and find which pallet is the 4th index (the 5th pallet), and which call is the 2nd index (the 3rd call).

I think in this case that this is NOT the timestamp set call, since timestamp only has 1 extrinsic, so the call index would never be 02.

17
  • ok thank you, and how to know how much args do we have for example in this case { isSigned: true method: { args: { dest: { Id: 5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY } value: 1.0000 µUnit } method: transfer section: balances }
    – cibou
    Commented Mar 16, 2022 at 14:20
  • That is also in the metadata, each call will have a list of the arguments it expects, and the datatype that it expects.
    – Shawn Tabrizi
    Commented Mar 16, 2022 at 17:00
  • 1
    Please see here how Parity Signer does this: github.com/paritytech/parity-signer/tree/master/rust/parser Commented Mar 17, 2022 at 20:06
  • 1
    You need to convert this line to Vec<u8> and pass it to github.com/paritytech/parity-signer/blob/… - as you can see, that function also requires other information, that is, metadata and some extra network specs. Feel free to use this function (I'll certainly publish this crate after formatting it properly) or just study how it works - essentially it consumes method vector sequentially checking for exact formatting in metadata. I'll try to post my cowboy's notes on how to decode that manually later unless I forget to. Commented Mar 17, 2022 at 20:34
  • 1
    It is a struct that describes whether it is legacy or V14+ metadata: github.com/varovainen/parity-signer/blob/… If it is V14, it indeed contains substrate metadata object from frame_metadata Commented Mar 17, 2022 at 20:57
0

If your chain is running metadata version v14 or above you can use Libuptest:

use libuptest::decode_extrinsic::decode_extrinsic_hex_string;
use libuptest::jsonrpseeclient::JsonrpseeClient;
use libuptest::ws_mod::get_raw_metadata;


let raw_extrinsic = "input my hex string here";
let metadata: Vec<u8> = get_raw_metadata(JsonrpseeClient::polkadot_default_url().unwrap())
        .await?; 
let decoded_output = decode_extrinsic_hex_string(raw_extrinsic, &metadata);
println!("The decoded output is: {:?}", decoded_output);

https://github.com/uptest-sc/uptest/blob/main/examples/examples/decode_extrinsics.rs

Your Answer

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

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