mrtnetwork / polkadot_dart

This package facilitates Substrate interactions: create, sign, send transactions (ECDSA, ED25519, SR25519), query, runtime calls, JSON-RPC for seamless Substrate operations.
BSD 3-Clause "New" or "Revised" License
3 stars 2 forks source link

Can't submit transfer transaction #3

Closed alirezaght closed 1 month ago

alirezaght commented 1 month ago

I'm trying to submit a transfer transaction. my code is like this:

var method = api!.transferAllowDeath(value, receiver);
final signer = privateKey.toAddress();
    final genesisHash =
        await provider!.request(const SubstrateRPCChainGetBlockHash(number: 0));
    final blockHash =
        await provider!.request(const SubstrateRPCChainChainGetFinalizedHead());
    final blockHeader = await provider!
        .request(SubstrateRPCChainChainGetHeader(atBlockHash: blockHash));
    final era = blockHeader.toMortalEra();
    final accountInfo = await getAccountInfo(signer);
    final int nonce = accountInfo.nonce;
    final version = api!.runtimeVersion();
    final int transactionVersion = version.transactionVersion;
    final int specVersion = version.specVersion;

    final payload = TransactionPayload(
        blockHash: SubstrateBlockHash.hash(blockHash),
        era: era,
        genesisHash: SubstrateBlockHash.hash(genesisHash),
        method: method,
        nonce: nonce,
        specVersion: specVersion,
        transactionVersion: transactionVersion,
        tip: BigInt.zero);

    final sig = privateKey.multiSignature(payload.serialize());

    final signature = ExtrinsicSignature(
        signature: sig,
        address: signer.toMultiAddress(),
        era: era,
        tip: BigInt.zero,
        nonce: nonce);
    final extrinsic = Extrinsic(signature: signature, methodBytes: method);
    final hash = await provider!.request(
        SubstrateRPCAuthorSubmitExtrinsic(extrinsic.toHex(prefix: "0x")));

But I get this error:


RPCError: got code 1002 with msg "Verification Error: Runtime error: Execution failed: Execution aborted due to trap: wasm trap: wasm `unreachable` instruction executed
WASM backtrace:
error while executing at wasm backtrace:
    0: 0x40cc7 - substrate_runtime.wasm!rust_begin_unwind
    1: 0x393a - substrate_runtime.wasm!core::panicking::panic_fmt::hc7427f902a13f1a9
    2: 0xd52e4 - substrate_runtime.wasm!TaggedTransactionQueue_validate_transaction". RuntimeApi("Execution failed: Execution aborted due to trap: wasm trap: wasm `unreachable` instruction executed\nWASM backtrace:\nerror while executing at wasm backtrace:\n    0: 0x40cc7 - substrate_runtime.wasm!rust_begin_unwind\n    1: 0x393a - substrate_runtime.wasm!core::panicking::panic_fmt::hc7427f902a13f1a9\n    2: 0xd52e4 - substrate_runtime.wasm!TaggedTransactionQueue_validate_transaction")
#0      SubstrateRPC._findResult (package:polkadot_dart/src/provider/provider/provider.dart:21:7)
#1      SubstrateRPC.request (package:polkadot_dart/src/provider/provider/provider.dart:45:30)
<asynchronous suspension>
#2      SubstrateService.submitMethod (package:example/blockchain/substrate_service.dart:136:18)
<asynchronous suspension>
#3      main (package:example/blockchain/test.dart:12:13)
<asynchronous suspension>

I also see this log on my substrate node:

ERROR tokio-runtime-worker runtime: [Parachain] panicked at /parachain/runtime/src/lib.rs:520:1:
Bad input data provided to validate_transaction: Codec error 

Can anyone help me on this?

mrtnetwork commented 1 month ago

I'm trying to submit a transfer transaction. my code is like this:

