1

I'm wondering what are the possible ways to extract the payload from a polkadot-js transaction. So far the only way seems to be to define a custom signer that implements the Signer interface and then pass it to one of the sign methods on the transaction (SignAndSend, SignAsync, ...) to get access to the payload in the signPayload method. This of course works when someone wants to implement a custom Signer, but I am wondering if there is any other way to extract or construct a transaction payload without implementing a custom signer?!

1
  • Can you give a more concrete example of what you are looking for?
    – Bruno
    Mar 4, 2023 at 0:55

1 Answer 1

0

This code may help (or at least give you some insight):

import { ApiPromise, WsProvider } from '@polkadot/api';

export const getExtrinsic = async () => {

    const wsProvider = new WsProvider('wss://rpc.polkadot.io');
    const api = await ApiPromise.create({ provider: wsProvider });
    const exampleBlockNumber = 7200920
    const blockHash = await api.rpc.chain.getBlockHash(exampleBlockNumber);
    const signedBlock = await api.rpc.chain.getBlock(blockHash);
    const extrinsicHash = "0xeb8f2a5af4a82a237e7e270ed6bd51ce82bb9253802259fd0fdb24212fe65260"
    signedBlock.block.extrinsics.forEach(async (ex, index) => {
        if (extrinsicHash === ex.hash.toHex()) {
            console.log(index, ex.toHuman());
            const { method: { args, method, section } } = ex;
            console.log(`${section}.${method}(${args.map((a) => a.toString()).join(', ')})`);
        }
    });
}

If you need any of the data that it returns in hex you can use: .toHex()

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.