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

# Precompile: Agent

## Address

`0x0A01700000000000000000000000000000000003`

The Agent precompile exposes the `x/agent` module, which lets a **master** account
authorize an **agent** account to sign transactions on its behalf. Authorizations are
per master/agent pair, carry an optional human-readable name, and always expire.

## Supported Methods

### Transactions

| Signature                           |
| ----------------------------------- |
| `approveAgent(bytes,string,uint64)` |
| `revokeAgent(address)`              |

### Queries

| Signature                       |
| ------------------------------- |
| `agent(address,address)`        |
| `isAuthorized(address,address)` |
| `agentsByMaster(address,tuple)` |
| `params()`                      |

### Events

| Signature                                                                                                             |
| --------------------------------------------------------------------------------------------------------------------- |
| `AgentApproved(address indexed master, address indexed agent, string name, uint256 expiresAt, address replacedAgent)` |
| `AgentRevoked(address indexed master, address indexed agent, string name)`                                            |

## Types

```solidity theme={null}
struct Agent {
    address masterAddress;
    address agentAddress;
    bytes   agentPubkey;
    string  name;
    uint256 expiresAt;
    uint256 createdAt;
}

struct AgentParams {
    uint32 maxAgentsPerAccount;
    uint64 defaultExpirySeconds;
    uint64 maxExpirySeconds;
}
```

## Query Examples

Set the current testnet EVM JSON-RPC endpoint and precompile address:

> Security note:
> Use a keystore or hardware wallet for real operations.
> Do not pass raw private keys directly in shell commands.

```bash theme={null}
export RPC_URL="https://test-json-rpc.cloud.aultblockchain.xyz"
export AGENT_PRECOMPILE="0x0A01700000000000000000000000000000000003"
```

### Direct call

```bash theme={null}
cast call "$AGENT_PRECOMPILE" \
  "isAuthorized(address,address)(bool)" \
  "$MASTER" \
  "$AGENT" \
  --rpc-url "$RPC_URL"
```

```bash theme={null}
cast call "$AGENT_PRECOMPILE" \
  "params()((uint32,uint64,uint64))" \
  --rpc-url "$RPC_URL"
```

### Call from contract

```solidity theme={null}
address constant AGENT = 0x0A01700000000000000000000000000000000003;

function isAgentAuthorized(
    address master,
    address agent
) external view returns (bool) {
    (bool ok, bytes memory out) = AGENT.staticcall(
        abi.encodeWithSignature("isAuthorized(address,address)", master, agent)
    );
    require(ok, "precompile call failed");
    return abi.decode(out, (bool));
}
```

## Transaction Examples

### Environment Variables

```bash theme={null}
cast wallet import ault-ops --interactive

export CAST_ACCOUNT="ault-ops"
export FROM="$(cast wallet address --account "$CAST_ACCOUNT")"

# 33-byte compressed secp256k1 public key of the agent key
export AGENT_PUBKEY="0x02<compressed-pubkey-hex>"
export AGENT_NAME="trading-bot"
# Absolute unix seconds; 0 uses the module default expiry
export EXPIRES_AT="0"
```

### Direct call

```bash theme={null}
cast send "$AGENT_PRECOMPILE" \
  "approveAgent(bytes,string,uint64)" \
  "$AGENT_PUBKEY" \
  "$AGENT_NAME" \
  "$EXPIRES_AT" \
  --rpc-url "$RPC_URL" \
  --account "$CAST_ACCOUNT"
```

```bash theme={null}
cast send "$AGENT_PRECOMPILE" \
  "revokeAgent(address)" \
  "$AGENT" \
  --rpc-url "$RPC_URL" \
  --account "$CAST_ACCOUNT"
```

### Call from contract

```solidity theme={null}
address constant AGENT = 0x0A01700000000000000000000000000000000003;

function txApproveAgent(
    bytes calldata agentPubkey,
    string calldata name,
    uint64 expiresAt
) external {
    (bool ok, ) = AGENT.call(
        abi.encodeWithSignature(
            "approveAgent(bytes,string,uint64)",
            agentPubkey,
            name,
            expiresAt
        )
    );
    require(ok, "precompile call failed");
}
```

## Notes

* The **caller is always the master**: `approveAgent` and `revokeAgent` derive the master
  account from `msg.sender`, so a contract calling the precompile authorizes agents for
  *itself*, not for the EOA that called the contract.
* `agentPubkey` must be the 33-byte compressed secp256k1 public key of the agent. The agent
  address is derived from it; you cannot register an agent by address alone.
* `expiresAt` is an **absolute** unix timestamp in seconds. Pass `0` to use
  `defaultExpirySeconds` from module params. It must not exceed `maxExpirySeconds`.
* Approving an unnamed agent may replace an existing unnamed agent. When that happens the
  replaced address is returned as `replacedAgentAddress` and reported in `AgentApproved`.
* `maxAgentsPerAccount` caps how many agents a single master may hold.
* `agentsByMaster` takes a `PageRequest` tuple and returns a `PageResponse` alongside the
  agent list.

## ABI

<a href="/assets/abi/agent_precompile_abi.json" download>
  Download Agent ABI JSON
</a>
