Skip to main content

Complex Cross Contract Call

This example presents 3 instances of complex cross-contract calls. Particularly, it shows:

  1. How to batch multiple method calls to a same contract.
  2. How to call multiple contracts in parallel, each returning a different type.
  3. Different ways of handling the responses in the callback.

Batch Actions​

You can aggregate multiple actions directed towards one same contract into a batched transaction. Methods called this way are executed sequentially, with the added benefit that, if one fails then they all get reverted.

contract/src/batch_actions.rs
loading...

Getting the Last Response​

In this case, the callback has access to the value returned by the last action from the chain.

contract/src/batch_actions.rs
loading...

Calling Multiple Contracts​

A contract can call multiple other contracts. This creates multiple transactions that execute all in parallel. If one of them fails the rest ARE NOT REVERTED.

contract/src/multiple_contracts.rs
loading...

Getting All Responses​

In this case, the callback has access to an array of responses, which have either the value returned by each call, or an error message.

contract/src/multiple_contracts.rs
loading...

Multiple Calls - Same Result Type​

This example is a particular case of the previous one (2. Calling Multiple Contracts). It simply showcases a different way to check the results by directly accessing the promise_result array.

In this case, we call multiple contracts that will return the same type:

contract/src/similar_contracts.rs
loading...

Getting All Responses​

In this case, the callback again has access to an array of responses, which we can iterate checking the results.

contract/src/similar_contracts.rs
loading...