Multicall parameters when calling a function that sends tokens

Hello, I was wondering if there is a specific way to call a function in a contract that sends tokens when using the multicall feature.

For example, when not using multicall, this works just fine:

market.withdraw(quote_withdraw_amount, AssetType::Quote).await;

This function allows a user to withdraw assets.

However, when adding this same function call to the multi_call_handler, it will fail. I was wondering if there are specific call parameters I need to add to this call?

let mut multi_call_handler = CallHandler::new_multi_call(main_wallet.clone());
        
let withdraw_quote_call = market.get_instance().methods().withdraw(quote_withdraw_amount, AssetType::Quote);

multi_call_handler = multi_call_handler.add_call(withdraw_quote_call);

Here’s a script that does what I describe above, you can try it yourself:

Here’s a tx on the block explorer that has the failed transaction when calling withdraw in the multicall: Fuel Explorer

What is the error message you get? Is there a way for us to reproduce this locally ?

1 Like

Yes, the best way to replicate this is to clone the examples repo and run the withdraw_multicall.rs script:

Here’s an isolated test that is easy to run locally. In the test we withdraw and then deposit an asset from a single contract.

In our flow in production we would like to withdraw from one contract, then deposit to a second contract.

The test: orderbook-contract/spark-market/tests/functions/core/withdraw.rs at aeca39ce9dab2ed5ec01b47a30222fac7a4b4d89 · compolabs/orderbook-contract · GitHub

We get the error: “not enough coins to fit the target”

After setting the correct number of variable outputs the issue should be resolved.

added a test to our repo

we are using variable_outputs in our sdk

The error is still here, I checked it with different versions of forc

Steps to reproduce:

  1. Using forc version “0.63.5”:

    • Clone the repository:
      git clone git@github.com:compolabs/orderbook-contract.git
      
    • Switch to the branch:
      git checkout bug-multicall-withdraw-deposit
      
    • Run the test:
      cargo test --package spark-market --test integration_tests -- functions::core::withdraw::success --show-output
      
  2. Using forc version “0.63.6”:

    • Update the forc version in fuel-toolchain.toml to:
      forc = "0.63.6"
      
    • Build the project:
      forc build --release
      
    • Run the test:
      cargo test --package spark-market --test integration_tests -- functions::core::withdraw::success --show-output
      
1 Like

Just for reference, I was able to perform a multicall, withdrawing assets from one contract, and depositing them to another using our spark-rust-sdk-examples repo.

The issue is doing this within our tests in our orderbook-contract repo, as well as on the frontend using fuels-ts.