Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to decode block extrinsics using Polkadot js api

Tags:

polkadot-js

I am writing typescript code to get block information. I am connected to wss://kusama-rpc.polkadot.io . I am followig official polkadot js api documentation .

I am calling api.rpc.chain.getBlock method get block information, and it returns block information as json :

{
  "header": {
    "parentHash": "0xf292579563eb2f12e7a1571643d5285a072f04694397758cae76b38075daf631",
    "number": 1134,
    "stateRoot": "0x468de0ef831c96f56d518017b18d76a89f35f30371c45866d12c12ca2116a407",
    "extrinsicsRoot": "0x4875f3ab89c2a3c30f5de8be2ac40cfaee02059fd69ea76115550a418db5fcc8",
    "digest": {
      "logs": [
        "0x066175726120d86ae01200000000",
        "0x05617572610101be3d6d596445d3cb3b711da09e22f9f24c283306744657ce397d17ff1dbf9859051def7406cd356b2d3d2add155d76618f6b098de0c4ce6b7620106ec00e1188"
      ]
    }
  },
  "extrinsics": [
    "0x280401000bc0ca26af7001"
  ]
}

How do I get extrinsic details as -

{
    "method": {
        "callIndex": "0x0200",
        "section":"timestamp",
        "method": "set",
        "args" : [
            "1,582,827,870,000"
        ]
    },
    "isSigned": false
}

I am assuming the extrinsic I am getting is encoded, what is the method to to decode it?

like image 529
Bopsi Avatar asked Nov 07 '22 09:11

Bopsi


1 Answers

I found parseInt('0x33c395') works great to decode block numbers

like image 169
Deekor Avatar answered Dec 01 '22 11:12

Deekor