question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Submit Extrinsic error by Creating ExtrinsicPayload and sign

See original GitHub issue

I can’t make a transfer successfully, so I tired to generate extrinsicPayload and sign without creating signerPayload, but submitted extrinsic failed, could you please help me ? here’s the code and key pair:

it('totally-offline', async () => {
   const wsProvider = new WsProvider('wss://westend-rpc.polkadot.io')
    const from = '5FA5GKjtaCYHRhLtJ8bWhA1zP137PzTMmiDw8nfb5wDXSyGD';
    const to = '5Dgq3axpAPE7nUDKdhsxfvHKjBiRTwCQJesfxZ2z12b91TC3';
   const keyring = new Keyring({type: 'ed25519'});
    const pair = keyring.addFromUri(****)


    const api = await ApiPromise.create({provider: wsProvider});
    const nonce = (await api.query.system.account(from)).nonce.toString();
    const genesisHash = api._genesisHash.toString();
    const version = api.extrinsicVersion;
    const runtimeVersion = (await api._rpc.state.getRuntimeVersion());
    const header = await api.rpc.chain.getHeader();

    let current = header.number.toString()

    let registry = new TypeRegistry();
    let decorated = new Decorated(registry, metadataStatic);
    new Metadata(registry, metadataStatic);

    let tx = new Extrinsic(registry, decorated.tx.balances.transfer(to, 100));
    let era = registry.createType('ExtrinsicEra', {current: current, period: 900});


    let data = {
        address: from,
        blockHash: genesisHash,
       // blockNumber: '',
        era: era,
        genesisHash: genesisHash,
        method: tx.method.toHex(),
        nonce: nonce,
       // runtimeVersion: runtimeVersion,
       // signedExtensions:signedExtensions,
        specVersion: runtimeVersion.specVersion.toString(),
        tip: '',
      //  transactionVersion: runtimeVersion.transactionVersion.toString(),
       // version: version
    }

    let extrinsicPayload = new ExtrinsicPayload(registry, data, { version: 4 });

    const {signature} = extrinsicPayload.sign(pair);
    console.log('signature', signature)

    let verifySignature = hex.hexToU8a(signature).subarray(1)
    const verifyData = extrinsicPayload.toU8a(true);
    let verifyResult = pair.verify(verifyData, verifySignature);
    console.log('verifyResult', verifyResult)
    
     tx.addSignature(from, signature, extrinsicPayload);

     const hash = await api.rpc.author.submitExtrinsic(tx.toHex()
     console.log(hash.toHex())
    process.exit();
});

And always got the error: 1002: Verification Error: Execution(Wasmi(Trap(Trap { kind: Unreachable }))): RuntimeApi("Execution(Wasmi(Trap(Trap { kind: Unreachable })))

I don’t know what the problem is Can you please run my unit test and told me the result? thank you very much!

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:5

github_iconTop GitHub Comments

1reaction
jacklczcommented, Sep 21, 2020

i’m so sad

0reactions
polkadot-js-botcommented, Jun 3, 2021

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue if you think you have a related problem or query.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Tx.addSignature emiting error · Issue #4446 · polkadot-js/api
The extrinsic payload is signed, not the transaction. You are serializing the transaction and signing that. The payload has all transaction ...
Read more >
Sending extrinsic fails when signed payload goes over 256 ...
The extrinsic started failing with error code 1010 BadProof (invalid signature) all of a sudden. I managed to validate all the data again, ......
Read more >
Day in the Life of a Substrate Extrinsic - Unit 410
The Polkadot.js web UI does not show you the SCALE-encoded signer payload. It creates that on the fly when you click “Submit Transaction.”....
Read more >
Errors and How to Resolve Them - Polkadot Wiki
Polkascan and Subscan show the ExtrinsicFailed event when a transaction does not succeed (example). This event gives us the error and index ...
Read more >
Transactions in Off-chain Workers - Substrate Recipes
Unsigned transactions with signed payloads are used if the transaction requires ... This tell the runtime that this pallet can create signed transactions....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found