call and try_call:
try_call(contract, function, args)callsfunctionexported fromcontract, passingargsand returning anErroron a recoverable error. A non-recoverable error traps instead.call(contract, function, args)just callstry_callwith its arguments and traps onError, essentially propagating the error.
contract is a Binary host object containing the contract ID, function is a Symbol holding the name of an exported function to call, and args is a Vector of values to pass as arguments.
These host functions can be invoked in two separate ways:
- From outside the host, such as when a user submits a transaction that calls a contract.
- From within the host, when one contract calls another.
- The contract’s Wasm bytecode is retrieved from a
CONTRACT_DATAledger entry in the host’s storage system. - A Wasm VM is instantiated for the duration of the invocation.
- The function is looked up and invoked, with arguments passed from caller to callee.
Recoverable and Non-Recoverable Errors
try_call returns an Error value only for a recoverable error. A non-recoverable error traps the caller instead: the invocation aborts and the transaction fails, and the calling contract cannot handle the error. A contract does not choose which errors are recoverable. The host decides, and the rule is the same for every contract.
Two groups of errors are non-recoverable:
- Resource limit errors, which carry the error code
ExceededLimitand the error typeBudgetorStorage. ABudgeterror means the transaction ran out of CPU instructions or memory. AStorageerror means the contract accessed a ledger entry that the transaction footprint does not list. - Internal errors, which carry the error code
InternalErrorand any error type other thanContract. The host found a fault in its own logic. This should not happen in practice.
simulateTransaction never saw. The footprint then misses that entry and the call traps. Debugging Contract Errors lists the diagnostic events for this case and the other errors of the apply step.
Every other error is recoverable. try_call passes a contract error code through unchanged. It reports every other recoverable host error as an error of type Context with the code InvalidAction, and the granular code stays visible in the diagnostic events.