polkascan / py-substrate-interface

Python Substrate Interface
https://polkascan.github.io/py-substrate-interface/
Apache License 2.0
239 stars 111 forks source link

How to create an Hex that can be used in JS UI with Extrinsic / Decode? #373

Closed johnuopini closed 6 months ago

johnuopini commented 6 months ago

Is there a way to encode the compose_call output in a way that can be understood in JS UI using Extrinsic -> Decode? I cant find an equivalent to toHex() in JS.

arjanz commented 6 months ago

You can output the hex of the encoded SCALE data using call.data.to_hex():

call = substrate.compose_call(
    call_module='Balances',
    call_function='transfer',
    call_params={
        'dest': '5FHneW46xGXgs5mUiveU4sbTyGBzmstUspZC92UhjJM694ty',
        'value': 1 * 10**15
    }
)

print(call.data.to_hex())

For the other way around, see: https://github.com/polkascan/py-substrate-interface/discussions/361

johnuopini commented 6 months ago

Works like a charm, thanks!