> For the complete documentation index, see [llms.txt](https://docs.ainetwork.ai/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.ainetwork.ai/ain-blockchain/ai-network-design/blockchain-database/triggers/built-in-functions.md).

# Built-in Functions

## Built-in Functions

To apply predefined system operations, built-in functions are defined. For example, account value transfer is implemented using transfer built-in function. Each built-in function consists of triggering conditions and a function. The triggering condition is given by a database path pattern and whenever a new value is written on the path patten, the function is called. If the function fails, the transaction triggered the function call also fails.

### Transfer

```
{
  '/transfer/{from_addr}/{to_addr}/{transfer_id}/value': _transfer(value, context) {
    // Check (the balance of from_addr) >= value
    // Decrement the balance of from_addr by value
    // Increment the balance of to_addr by value
  }
}
```

### Deposit

```
{
  '/deposit/{service_id}/{addr}/{deposit_id}/value': _deposit(value, context) {
    // Check (the balance of addr) >= value
    // Decrement the balance of addr by value
    // Increment the value of /deposit_accounts/$service_id/$addr by value
    // Set /deposit_accounts/$service_id/$addr/expire_at as
    // transaction's timestamp + service's deposit lockup time, which is
    // configured at /deposit_accounts/$service_id/config/lockup_duration
  }
}
```

### Withdraw

```
{
  '/withdraw/{service_id}/{addr}/{withdraw_id}/value': _withdraw(value, context) {
    // Check the value at (/deposit_accounts/$service_id/$addr/value) >= value
    // Check (deposit_accounts/$service_id/$addr/expire_at) >= current time
    // Decrement the value of /deposit_accounts/$service_id/$addr by value
    // Increment the balance of addr by value
  }
}
```


---

# 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.ainetwork.ai/ain-blockchain/ai-network-design/blockchain-database/triggers/built-in-functions.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.
