1

I am working on a Substrate-based blockchain project and I have the following function in my custom pallet:

#[pallet::call_index(8)]
#[pallet::weight(<T as Config>::WeightInfo::create_exchange())]
#[transactional]
pub fn call_smart_contract(
    origin: OriginFor<T>,
    dest: T::AccountId,
    mut selector: Vec<u8>,
    arg: u32,
    gas_limit: Weight,
) -> DispatchResult {
    let who = ensure_signed(origin)?;
    ensure!(selector.len() < MAX_LENGTH, Error::<T>::InputTooLarge);
    let value: BalanceOf<T> = Default::default();
    let mut arg_enc: Vec<u8> = arg.encode();
    let mut data = Vec::new();
    data.append(&mut selector);
    data.append(&mut arg_enc);

    pallet_contracts::Pallet::<T>::bare_call(
        who,
        dest.clone(),
        value,
        gas_limit,
        data,
        pallet_contracts::Pallet::<T>::deterministic(),
        None,
        false,
    );

    Self::deposit_event(Event::CalledContractFromPallet(dest));
    Ok(())
}

I encountered the following errors when compiling my code:

1 - Error: no method named map_err found for struct ContractResult in the current scope

--> /home/kianoush/projects/music-chain/frame/dex/src/lib.rs:327:5
327 |             .map_err(|e| {
|              ^^^^^^^ method not found in `ContractResult<Result<ExecReturnValue, DispatchError>, <<T as Config>::Currency as Currency<<T as Config>::AccountId>>::Balance>`

2 - Error: no associated item named Deterministic found for struct Pallet in the current scope

--> /home/kianoush/projects/music-chain/frame/dex/src/lib.rs:323:36
323 |                 pallet_contracts::Pallet::<T>::Deterministic,
|                                                ^^^^^^^^^^^^^ associated item not found in `Pallet<T>`

3 - Error: arguments to this function are incorrect

--> /home/kianoush/projects/music-chain/frame/dex/src/lib.rs:317:4
317  |             pallet_contracts::Pallet::<T>::bare_call(

I am not sure how to resolve these errors. Can anyone help me understand what's wrong with my code and how to fix these issues?

0

1 Answer 1

4

what version of the template / pallet-contracts are you using?

--> /home/kianoush/projects/music-chain/frame/dex/src/lib.rs:323:36
323 |                 pallet_contracts::Pallet::<T>::Deterministic,

It looks like this does not exist, you should probably use something like that instead

pallet_contracts::Determinism::Deterministic

The parameters seems incorrect as well, see Rust Doc here

 pallet_contracts::Pallet::<T>::bare_call(
        who,
        dest.clone(),
        value,
        gas_limit,
        data,
        pallet_contracts::Pallet::<T>::deterministic(),
        None,
        false,
    );

Finally, If you are just trying to deploy contracts, you can probably use this substrate-contracts-node which is already configured with the pallet-contracts (see configuration here)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.