1

Is there any way to call ink! smart contract function in substrate custom pallet?

We've found this answer where bare_call function is based on older version of contract_pallet.

// This ends up calling our contract!
pallet_contracts::Pallet::<T>::bare_call(
    who,
    dest.clone(),
    value,
    gas_limit,
    data,
    debug,
)
.result?;

Now in updated version bare_call function is like this,

pub fn bare_call(
    origin: T::AccountId,
    dest: T::AccountId,
    value: BalanceOf<T>,
    gas_limit: Weight,
    storage_deposit_limit: Option<BalanceOf<T>>,
    data: Vec<u8>,
    debug: DebugInfo,
    collect_events: CollectEvents,
    determinism: Determinism,
) -> ContractExecResult<BalanceOf<T>, EventRecordOf<T>> {}

This is our github repo and right now we are getting this error,

ganesholi@Ganeshs-MacBook-Air MarketplaceMVP_Substrate % cargo build --release
   Compiling node-template-runtime v4.0.0-dev (/Users/ganesholi/xcav/MarketplaceMVP_Substrate/runtime)
   Compiling pallet-community-loan-pool v4.0.0-dev (/Users/ganesholi/xcav/MarketplaceMVP_Substrate/pallets/community-loan-pool)
warning: unused import: `frame_support::traits::tokens::Balance`
  --> pallets/community-loan-pool/src/lib.rs:58:6
   |
58 |     use frame_support::traits::tokens::Balance;
   |         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
   |
   = note: `#[warn(unused_imports)]` on by default

error[E0308]: arguments to this function are incorrect
    --> pallets/community-loan-pool/src/lib.rs:264:4
     |
