A frontend-only example showing how to interact with multiple contracts simultaneously.
- How to view methods in multiple contracts
- How to call methods in multiple contracts simultaneously
near-api-js
allows to dispatch multiple transactions simultaneously, so the user interacts with the wallet only once. However, the transactions remain independent.
const guestTx = {
receiverId: GUEST_ADDRESS,
actions: [
// You can batch actions against a contract: If any fails, they ALL get reverted
{
type: 'FunctionCall',
params: {
methodName: 'add_message', args: { text: greeting.value },
gas: THIRTY_TGAS, deposit: GUEST_DEPOSIT
}
}
]
}
const helloTx = {
receiverId: HELLO_ADDRESS,
actions: [
{
type: 'FunctionCall',
params: {
methodName: 'set_greeting', args: { greeting: greeting.value },
gas: THIRTY_TGAS, deposit: NO_DEPOSIT
}
}
]
}
// Ask the user to sign the **independent** transactions
await wallet.signAndSendTransactions({ transactions: [ helloTx, guestTx ] })
In this example, the user signs two independent transactions:
- A transaction to call
set_greeting
in our Hello NEAR example - A transaction to call
add_message
in our GuestBook example
Important Note: Even when the user accepts signing the transactions at the same time, the transactions remain independent. This is, if one fails, the other is NOT rollback.
In NEAR, only Actions against a same contract can be batched, so if one action fails they all get reverted.
Clone this repository locally or open it in gitpod. Then follow these steps:
npm install
Start the web application to interact with your smart contract
npm start
- Learn more about the contract through its README.
- Check our documentation.