# Multicall parameters when calling a function that sends tokens

**URL:** <https://forum.fuel.network/t/multicall-parameters-when-calling-a-function-that-sends-tokens/6630>\
**Category:** Rust SDK\
**Tags:** testnet, feedback, tutorials\
**Created:** [September 18, 2024, 7:31am UTC](https://forum.fuel.network/t/multicall-parameters-when-calling-a-function-that-sends-tokens/6630 "2024-09-18T07:31:19Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![partylikeits1983](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.fuel.network/partylikeits1983/32/3471_2.png) [@partylikeits1983](https://forum.fuel.network/u/partylikeits1983)\
**Post date:** [September 18, 2024, 7:31am UTC](https://forum.fuel.network/t/multicall-parameters-when-calling-a-function-that-sends-tokens/6630/1 "2024-09-18T07:31:19Z")

</div>

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:

```auto
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?

```auto
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:

> <https://github.com/compolabs/spark-rust-sdk-examples/blob/88fd3a03dfb473ec45ecdf09be277d45f5ff7c73/src/bin/market_multicall.rs#L91>

Here’s a tx on the block explorer that has the failed transaction when calling withdraw in the multicall: [Fuel Explorer](https://app.fuel.network/tx/0xa3f5c168e68ec76b6e1215c887fbe50dc7c02c06dcb1cc89825f149055fe91d9/simple)

---

<div class="post-metadata">

**Author:** ![hal3e](https://avatars.discourse-cdn.com/v4/letter/h/958977/32.png) [@hal3e](https://forum.fuel.network/u/hal3e)\
**Post date:** [September 18, 2024, 8:31am UTC](https://forum.fuel.network/t/multicall-parameters-when-calling-a-function-that-sends-tokens/6630/2 "2024-09-18T08:31:31Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![partylikeits1983](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.fuel.network/partylikeits1983/32/3471_2.png) [@partylikeits1983](https://forum.fuel.network/u/partylikeits1983)\
**Post date:** [September 18, 2024, 9:37am UTC](https://forum.fuel.network/t/multicall-parameters-when-calling-a-function-that-sends-tokens/6630/3 "2024-09-18T09:37:49Z")

</div>

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

> <https://github.com/compolabs/spark-rust-sdk-examples/blob/master/src/bin/withdraw_multicall.rs>

---

<div class="post-metadata">

**Author:** ![partylikeits1983](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.fuel.network/partylikeits1983/32/3471_2.png) [@partylikeits1983](https://forum.fuel.network/u/partylikeits1983)\
**Post date:** [September 19, 2024, 11:11am UTC](https://forum.fuel.network/t/multicall-parameters-when-calling-a-function-that-sends-tokens/6630/4 "2024-09-19T11:11:47Z")

</div>

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](https://github.com/compolabs/orderbook-contract/blob/aeca39ce9dab2ed5ec01b47a30222fac7a4b4d89/spark-market/tests/functions/core/withdraw.rs#L62)

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

---

<div class="post-metadata">

**Author:** ![hal3e](https://avatars.discourse-cdn.com/v4/letter/h/958977/32.png) [@hal3e](https://forum.fuel.network/u/hal3e)\
**Post date:** [September 20, 2024, 8:26am UTC](https://forum.fuel.network/t/multicall-parameters-when-calling-a-function-that-sends-tokens/6630/5 "2024-09-20T08:26:33Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![fuel](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.fuel.network/fuel/32/1677_2.png) [@fuel](https://forum.fuel.network/u/fuel)\
**Post date:** [September 20, 2024, 10:42am UTC](https://forum.fuel.network/t/multicall-parameters-when-calling-a-function-that-sends-tokens/6630/6 "2024-09-20T10:42:10Z")

</div>

added a test to our repo

> <https://github.com/compolabs/orderbook-contract/blob/aeca39ce9dab2ed5ec01b47a30222fac7a4b4d89/spark-market/tests/functions/core/withdraw.rs#L62>

we are using variable\_outputs in our sdk

> <https://github.com/compolabs/orderbook-contract/blob/aeca39ce9dab2ed5ec01b47a30222fac7a4b4d89/spark-market-sdk/src/lib.rs#L159>

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

**Steps to reproduce:**

1. **Using forc version “0.63.5”:**

2. **Using forc version “0.63.6”:**

---

<div class="post-metadata">

**Author:** ![partylikeits1983](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.fuel.network/partylikeits1983/32/3471_2.png) [@partylikeits1983](https://forum.fuel.network/u/partylikeits1983)\
**Post date:** [September 23, 2024, 11:08am UTC](https://forum.fuel.network/t/multicall-parameters-when-calling-a-function-that-sends-tokens/6630/7 "2024-09-23T11:08:42Z")

</div>

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.
