0

I am using python substrate Interface (https://github.com/polkascan/py-substrate-interface) to interact with the substrate node.

I need to execute Pallet::Balances::transfer twice by combine both of my transaction in the utility batch. Now I wanted to retrieve the status and other details of my transaction. How Can I do that. Following is the code that I am using:


from substrateinterface import SubstrateInterface, Keypair
from tools.utils import show_extrinsic, WS_URL, TOKEN_NUM_BASE,transfer
from tools.two_address_substrate_with_extrinsic import show_account 
  
def pallet_utility_test():
    substrate = SubstrateInterface (
        url=WS_URL
)

    kp_src = Keypair.create_from_uri('//Alice')
    kp_dst=Keypair.create_from_uri('//Bob')
  

 
   
    nonce = substrate.get_account_nonce(kp_src.ss58_address)
    amount_to_be_transfered= 10  
    
    #first valid transaciton
    payload_first = substrate.compose_call(
        call_module='Balances',
        call_function='transfer',
        call_params={
            'dest': kp_dst.ss58_address,
            'value': amount_to_be_transfered * TOKEN_NUM_BASE
        })

    #Second invalid transaciton
    payload_second = substrate.compose_call(
        call_module='Balances',
        call_function='force_transfer',
        call_params={
            'source': kp_src.ss58_address, 
            'dest': kp_dst.ss58_address,
            'value': amount_to_be_transfered * TOKEN_NUM_BASE
        })


    batch = substrate.compose_call(
        call_module='Utility',
        call_function='batch',
        call_params={
            'calls': [payload_first.value, payload_second.value],
        })

    extrinsic = substrate.create_signed_extrinsic(
        call=batch,
        keypair= kp_src,
        era={'period': 64},
        nonce=nonce
    )

    receipt = substrate.submit_extrinsic(extrinsic, wait_for_inclusion=True)
    
    if not receipt.is_success:
        print(substrate.get_events(receipt.block_hash))
        raise IOError

1 Answer 1

1

If you wait for the extrinsic to be finalized by setting wait_for_finalization=True in the submit_extrinsic call, you will get back relevant information in the receipt. The best resource for this is the docs or in the extrinsic receipt source code.

For instance, you can look at

  • receipt.triggered_events to get the events that were triggered by the transaction
  • receipt.is_success like you already do to see if it succeeded
  • receipt.extrinsic to get info about the extrinsic itself
  • receipt.error_message to get info about how it failed, if it failed

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.