> ## Documentation Index
> Fetch the complete documentation index at: https://solana.com/llms.txt
> Use this file to discover all available pages before exploring further.

> ## Agent Instructions
> This page is part of the Solana developer documentation at https://solana.com/developers/docs. Append `.md` to any docs URL, or send `Accept: text/markdown`, to get the page as Markdown.
> Index of all pages: https://solana.com/llms.txt. Per-section indexes such as https://solana.com/developers/docs/payments/llms.txt are smaller; prefer them when working on one task.
> Coding agents: install the official Solana skill for current APIs and conventions with `npx skills add https://github.com/solana-foundation/solana-dev-skill` (also served at https://solana.com/SKILL.md).
> Code in the cookbook and task pages comes from tested example files. Prefer it over writing API calls from memory.

# SVM-Funktionen

> Funktionen für Solana und SVM-kompatible Blockchains

Diese Funktionen stehen zur Verfügung, wenn das SVM-Addon für Solana und
SVM-kompatible Blockchains verwendet wird.

## system_program_id

`svm::system_program_id` gibt die ID des System Program zurück,
`11111111111111111111111111111111`.

```hcl
output "system_program_id" {
    value = svm::system_program_id()
}
// > 11111111111111111111111111111111
```

---

## default_pubkey

`svm::default_pubkey` gibt einen standardmäßigen öffentlichen Schlüssel zurück,
`11111111111111111111111111111111`.

```hcl
output "default_pubkey" {
    value = svm::default_pubkey()
}
// > 11111111111111111111111111111111
```

---

## get_instruction_data_from_idl_path

`svm::get_instruction_data_from_idl_path` erstellt kodierte instruction data für
einen Programmaufruf und bietet Typprüfung und Serialisierung auf Grundlage der
angegebenen IDL-Datei.

### Eingaben

| Name               | Erforderlich | Typ          | Beschreibung                                                 |
| ------------------ | -------- | ------------- | ----------------------------------------------------------- |
| `idl_path`         | erforderlich | string        | Der Pfad zur IDL-Datei (`.json`), relativ zur txtx.yml |
| `instruction_name` | erforderlich | string        | Der Name der Anweisung, für die Daten erzeugt werden sollen            |
| `arguments`        | optional | array[string] | Die Argumente der Anweisung, für die Daten erzeugt werden sollen              |

```hcl
output "data" {
    value = svm::get_instruction_data_from_idl_path("idl.json", "my_instruction", ["arg1", "arg2"])
}
// > data: 0xc3f1b80e7f9b443504000000617267310400000061726732
```

Bei einer Anchor-IDL besteht die Ausgabe aus dem 8-Byte-Discriminator der Anweisung (hier
`c3f1b80e7f9b4435`, die ersten 8 Bytes von `sha256("global:my_instruction")`),
gefolgt von den Borsh-kodierten Argumenten: Jeder String besteht aus einer 4-Byte-Länge im Little-Endian-Format
und seinen UTF-8-Bytes.

---

## get_instruction_data_from_idl

`svm::get_instruction_data_from_idl` erstellt kodierte instruction data für
einen Programmaufruf und bietet Typprüfung und Serialisierung auf Grundlage der
angegebenen IDL-Daten.

### Eingaben

| Name               | Erforderlich | Typ              | Beschreibung                                                             |
| ------------------ | -------- | ----------------- | ----------------------------------------------------------------------- |
| `idl`              | erforderlich | string \| SVM_IDL | Die IDL des Programms                                                         |
| `instruction_name` | erforderlich | string            | Der Name der Anweisung, für die Daten erzeugt werden sollen, wie in der IDL indiziert |
| `arguments`        | optional | array[string]     | Die Argumente der Anweisung, für die Daten erzeugt werden sollen                          |

```hcl
output "data" {
    value = svm::get_instruction_data_from_idl(variable.contract.idl, "my_instruction", ["arg1", "arg2"])
}
// > data: 0xc3f1b80e7f9b443504000000617267310400000061726732
```

---

## get_program_from_anchor_project

`svm::get_program_from_anchor_project` ruft die Deployment-Artefakte eines
Programms in einem Anchor-Projekt ab.

### Eingaben

| Name           | Erforderlich | Typ   | Beschreibung                              |
| -------------- | -------- | ------ | ---------------------------------------- |
| `program_name` | erforderlich | string | Der Name des Programms, für das das Deployment erfolgt   |
| `keypair_path` | optional | string | Der Speicherort der keypair-Datei des Programms |
| `idl_path`     | optional | string | Der Speicherort der IDL-Datei des Programms     |
| `bin_path`     | optional | string | Der Speicherort der Binärdatei des Programms  |

```hcl
variable "contract" {
    value = svm::get_program_from_anchor_project("my_program")
}
output "idl" {
    value = variable.contract.idl
}
```

---

## get_program_from_native_project

`svm::get_program_from_native_project` ruft die Deployment-Artefakte eines
Programms ab, das nicht auf Anchor basiert.

### Eingaben

| Name           | Erforderlich | Typ   | Beschreibung                              |
| -------------- | -------- | ------ | ---------------------------------------- |
| `program_name` | erforderlich | string | Der Name des Programms, für das das Deployment erfolgt   |
| `keypair_path` | optional | string | Der Speicherort der keypair-Datei des Programms |
| `idl_path`     | optional | string | Der Speicherort der IDL-Datei des Programms     |
| `bin_path`     | optional | string | Der Speicherort der Binärdatei des Programms  |

```hcl
variable "contract" {
    value = svm::get_program_from_native_project("my_program")
}
output "idl" {
    value = variable.contract.idl
}
```

---

## sol_to_lamports

`svm::sol_to_lamports` wandelt den angegebenen SOL-Betrag in lamports um.

```hcl
output "lamports" {
    value = svm::sol_to_lamports(1.1)
}
// lamports: 1100000000
```

---

## lamports_to_sol

`svm::lamports_to_sol` wandelt die angegebene Anzahl von lamports in SOL um.

```hcl
output "sol" {
    value = svm::lamports_to_sol(1100000000)
}
// sol: 1.1
```

---

## find_pda

`svm::find_pda` findet eine gültige PDA anhand der angegebenen Programm-ID und der seeds.

### Eingaben

| Name         | Erforderlich | Typ          | Beschreibung                                        |
| ------------ | -------- | ------------- | -------------------------------------------------- |
| `program_id` | erforderlich | string        | Die Adresse des Programms, von dem die PDA abgeleitet wird |
| `seeds`      | optional | array[string] | Ein optionales Array von seeds (max. 16, jeweils 32 Bytes) |

```hcl
variable "pda" {
    value = svm::find_pda("3bv3j4GvMPjvvBX9QdoX27pVoWhDSXpwKZipFF1QiVr6", ["data"])
}
output "pda" {
    value = variable.pda.pda
}
output "bump" {
    value = variable.pda.bump_seed
}
// > pda: AAU8CSawL7uBQLt4QHdTtwsNuRQthNtYzhMVNx2bwuGC
// > bump: 254
```

---

## get_associated_token_account

`svm::get_associated_token_account` berechnet die Adresse des associated token
account für die angegebene Wallet-Adresse und die Adresse des Token-Mints.

### Eingaben

| Name                 | Erforderlich | Typ   | Beschreibung                   |
| -------------------- | -------- | ------ | ----------------------------- |
| `wallet_address`     | erforderlich | string | Die Adresse des Wallets     |
| `token_mint_address` | optional | string | Die Adresse des Token-Mints |

```hcl
variable "token_account" {
    value = svm::get_associated_token_account(signer.caller.address, "So11111111111111111111111111111111111111112")
}
```

---

## create_token_account_instruction

`svm::create_token_account_instruction` erstellt rohe Anweisungs-Bytes zum Erstellen
eines associated token account.

### Eingaben

| Name                 | Erforderlich | Typ   | Beschreibung                        |
| -------------------- | -------- | ------ | ---------------------------------- |
| `funding_address`    | erforderlich | string | Die Adresse der Funding-Konten |
| `wallet_address`     | erforderlich | string | Die Adresse des Wallets          |
| `token_mint_address` | optional | string | Die Adresse des Token-Mints      |
| `token_program_id`   | optional | string | Die Adresse des Token Program   |

```hcl
action "call" "svm::process_instructions" {
    signers = [signer.caller]

    instruction {
        raw_bytes = svm::create_token_account_instruction(
            signer.caller.address, // funding address
            signer.caller.address, // wallet address
            variable.token_mint, // token mint address
            variable.token_program // token program id
        )
    }
}
```

---

## u64

`svm::u64` erstellt eine Byte-Array-Darstellung einer u64-Ganzzahl, die sich als
seed für die PDA-Ableitung eignet.

### Eingaben

| Name    | Erforderlich | Typ    | Beschreibung                                |
| ------- | -------- | ------- | ------------------------------------------ |
| `value` | erforderlich | integer | Die u64-Ganzzahl, die in ein Byte-Array umgewandelt werden soll |

```hcl
variable "pda" {
    value = svm::find_pda("3bv3j4GvMPjvvBX9QdoX27pVoWhDSXpwKZipFF1QiVr6", [svm::u64(1000000000)])
}
```

---

## i64

`svm::i64` erstellt eine Byte-Array-Darstellung einer i64-Ganzzahl, die sich als
seed für die PDA-Ableitung eignet.

### Eingaben

| Name    | Erforderlich | Typ    | Beschreibung                                |
| ------- | -------- | ------- | ------------------------------------------ |
| `value` | erforderlich | integer | Die i64-Ganzzahl, die in ein Byte-Array umgewandelt werden soll |

```hcl
variable "pda" {
    value = svm::find_pda("3bv3j4GvMPjvvBX9QdoX27pVoWhDSXpwKZipFF1QiVr6", [svm::i64(-1000000000)])
}
```
