Mikko Ohtamaa
Mikko Ohtamaa

Reputation: 83536

Dealing with promise chain failures in NEAR blockchain

I am writing a set of interacting smart contracts for a NEAR blockchain. Let's imagine the the following scenario

  1. User sends a token to an exchange smart contract
  2. Token smart contract calls exchange smart contract
  3. Exchange smart contract calls fee smart contract
  4. Exchange smart contract calls another token contract to send back another set token in the trade

Unlike a single shard Ethereum, NEAR does cross contract calls with promises. Whereas a single tripped require() automatically rolls back to the whole Ethereum transactions, in the sharded nature to NEAR smart contracts themselves are responsible for rolling back state changes if the promise they triggered does not complete successfully.

My question is how to safely handle failures in the chain of promises between NEAR smart contracts

Upvotes: 2

Views: 359

Answers (1)

berryguy
berryguy

Reputation: 1154

Generally you can only tell whether a promise has succeeded without knowing what goes wrong in the case of an error. An example of such a check can be found here https://github.com/near/core-contracts/blob/4f245101d7d029ffb3450c560770db244fc7b3ce/lockup/src/utils.rs#L7. What is the use case of reacting differently to different error that you have in mind?

Upvotes: 3

Related Questions