2

Getting Error : "Verification Error: Runtime error: Execution failed: Runtime panicked: Bad input data provided to validate_transaction: Invalid length prefix" While calling the custom RPC method in substrate using golang centrifuge rpc client.

Custom Pallet Method

#[pallet::weight(10000)]
    pub fn post_single(
        origin: OriginFor<T>,
        amount: <<T as Config>::Currency as Currency<<T as frame_system::Config>::AccountId>>::Balance,
        ) -> DispatchResult {
        let author = ensure_signed(origin)?;
                
        
         T::Currency::deposit_creating(
            &author,
            amount
        );
    

        Self::deposit_event(Event::PostTransaction(author));

        Ok(())
    }

Code from glang

    func Example_makeASimpleTransfer() {
        // Instantiate the API
        api, err := gsrpc.NewSubstrateAPI(config.Default().RPCURL)
        if err != nil {
            panic(err)
        }
    
        meta, err := api.RPC.State.GetMetadataLatest()
        if err != nil {
            panic(err)
        }
        
        if err != nil {
            panic(err)
        }
    
    
        bal, ok := new(big.Int).SetString("100000000000000", 10)
        if !ok {
            panic(fmt.Errorf("failed to convert balance"))
        }
    
    
        c, err := types.NewCall(meta, "Ntxn.post_single",types.NewUCompact(bal))
        if err != nil {   
          panic(err)
        }   
         ........
_, err = api.RPC.Author.SubmitExtrinsic(ext)
    if err != nil {
        panic(err)
    }
}   

Substrate node has panic error.

Version: 4.0.0-dev-71cad6ec672

0: sp_panic_handler::set::{{closure}} 1: std::panicking::rust_panic_with_hook at /rustc/897e37553bba8b42751c67658967889d11ecd120/library/std/src/panicking.rs:702:17 2: std::panicking::begin_panic_handler::{{closure}} at /rustc/897e37553bba8b42751c67658967889d11ecd120/library/std/src/panicking.rs:588:13 3: std::sys_common::backtrace::__rust_end_short_backtrace at /rustc/897e37553bba8b42751c67658967889d11ecd120/library/std/src/sys_common/backtrace.rs:138:18 4: rust_begin_unwind at /rustc/897e37553bba8b42751c67658967889d11ecd120/library/std/src/panicking.rs:584:5 5: core::panicking::panic_fmt at /rustc/897e37553bba8b42751c67658967889d11ecd120/library/core/src/panicking.rs:142:14 6: node_template_runtime::api::dispatch 7: std::thread::local::LocalKey::with 8: sc_executor::native_executor::WasmExecutor::with_instance::{{closure}} 9: sc_executor::wasm_runtime::RuntimeCache::with_instance 10: <sc_executor::native_executor::NativeElseWasmExecutor as sp_core::traits::CodeExecutor>::call 11: sp_state_machine::execution::StateMachine<B,H,Exec>::execute_aux 12: sp_state_machine::execution::StateMachine<B,H,Exec>::execute_using_consensus_failure_handler 13: <sc_service::client::call_executor::LocalCallExecutor<Block,B,E> as sc_client_api::call_executor::CallExecutor>::contextual_call 14: <sc_service::client::client::Client<B,E,Block,RA> as sp_api::CallApiAt>::call_api_at 15: <node_template_runtime::RuntimeApiImpl<SR_API_BLOCK,RuntimeApiImplCall> as sp_finality_grandpa::GrandpaApi<SR_API_BLOCK>>::__runtime_api_internal_call_api_at 16: sp_transaction_pool::runtime_api::TaggedTransactionQueue::validate_transaction 17: tracing::span::Span::in_scope 18: sc_transaction_pool::api::validate_transaction_blocking 19: core::future::from_generator::GenFuture<T as core::future::future::Future>::poll 20: core::future::from_generator::GenFuture<T as core::future::future::Future>::poll 21: <futures_util::future::future::Map<Fut,F> as core::future::future::Future>::poll 22: <sc_service::task_manager::prometheus_future::PrometheusFuture as core::future::future::Future>::poll 23: core::future::from_generator::GenFuture<T as core::future::future::Future>::poll 24: tokio::runtime::context::BlockingRegionGuard::block_on 25: tokio::runtime::handle::Handle::block_on 26: tokio::runtime::blocking::task::BlockingTask<T as core::future::future::Future>::poll

As I am new to substrate and Rust not able to identify the issue. Please help how I need to pass the balance value. Seems that is the problem here.

Thanks in advance.

1 Answer 1

2

It is difficult do debug any of your issue without source code.
However, it could be just the way that you are passing the balance.
Instead of types.NewUCompact you can try types.U128. The exact type depends on your runtime config, but the default would be U128, which has worked for me in the past as well.

If this does not solve your issue then please provide the code, thanks.

1
  • 1
    Thanks Its working when changed the types.
    – Kumar
    Dec 21, 2022 at 8:44

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.