> For the complete documentation index, see [llms.txt](https://docs.applayer.com/testnet/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.applayer.com/testnet/understanding-contracts/internal-and-external-contract-calls.md).

# Internal and external contract calls

In the context of interacting with smart contracts, calls can be classified into two types: *external* and *internal*.

**External calls** occur when a contract is invoked from an external source, which can be either a user transaction (e.g. a block and its transactions are being processed) or a remote procedure call (RPC, e.g. an `eth_call` request). External calls serve as entry points into the smart contract from the outside world, initiating a transaction or a query. Within AppLayer's BDK, to process an external call, a `ContractHost` object is created, which establishes the execution context based on the specified parameters.

**Internal calls** occur when a smart contract, already running as part of an ongoing transaction/chain of execution, calls another contract or a function within another contract. This is considered an internal process, as it happens within the chain of execution started by an external call. In AppLayer's BDK, internal calls utilize the same `ContractHost` object created for the initial external call. This maintains consistency and control over the execution environment, allowing for functions like commits or rollbacks within the same transactional context.

Basically, an external call creates a new "chain of execution", while internal calls only exist within that same given chain of execution, thus they cannot create new chains by themselves. A chain of execution is a sequence of calls that are executed in a given external call, always composed of an initial external call and a set of internal calls (if applicable).


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.applayer.com/testnet/understanding-contracts/internal-and-external-contract-calls.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
