2026-06-17 01:32:06 +03:00

6.3 KiB

ERC-8004 Identity Registry

On-chain registry of AI-agent identities on EVM chains. Registering mints an NFT whose token ID is the agentId; the caller becomes the owner. Each identity carries an agentURI (points to the agent's registration JSON) plus optional free-form on-chain metadata key/value entries.

Known deployments

erc8004 commands default to --chain bsc. Known registry deployments:

  • bsc — 0x8004a169fb4a3325136eb29fa0ceb6d2e539a432
  • bsctestnet — 0x8004a818bfb912233c491871b3d84c89a494bd9e (chain ID 97; not listed by twak chains)

For any other EVM chain that twak already knows (listed by twak chains), set ERC8004_REGISTRY_ADDRESS=0x… to target a custom deployment. The override does not add new chains — an unrecognized --chain key fails with CHAIN_UNSUPPORTED (Unknown chain: "…") before the override is read. ERC-8004 is EVM-only: a non-EVM chain, or an EVM chain with no known deployment and no env override, also fails with CHAIN_UNSUPPORTED.

Metadata value encoding

Every metadata value (register --metadata, set-metadata --value) is encoded by the same rule:

  • a valid 0x-prefixed even-length hex string is sent as raw bytes — 0x01 → byte 0x01 (a 0X prefix is accepted and canonicalized to 0x)
  • a 0x-prefixed string that is not valid even-length hex fails with VALIDATION_ERROR — it is never silently UTF-8 encoded; drop the 0x prefix to send it as a string
  • any other string is UTF-8 encoded — twak → 0x7477616b

Reads (get-metadata) return the raw on-chain bytes as a 0x-hex string; an unset key returns 0x.

Prerequisites

  • Authenticated (twak auth status)
  • Agent wallet created (twak wallet create --password <pw>) — the owner is your stored wallet address on the target chain

Writes (register, set-uri, set-metadata) need the wallet; reads (get-metadata, show) do not.

Register an Identity

twak erc8004 register --uri <agentURI> --json

Mints a new identity; you become the owner. --uri is stored on-chain as the token URI and should point to the agent registration JSON. It accepts:

  • https://… or ipfs://… — a hosted URI
  • data:application/json;base64,… — the agent card inlined directly on-chain (no external hosting)

Atomic register + metadata

Pass --metadata key=value (repeatable) to write metadata entries in the same transaction as the mint:

twak erc8004 register \
  --uri data:application/json;base64,eyJuYW1lIjoibXktYWdlbnQiLCJkZXNjcmlwdGlvbiI6Im15IEFJIGFnZW50IiwidmVyc2lvbiI6IjEifQ== \
  --metadata client=twak \
  --metadata version=0x01 \
  --json

Success output: { agentId, owner, agentURI, metadata?, hash, chain, explorer }

  • agentId — the minted NFT token ID (decimal string)
  • owner — your wallet address
  • agentURI — the stored token URI (echoes --uri)
  • metadata — present only when --metadata was passed; an object { key: "0x<hexValue>" } per entry (e.g. { "client": "0x7477616b", "version": "0x01" })
  • hash — mint transaction hash
  • explorer — block-explorer URL

Update the agentURI

twak erc8004 set-uri <agentId> --uri <newURI> --json

Replaces the stored token URI (caller must own the NFT). --uri accepts the same https:// / ipfs:// / data: forms as register.

Output: { agentId, agentURI, hash, chain, explorer }

Set a Metadata Entry

twak erc8004 set-metadata <agentId> --key <key> --value <hex|string> --json

Sets one metadata entry. --value follows the encoding rule above. Pass --value 0x to clear an entry.

Output: { agentId, key, value, hash, chain, explorer } — value is the 0x-hex bytes actually written.

Read a Metadata Entry

twak erc8004 get-metadata <agentId> --key <key> --json

Output: { agentId, key, value, chain } — value is the raw on-chain bytes as a 0x-hex string; an unset key returns 0x.

Show an Identity

twak erc8004 show <agentId> --json

Output: { agentId, owner, agentWallet, agentURI, chain } — agentWallet is null when unset (zero address).

Options

erc8004 register

  • --uri <url> — Agent registration URI: https://, ipfs://, or data: inline (required)
  • --metadata <key=value> — Metadata entry to set atomically with the mint; repeatable. Value is 0x-hex bytes or a UTF-8 string
  • --chain <key> — EVM chain key (default bsc; bsctestnet supported; other EVM chains need ERC8004_REGISTRY_ADDRESS)
  • --password <pw> — Wallet password (resolved from OS keychain / TWAK_WALLET_PASSWORD if omitted)
  • --json — Output as JSON

erc8004 set-uri <agentId>

  • --uri <url> — New agent URI: https://, ipfs://, or data: inline (required)
  • --chain <key> — EVM chain key (default bsc)
  • --password <pw> — Wallet password (resolved from OS keychain if omitted)
  • --json — Output as JSON

erc8004 set-metadata <agentId>

  • --key <string> — Metadata key (required)
  • --value <hex|string> — 0x-hex bytes or plain string, UTF-8 encoded (required)
  • --chain <key> — EVM chain key (default bsc)
  • --password <pw> — Wallet password (resolved from OS keychain if omitted)
  • --json — Output as JSON

erc8004 get-metadata <agentId>

  • --key <string> — Metadata key (required)
  • --chain <key> — EVM chain key (default bsc)
  • --json — Output as JSON

erc8004 show <agentId>

  • --chain <key> — EVM chain key (default bsc)
  • --json — Output as JSON

Errors

With --json, failures print { error, errorCode } to stdout and exit with code 1.

  • VALIDATION_ERROR — <agentId> is not a decimal integer string (checked before any network call); a --metadata pair is not key=value; a 0x-prefixed value is not valid even-length hex
  • CHAIN_UNSUPPORTED — unrecognized --chain key (Unknown chain: "…"); non-EVM chain; or EVM chain with no known deployment and no ERC8004_REGISTRY_ADDRESS override
  • TX_FAILED — register transaction confirmed but emitted no Registered event; the message includes the tx hash

BSC Testnet

Pass --chain bsctestnet to operate against the BSC testnet deployment (0x8004a818bfb912233c491871b3d84c89a494bd9e, chain ID 97). The testnet key is not listed by twak chains.

twak erc8004 register --chain bsctestnet --uri ipfs://Qm… --json