# ServerAvmSigner

> Facilitator-side signer (`FacilitatorAvmSigner`) backed by private keys and algod.

```python
from x402_algorand import ServerAvmSigner
```

```python
class ServerAvmSigner(
    private_keys: str | Sequence[str],
    algod_client: algod.AlgodClient | None = None,
    algod_url: str | None = None,
    algod_token: str | None = None,
)
```

Facilitator-side signer (`FacilitatorAvmSigner`) backed by private keys and algod.

Signs fee payer transactions, simulates groups, sends them, and waits for
confirmation. It also implements `ClientAvmSigner` (`address` /
`sign_transactions`), so one object can serve both roles in tests and demos.

algod selection:

- `algod_client` (or `algod_url`/`algod_token`) given: that node is used for
every call. The first call for a network checks that the node's genesis hash
matches it and raises `NetworkMismatchError` otherwise.
- nothing given: the algod URL configured for the network in `NETWORK_CONFIGS`
(MainNet / TestNet defaults, or a network added with `register_network`).

**Example**

```python
signer = ServerAvmSigner.from_mnemonic(
    os.environ["FACILITATOR_MNEMONIC"],
    algod_url="http://localhost:4001",
    algod_token="a" * 64,
)
register_exact_avm_facilitator(facilitator, signer, network)
```

## Constructor parameters

- `private_keys` (`str | Sequence[str]`, required):

- `algod_client` (`algod.AlgodClient | None`, default `None`):

- `algod_url` (`str | None`, default `None`):

- `algod_token` (`str | None`, default `None`):

## Methods

### `from_private_key`

```python
@classmethod
def from_private_key(
    private_key: str,
    algod_client: algod.AlgodClient | None = None,
    algod_url: str | None = None,
    algod_token: str | None = None,
) -> ServerAvmSigner
```

Create a signer from one base64 private key.

**Parameters**

- `private_key` (`str`, required):

- `algod_client` (`algod.AlgodClient | None`, default `None`):

- `algod_url` (`str | None`, default `None`):

- `algod_token` (`str | None`, default `None`):

### `from_mnemonic`

```python
@classmethod
def from_mnemonic(
    mnemonic_phrase: str,
    algod_client: algod.AlgodClient | None = None,
    algod_url: str | None = None,
    algod_token: str | None = None,
) -> ServerAvmSigner
```

Create a signer from a 25-word Algorand mnemonic.

**Parameters**

- `mnemonic_phrase` (`str`, required):

- `algod_client` (`algod.AlgodClient | None`, default `None`):

- `algod_url` (`str | None`, default `None`):

- `algod_token` (`str | None`, default `None`):

### `sign_transactions`

```python
def sign_transactions(
    unsigned_txns: list[bytes],
    indexes_to_sign: list[int],
) -> list[bytes | None]
```

Sign the transactions at `indexes_to_sign` with the key of each sender.

**Parameters**

- `unsigned_txns` (`list[bytes]`, required):

- `indexes_to_sign` (`list[int]`, required):

### `get_addresses`

```python
def get_addresses() -> list[str]
```

All managed fee payer addresses.

### `sign_transaction`

```python
def sign_transaction(txn_bytes: bytes, fee_payer: str, network: str) -> bytes
```

Sign one unsigned transaction with `fee_payer`'s key.

**Parameters**

- `txn_bytes` (`bytes`, required):

- `fee_payer` (`str`, required):

- `network` (`str`, required):

**Raises**

- `SigningError`: If `fee_payer` is not managed by this signer.

### `sign_group`

```python
def sign_group(
    group_bytes: list[bytes],
    fee_payer: str,
    indexes_to_sign: list[int],
    network: str,
) -> list[bytes]
```

Sign the transactions at `indexes_to_sign` with `fee_payer`'s key.

**Parameters**

- `group_bytes` (`list[bytes]`, required):

- `fee_payer` (`str`, required):

- `indexes_to_sign` (`list[int]`, required):

- `network` (`str`, required):

**Raises**

- `SigningError`: If `fee_payer` is not managed by this signer.

### `simulate_group`

```python
def simulate_group(group_bytes: list[bytes], network: str) -> None
```

Simulate the group with algod (unsigned transactions allowed).

**Parameters**

- `group_bytes` (`list[bytes]`, required):

- `network` (`str`, required):

**Raises**

- `SimulationError`: If algod reports the group would fail.
- `NetworkMismatchError`: If algod is on a different network.

### `send_group`

```python
def send_group(group_bytes: list[bytes], network: str) -> str
```

Submit a fully signed group; returns the ID of its first transaction.

**Parameters**

- `group_bytes` (`list[bytes]`, required):

- `network` (`str`, required):

### `confirm_transaction`

```python
def confirm_transaction(txid: str, network: str, rounds: int = 4) -> None
```

Wait up to `rounds` rounds for `txid` to be in a block.

**Parameters**

- `txid` (`str`, required):

- `network` (`str`, required):

- `rounds` (`int`, default `4`):

**Raises**

- `algosdk.error.ConfirmationTimeoutError`: If not confirmed in time.
- `algosdk.error.TransactionRejectedError`: If the pool rejected it.

### `algod_for`

```python
def algod_for(network: str) -> algod.AlgodClient
```

The algod client used for `network` (CAIP-2 or V1 name).

**Parameters**

- `network` (`str`, required):

**Raises**

- `NetworkError`: If no algod is configured for the network.
- `NetworkMismatchError`: If the configured algod is on another network.

Source: [x402_algorand/signer.py](https://github.com/x402-avm/x402-algorand/blob/main/x402_algorand/signer.py#L348)

Source: https://x402-avm.github.io/reference/python/x402-algorand/server-avm-signer
