apps/docs/src/guide/contracts/inter-contract-calls.md
This guide explains how to use the SDK to execute a contract call where one contract interacts with another contract. We will use a simple scenario involving a SimpleToken contract and a TokenDepositor contract.
SimpleToken and TokenDepositor ContractsIn this example, we have a SimpleToken contract representing a basic token contract capable of holding balances for different addresses. We also have a TokenDepositor contract that deposits tokens into the SimpleToken contract.
SimpleTokenHere's a simple token contract that allows holding balances:
<<< @/../../docs/sway/simple-token/src/main.sw#inter-contract-calls-1{rs:line-numbers}
TokenDepositorThe TokenDepositor contract imports the SimpleToken contract and calls its deposit function to deposit tokens:
<<< @/../../docs/sway/token-depositor/src/main.sw#inter-contract-calls-2{rs:line-numbers}
Once both contracts are deployed, we can use the SDK to make the TokenDepositor contract to call the SimpleToken contract.
<<< @./snippets/inter-contract-calls.ts#full{ts:line-numbers}
Pay attention to the method addContracts called by the TokenDepositor contract. This method accepts an array of instances of deployed contracts. Without calling this method, the inter-contract call will not work.