if_else

Call v320 → current #6

Executes fallback call if main call fails.

View calls on chain

Click items to navigate. Pan and zoom to explore.

From Chain Metadata

Dispatch a fallback call in the event the main call fails to execute. May be called from any origin except `None`. This function first attempts to dispatch the `main` call. If the `main` call fails, the `fallback` is attemted. if the fallback is successfully dispatched, the weights of both calls are accumulated and an event containing the main call error is deposited. In the event of a fallback failure the whole call fails with the weights returned. `main`: The main call to be dispatched. This is the primary action to execute. `fallback`: The fallback call to be dispatched in case the `main` call fails. ## Dispatch Logic If the origin is `root`, both the main and fallback calls are executed without applying any origin filters. If the origin is not `root`, the origin filter is applied to both the `main` and `fallback` calls. ## Use Case Some use cases might involve submitting a `batch` type call in either main, fallback or both.

Input Parameters

#NameTypeDescription
0
main
RuntimeCall main (RuntimeCall)
1
fallback
RuntimeCall fallback (RuntimeCall)

Permissions

Origin
Unknown
Required Role

Permission data inferred from metadata. May be incomplete.

Requirements

  • Main and fallback calls provided

Effects

Postconditions

  • Main call executed, or fallback on failure

Side Effects

  • Enables conditional execution patterns

Code Examples

import { ApiPromise, WsProvider } from "@polkadot/api";
import { stringCamelCase } from "@polkadot/util";

const provider = new WsProvider("wss://entrypoint-finney.opentensor.ai:443");
const api = await ApiPromise.create({ provider });

// Build if_else call
const main = 0 as any /* RuntimeCall */;
const fallback = 0 as any /* RuntimeCall */;

const call = api.tx[stringCamelCase("Utility")][stringCamelCase("if_else")](
  main,
  fallback
);

Runtime Info

Pallet Index
11
Call Index
6
First Version
v320
Current Version
v393