var method = api!.transferAllowDeath(value, receiver);
final signer = privateKey.toAddress();
    final genesisHash =
        await provider!.request(const SubstrateRPCChainGetBlockHash(number: 0));
    final blockHash =
        await provider!.request(const SubstrateRPCChainChainGetFinalizedHead());
    final blockHeader = await provider!
        .request(SubstrateRPCChainChainGetHeader(atBlockHash: blockHash));
    final era = blockHeader.toMortalEra();
    final accountInfo = await getAccountInfo(signer);
    final int nonce = accountInfo.nonce;
    final version = api!.runtimeVersion();
    final int transactionVersion = version.transactionVersion;
    final int specVersion = version.specVersion;

    final payload = TransactionPayload(
        blockHash: SubstrateBlockHash.hash(blockHash),
        era: era,
        genesisHash: SubstrateBlockHash.hash(genesisHash),
        method: method,
        nonce: nonce,
        specVersion: specVersion,
        transactionVersion: transactionVersion,
        tip: BigInt.zero);

    final sig = privateKey.multiSignature(payload.serialize());

    final signature = ExtrinsicSignature(
        signature: sig,
        address: signer.toMultiAddress(),
        era: era,
        tip: BigInt.zero,
        nonce: nonce);
    final extrinsic = Extrinsic(signature: signature, methodBytes: method);
    final hash = await provider!.request(
        SubstrateRPCAuthorSubmitExtrinsic(extrinsic.toHex(prefix: "0x")));

But I get this error:


RPCError: got code 1002 with msg "Verification Error: Runtime error: Execution failed: Execution aborted due to trap: wasm trap: wasm `unreachable` instruction executed
WASM backtrace:
error while executing at wasm backtrace:
    0: 0x40cc7 - substrate_runtime.wasm!rust_begin_unwind
    1: 0x393a - substrate_runtime.wasm!core::panicking::panic_fmt::hc7427f902a13f1a9
    2: 0xd52e4 - substrate_runtime.wasm!TaggedTransactionQueue_validate_transaction". RuntimeApi("Execution failed: Execution aborted due to trap: wasm trap: wasm `unreachable` instruction executed\nWASM backtrace:\nerror while executing at wasm backtrace:\n    0: 0x40cc7 - substrate_runtime.wasm!rust_begin_unwind\n    1: 0x393a - substrate_runtime.wasm!core::panicking::panic_fmt::hc7427f902a13f1a9\n    2: 0xd52e4 - substrate_runtime.wasm!TaggedTransactionQueue_validate_transaction")
#0      SubstrateRPC._findResult (package:polkadot_dart/src/provider/provider/provider.dart:21:7)
#1      SubstrateRPC.request (package:polkadot_dart/src/provider/provider/provider.dart:45:30)
<asynchronous suspension>
#2      SubstrateService.submitMethod (package:example/blockchain/substrate_service.dart:136:18)
<asynchronous suspension>
#3      main (package:example/blockchain/test.dart:12:13)
<asynchronous suspension>

I also see this log on my substrate node:

ERROR tokio-runtime-worker runtime: [Parachain] panicked at /parachain/runtime/src/lib.rs:520:1:
Bad input data provided to validate_transaction: Codec error 

Can anyone help me on this?

Hi, I tried this example, and it worked fine.

Make sure you're using the latest version of the runtime metadata, as the package repository for metadata might be outdated. Here's a code snippet that requests the metadata from the blockchain and determines its version:

/// Requesting metadata from the blockchain to determine its version.
final requestMetadata = await provider
    .request(const SubstrateRPCRuntimeMetadataGetMetadataAtVersion(15));
final metadata = requestMetadata!.metadata as MetadataV15;

If this doesn't resolve your issue, please share the complete code, and I'll be happy to help further.

alirezaght commented 1 month ago

That is exactly how I get the metadata:

final requestMetadata = await provider
          ?.request(const SubstrateRPCRuntimeMetadataGetMetadataAtVersion(15));
      final metadata = requestMetadata?.metadata as MetadataV15;
final api = MetadataApi(metadata);

however, I'm trying to connect to my own parachain with this.

alirezaght commented 1 month ago

it was a problem with my parachain. fixed.