> ## 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.

# Fonctions SVM

> Fonctions pour Solana et les blockchains compatibles SVM

Ces fonctions sont disponibles lorsque vous utilisez l'addon SVM pour Solana et
les blockchains compatibles SVM.

## system_program_id

`svm::system_program_id` renvoie l'identifiant du System Program,
`11111111111111111111111111111111`.

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

---

## default_pubkey

`svm::default_pubkey` renvoie une clé publique par défaut,
`11111111111111111111111111111111`.

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

---

## get_instruction_data_from_idl_path

`svm::get_instruction_data_from_idl_path` crée des instruction data encodées pour
l'invocation d'un programme, avec vérification des types et sérialisation basées sur
le fichier IDL fourni.

### Entrées

| Nom               | Requis | Type          | Description                                                 |
| ------------------ | -------- | ------------- | ----------------------------------------------------------- |
| `idl_path`         | requis | string        | Le chemin, relatif à txtx.yml, vers le fichier IDL `.json` |
| `instruction_name` | requis | string        | Le nom de l'instruction pour laquelle générer les données            |
| `arguments`        | facultatif | array[string] | Les arguments de l'instruction pour lesquels générer les données              |

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

Pour un IDL Anchor, les données sont constituées du discriminateur de 8 octets de l'instruction (ici
`c3f1b80e7f9b4435`, les 8 premiers octets de `sha256("global:my_instruction")`)
suivi des arguments encodés en Borsh : chaque chaîne de caractères est précédée d'une longueur de 4 octets en little-endian
et suivie de ses octets UTF-8.

---

## get_instruction_data_from_idl

`svm::get_instruction_data_from_idl` crée des instruction data encodées pour
l'invocation d'un programme, avec vérification des types et sérialisation basées sur
les données IDL fournies.

### Entrées

| Nom               | Requis | Type              | Description                                                             |
| ------------------ | -------- | ----------------- | ----------------------------------------------------------------------- |
| `idl`              | requis | string \| SVM_IDL | L'IDL du programme                                                         |
| `instruction_name` | requis | string            | Le nom de l'instruction pour laquelle générer les données, tel qu'indexé par l'IDL |
| `arguments`        | facultatif | array[string]     | Les arguments de l'instruction pour lesquels générer les données                          |

```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` récupère les artefacts de déploiement
d'un programme dans un projet Anchor.

### Entrées

| Nom           | Requis | Type   | Description                              |
| -------------- | -------- | ------ | ---------------------------------------- |
| `program_name` | requis | string | Le nom du programme à déployer   |
| `keypair_path` | facultatif | string | L'emplacement du fichier keypair du programme |
| `idl_path`     | facultatif | string | L'emplacement du fichier IDL du programme     |
| `bin_path`     | facultatif | string | L'emplacement du fichier binaire du programme  |

```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` récupère les artefacts de déploiement
d'un programme non-Anchor.

### Entrées

| Nom           | Requis | Type   | Description                              |
| -------------- | -------- | ------ | ---------------------------------------- |
| `program_name` | requis | string | Le nom du programme à déployer   |
| `keypair_path` | facultatif | string | L'emplacement du fichier keypair du programme |
| `idl_path`     | facultatif | string | L'emplacement du fichier IDL du programme     |
| `bin_path`     | facultatif | string | L'emplacement du fichier binaire du programme  |

```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` convertit le montant de SOL fourni en lamports.

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

---

## lamports_to_sol

`svm::lamports_to_sol` convertit le nombre de lamports fourni en SOL.

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

---

## find_pda

`svm::find_pda` trouve une PDA valide à partir de l'identifiant de programme et des seeds fournis.

### Entrées

| Nom         | Requis | Type          | Description                                        |
| ------------ | -------- | ------------- | -------------------------------------------------- |
| `program_id` | requis | string        | L'adresse du programme dont la PDA est dérivée |
| `seeds`      | facultatif | array[string] | Un tableau facultatif de seeds (16 maximum, 32 octets chacun) |

```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` calcule l'adresse de l'associated token
account correspondant aux adresses du portefeuille et du mint du token fournies.

### Entrées

| Nom                 | Requis | Type   | Description                   |
| -------------------- | -------- | ------ | ----------------------------- |
| `wallet_address`     | requis | string | L'adresse du portefeuille     |
| `token_mint_address` | facultatif | string | L'adresse du mint du token |

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

---

## create_token_account_instruction

`svm::create_token_account_instruction` crée les octets bruts d'une instruction pour créer
un associated token account.

### Entrées

| Nom                 | Requis | Type   | Description                        |
| -------------------- | -------- | ------ | ---------------------------------- |
| `funding_address`    | requis | string | L'adresse du compte de financement |
| `wallet_address`     | requis | string | L'adresse du portefeuille          |
| `token_mint_address` | facultatif | string | L'adresse du mint du token      |
| `token_program_id`   | facultatif | string | L'adresse du 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` crée une représentation sous forme de tableau d'octets d'un entier u64, adaptée
à une utilisation comme seed dans la dérivation de PDA.

### Entrées

| Nom    | Requis | Type    | Description                                |
| ------- | -------- | ------- | ------------------------------------------ |
| `value` | requis | integer | L'entier u64 à convertir en tableau d'octets |

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

---

## i64

`svm::i64` crée une représentation sous forme de tableau d'octets d'un entier i64, adaptée
à une utilisation comme seed dans la dérivation de PDA.

### Entrées

| Nom    | Requis | Type    | Description                                |
| ------- | -------- | ------- | ------------------------------------------ |
| `value` | requis | integer | L'entier i64 à convertir en tableau d'octets |

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