Simple Cross-Contract CallsCheck the tutorial on how to use simple cross-contract calls
Obtaining the Cross Contract Call Example
You have two options to start the Donation Example:- You can use the app through
Github Codespaces, which will open a web-based interactive environment. - Clone the repository locally and use it from your computer.
Structure of the Example
The smart contract is available in two flavors: Rust and JavaScript- 🌐 JavaScript
- 🦀 Rust
Smart Contract
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.Getting the Last Response
In this case, the callback has access to the value returned by the last action from the chain.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.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.Multiple Calls - Same Result Type
This example is a particular case of the previous one (Calling Multiple Contracts). It simply showcases a different way to check the results by directly accessing thepromise_result array.
In this case, we call multiple contracts that will return the same type:
Getting All Responses
In this case, the callback again has access to an array of responses, which we can iterate checking the results.Testing the Contract
The contract readily includes a set of unit and sandbox testing to validate its functionality. To execute the tests, run the following commands:- 🌐 JavaScript
- 🦀 Rust
Deploying the Contract to the NEAR network
In order to deploy the contract you will need to create a NEAR account.- Short
- Full
cd contract-advanced-ts or cd contract-advanced-rs), build and deploy it:
- 🌐 JavaScript
- 🦀 Rust
CLI: Interacting with the Contract
To interact with the contract through the console, you can use the following commands:- Short
- Full
If at some point you get an “Exceeded the prepaid gas” error, try to increase the gas amount used within the functions when calling other contracts
Versioning for this articleAt the time of this writing, this example works with the following versions:
- near-cli:
4.0.13 - node:
18.19.1 - rustc:
1.77.0