264  |             pallet_contracts::Pallet::<T>::bare_call(
     |             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
...
268  |                 gas_limit,
     |                 --------- expected struct `Weight`, found integer
     |
note: expected pallet_contracts::Config::Currency, found pallet::Config::Currency
    --> pallets/community-loan-pool/src/lib.rs:267:5
     |
267  |                 value,
     |                 ^^^^^
     = note: expected associated type `<<T as pallet_contracts::Config>::Currency as frame_support::traits::Currency<<T as SysConfig>::AccountId>>::Balance`
                found associated type `<<T as pallet::Config>::Currency as frame_support::traits::Currency<<T as SysConfig>::AccountId>>::Balance`
note: expected pallet_contracts::Config::Currency, found pallet::Config::Currency
    --> pallets/community-loan-pool/src/lib.rs:269:5
     |
269  |                 storage_deposit_limit,
     |                 ^^^^^^^^^^^^^^^^^^^^^
     = note: expected enum `std::option::Option<<<T as pallet_contracts::Config>::Currency as frame_support::traits::Currency<<T as SysConfig>::AccountId>>::Balance>`
                found enum `std::option::Option<<<T as pallet::Config>::Currency as frame_support::traits::Currency<<T as SysConfig>::AccountId>>::Balance>`
note: associated function defined here
    --> /Users/ganesholi/.cargo/git/checkouts/substrate-7e08433d4c370a21/98f2e34/frame/contracts/src/lib.rs:1160:9
     |
1160 |     pub fn bare_call(
     |            ^^^^^^^^^
help: call `Into::into` on this expression to convert `{integer}` into `Weight`
     |
268  |                 gas_limit.into(),
     |                          +++++++

For more information about this error, try `rustc --explain E0308`.
warning: `pallet-community-loan-pool` (lib) generated 1 warning
error: could not compile `pallet-community-loan-pool` due to previous error; 1 warning emitted
warning: build failed, waiting for other jobs to finish...
error: failed to run custom build command for `node-template-runtime v4.0.0-dev (/Users/ganesholi/xcav/MarketplaceMVP_Substrate/runtime)`

Caused by:
  process didn't exit successfully: `/Users/ganesholi/xcav/MarketplaceMVP_Substrate/target/release/build/node-template-runtime-666e594096483e01/build-script-build` (exit status: 1)
  --- stdout
  Information that should be included in a bug report.
  Executing build command: RUSTFLAGS="-C link-arg=--export-table -Clink-arg=--export=__heap_base -C link-arg=--import-memory  " SKIP_WASM_BUILD="" "/Users/ganesholi/.rustup/toolchains/nightly-2023-01-01-aarch64-apple-darwin/bin/cargo" "rustc" "--target=wasm32-unknown-unknown" "--manifest-path=/Users/ganesholi/xcav/MarketplaceMVP_Substrate/target/release/wbuild/node-template-runtime/Cargo.toml" "--color=always" "--profile" "release"
  Using rustc version: rustc 1.68.0-nightly (574b64a97 2022-12-31)


  --- stderr
     Compiling pallet-community-loan-pool v4.0.0-dev (/Users/ganesholi/xcav/MarketplaceMVP_Substrate/pallets/community-loan-pool)
  warning: unused import: `frame_support::traits::tokens::Balance`
    --> /Users/ganesholi/xcav/MarketplaceMVP_Substrate/pallets/community-loan-pool/src/lib.rs:58:6
     |
  58 |     use frame_support::traits::tokens::Balance;
     |         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
     |
     = note: `#[warn(unused_imports)]` on by default

  error[E0308]: arguments to this function are incorrect
      --> /Users/ganesholi/xcav/MarketplaceMVP_Substrate/pallets/community-loan-pool/src/lib.rs:264:4
       |
  264  |             pallet_contracts::Pallet::<T>::bare_call(
       |             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  ...
  268  |                 gas_limit,
       |                 --------- expected struct `Weight`, found integer
       |
  note: expected pallet_contracts::Config::Currency, found pallet::Config::Currency
      --> /Users/ganesholi/xcav/MarketplaceMVP_Substrate/pallets/community-loan-pool/src/lib.rs:267:5
       |
  267  |                 value,
       |                 ^^^^^
       = note: expected associated type `<<T as pallet_contracts::Config>::Currency as frame_support::traits::Currency<<T as SysConfig>::AccountId>>::Balance`
                  found associated type `<<T as pallet::Config>::Currency as frame_support::traits::Currency<<T as SysConfig>::AccountId>>::Balance`
  note: expected pallet_contracts::Config::Currency, found pallet::Config::Currency
      --> /Users/ganesholi/xcav/MarketplaceMVP_Substrate/pallets/community-loan-pool/src/lib.rs:269:5
       |
  269  |                 storage_deposit_limit,
       |                 ^^^^^^^^^^^^^^^^^^^^^
       = note: expected enum `Option<<<T as pallet_contracts::Config>::Currency as frame_support::traits::Currency<<T as SysConfig>::AccountId>>::Balance>`
                  found enum `Option<<<T as pallet::Config>::Currency as frame_support::traits::Currency<<T as SysConfig>::AccountId>>::Balance>`
  note: associated function defined here
      --> /Users/ganesholi/.cargo/git/checkouts/substrate-7e08433d4c370a21/98f2e34/frame/contracts/src/lib.rs:1160:9
       |
  1160 |     pub fn bare_call(
       |            ^^^^^^^^^

  For more information about this error, try `rustc --explain E0308`.
  warning: `pallet-community-loan-pool` (lib) generated 1 warning
  error: could not compile `pallet-community-loan-pool` due to previous error; 1 warning emitted
ganesholi@Ganeshs-MacBook-Air MarketplaceMVP_Substrate %
4
  • 1
    This answer substrate.stackexchange.com/a/3949/234 might be useful for you.
    – dominique
    Aug 23 at 7:18
  • Try adding the pallet_contracts::Config to your Config (tight coupling). Aug 24 at 7:44
  • I have added now getting different error can you please look at
    – Ganesh11
    Aug 24 at 9:33
  • expected pallet_contracts::Config::Currency, found pallet::Config::Currency
    – Ganesh11
    Aug 24 at 9:39

1 Answer 1

1

As the error messages clearly state:

arguments to the function are incorrect

This has nothing to do with the change to the bare_call function; two additional arguments (which are not the cause of your problem).

However, it already provides one solution: gas_limit.into(), which converts the integer you give to the Weight struct.

The other two are solved with using a correct BalanceOf<T> type, e.g.:

type BalanceOf<T> = <<T as pallet_contracts::Config>::Currency as Currency<
    <T as frame_system::Config>::AccountId,

I suggest you study the post provided in the comments because it provides all the info you need. The problems you are facing right now are related to providing the correct arguments (working example).

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.