How to attach to transaction 2 payments?

I am trying to attach 2 payments to transaction, but don’t understand how to do it, and couldn’t find any related info.
Here is my following questions:

  • Is it possible to attach 2 token, with calParams you can attach one, but what abt 2?
  • how to access tokens on contract?
  • How to do it specifically with Rust SDK?

Looking forward for answers, thanks!

1 Like

I can help with some of this, but will need some more details on what you’re trying to do to address all of your points.

  1. You can only forward tokens of 1 asset ID with a call. However, you can use a sway script to atomically perform multiple contract calls in a single transaction.

  2. I’m not quite sure what you mean by “access tokens” on a contract, but if you tell me a bit more detail I can help with that. If you mean how do you query a contract for its token balance, , it would be the get_contract_asset_balance method on the provider: Provider in fuels::signers::provider - Rust

1 Like

For example, I want to call method “create_order” and attach 100 USDC as asset0 and 0.01 ETH or SWAY token as the matcher fee

Sorry, I only have this ts example of how we forward multiple assets. Here is the corresponding section in rust. I HAVEN’T COMPILED THIS RUST CODE but try something like this

let mut multi_call_handler = MultiContractCallHandler::new(wallet.clone());
multi_call_handler
  .add_call(contract.functions.deposit().call_params({ amount1, asset_id1 })
  .add_call(contract.functions.deposit().call_params({ amount2, asset_id2 })
  .call().await;

And how to handle 2 payments on the sway side?
Right now I’m use a call_frames::msg_asset_id and context::msg_amount but it returns only one value

As @furnic mentioned you can only forward 1 asset with a single call so you have use an sdk for a multicall or a sway script to call a contract function multiple times.

1 Like

On the sway side, this would be received as 2 seperate calls, so amount and asset id would be unique for each call.

2 Likes

I guess multicall will help me