Summary

The Foreign Call Protocol (FCP) facilitates the ability for SmartWeave contracts to behave inter-operably by invoking functions from other contracts that support FCP.

Background

The lack of interoperability between Arweave-based smart contracts has widely been considered a limiting factor to what developers can build with SmartWeave. It forced smart contract developers to design mechanisms that could not utilize or interface with external, existing mechanisms. The FCP removes this restriction.

Proposed Solution

Logic Flow

  1. User sends a nested contract interaction transaction for contract A to contract B by calling its invoke function.

    This contract interaction to contract B adds another contract interaction for contract A to contract B's foreignCalls array in the state (outbox)

  2. User sends a contract interaction transaction to contract A invoking its readOutbox function

    If contract A trusts contract B, this interaction triggers contract A to read the state of contract B to find the nested interaction inside of contract B's foreignCalls array

    With the new interaction, contract A recursively invokes the handle function to effectively process the nested interaction and update its own state

    The original nested interaction transaction is then added to the invocations state inside of contract A to prevent it from being evaluated twice.

Requirements

The FCP allows for two-way communication between SmartWeave contracts on Arweave. In order to facilitate this, contracts need two new arrays in their states and two new functions in their sources:

State modifications

Contract source modifications

Example Code

See two example contracts that successfully utilized the Foreign Call Protocol: ABC and DEF.