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—0x8004a169fb4a3325136eb29fa0ceb6d2e539a432bsctestnet—0x8004a818bfb912233c491871b3d84c89a494bd9e(chain ID 97; not listed bytwak 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→ byte0x01(a0Xprefix is accepted and canonicalized to0x) - a
0x-prefixed string that is not valid even-length hex fails withVALIDATION_ERROR— it is never silently UTF-8 encoded; drop the0xprefix 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://…oripfs://…— a hosted URIdata: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 addressagentURI— the stored token URI (echoes--uri)metadata— present only when--metadatawas passed; an object{ key: "0x<hexValue>" }per entry (e.g.{ "client": "0x7477616b", "version": "0x01" })hash— mint transaction hashexplorer— 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://, ordata:inline (required)--metadata <key=value>— Metadata entry to set atomically with the mint; repeatable. Value is0x-hex bytes or a UTF-8 string--chain <key>— EVM chain key (defaultbsc;bsctestnetsupported; other EVM chains needERC8004_REGISTRY_ADDRESS)--password <pw>— Wallet password (resolved from OS keychain /TWAK_WALLET_PASSWORDif omitted)--json— Output as JSON
erc8004 set-uri <agentId>
--uri <url>— New agent URI:https://,ipfs://, ordata:inline (required)--chain <key>— EVM chain key (defaultbsc)--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 (defaultbsc)--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 (defaultbsc)--json— Output as JSON
erc8004 show <agentId>
--chain <key>— EVM chain key (defaultbsc)--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--metadatapair is notkey=value; a0x-prefixed value is not valid even-length hexCHAIN_UNSUPPORTED— unrecognized--chainkey (Unknown chain: "…"); non-EVM chain; or EVM chain with no known deployment and noERC8004_REGISTRY_ADDRESSoverrideTX_FAILED—registertransaction confirmed but emitted noRegisteredevent; 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