This repo demonstrates cross-contract calls in Soroban smart contracts with different execution patterns and authorization requirements. It showcases how contracts can invoke other contracts in tree-like structures.
- Deno - Modern runtime for JavaScript and TypeScript
- Stellar CLI - The command line interface to Stellar smart contracts
- Copy the environment configuration:
cp .env.example .envThe .env is configured by default to use testnet. Feel free to adjust its parameters to use a different target network.
- Build the contract:
stellar contract buildThis project includes three different cross-contract execution patterns:
A basic linear chain of contract calls:
A -> B -> C
- A calls B
- B calls C
- C is a leaf node
- No authorization required
Deploy and run:
deno task deploy:simple
deno task call:simpleA complex tree structure with multiple branches:
A
/ | \
B C D
/| | |\
E F G H I
|
J
- A calls B, C, D
- B calls E, F
- C calls G
- D calls H, I
- H calls J
- E, F, G, I, J are leaf nodes
- No authorization required
Deploy and run:
deno task deploy:no-auth
deno task call:no-authA balanced tree with distributed authorization requirements:
A (u1)
/ \
B (u2) C
/ \ / \
D (u3) E F G (u1, u3)
/ \ / / \
H I J (u2) K L (u2)
- A calls B, C (requires user1 authorization)
- B calls D, E (requires user2 authorization)
- C calls F, G (no auth required)
- D calls H, I (requires user3 authorization)
- E calls J (no auth required)
- F calls K (no auth required)
- G calls L (requires user1 + user3 authorization)
- H, I, J, K, L are leaf nodes
Authorization Summary:
- A: requires u1
- B: requires u2
- D: requires u3
- G: requires u1 + u3 (multi-signature)
- J: requires u2
- L: requires u2
Deploy and run:
deno task deploy:auth
deno task call:authEach contract instance is configured during deployment with:
- Next contracts: Which contracts to call when
execute()is invoked - Auth addresses: Which user addresses must provide authorization
When you call execute() on the root contract:
- It checks for required authorizations
- Calls all configured next contracts
- Each next contract repeats the process
- Returns a list of all contract addresses that were invoked in the execution chain
The contract source lives at contracts/cross/src/contract.rs and implements a flexible pattern for cross-contract invocation testing.
Each example will show:
- The tree structure being executed
- All contract addresses in the execution order
- Authorization requirements (for auth example)
- User keypairs (for auth example)
This allows you to test different cross-contract call patterns and understand how authorization flows through contract invocation chains in Soroban.