checkcheck_has_key

Check if an address has a registered viewing key

Check whether an address has a registered viewing key in the Directory contract.

Overview

check_has_key() and async_check_has_key() query the Directory contract to check if a specific address has registered a viewing key. This is a public, read-only operation that requires no authentication.

Also documented here: get_key_hash() and async_get_key_hash() retrieve the keccak256 hash of an address's viewing key.

Signatures

def check_has_key(
    w3: Web3,
    address: ChecksumAddress,
) -> bool

async def async_check_has_key(
    w3: AsyncWeb3,
    address: ChecksumAddress,
) -> bool

def get_key_hash(
    w3: Web3,
    address: ChecksumAddress,
) -> bytes

async def async_get_key_hash(
    w3: AsyncWeb3,
    address: ChecksumAddress,
) -> bytes

Parameters

Parameter
Type
Required
Description

w3

Web3 or AsyncWeb3

Yes

Standard Web3 instance (no Seismic namespace required)

address

ChecksumAddress

Yes

Ethereum address to check

Returns

check_has_key / async_check_has_key

Type
Description

bool

True if the address has a registered key, False otherwise

get_key_hash / async_get_key_hash

Type
Description

bytes

32-byte keccak256 hash of the viewing key

Examples

Check Has Key (Sync)

Check Before Registering

Get Key Hash (Sync)

Compare Key Hash

Async Usage

Batch Check Multiple Addresses

Monitor Registration

Validate Before Event Watching

Get Key Hash for Event Filtering

How It Works

check_has_key

  1. Encode calldata - Encodes checkHasKey(address) with the target address

  2. Call contract - Makes a plain eth_call to Directory at 0x1000...0004

  3. Decode result - Decodes the boolean result from ABI

get_key_hash

  1. Encode calldata - Encodes keyHash(address) with the target address

  2. Call contract - Makes a plain eth_call to Directory at 0x1000...0004

  3. Decode result - Decodes the 32-byte hash from ABI

Notes

  • Both functions are read-only (no gas costs)

  • No authentication required (publicly accessible)

  • Works with standard Web3 instances (no Seismic namespace needed)

  • The key hash is keccak256(viewing_key)

  • Used as the 4th topic in SRC20 Transfer and Approval events

  • The hash allows event filtering without exposing the key

Use Cases

check_has_key

  • Verify an address has registered a viewing key before attempting to fetch it

  • Check if registration is complete after sending registration transaction

  • Validate addresses in batch operations

  • Monitor for new registrations

get_key_hash

  • Manual event filtering with eth_getLogs

  • Compare on-chain key with locally stored key (via hash)

  • Verify event watcher is filtering for the correct key

  • Debug event watching issues

Warnings

  • Public information - Anyone can check if an address has a key

  • No key retrieval - These functions do not return the viewing key itself

  • Hash only - get_key_hash returns the hash, not the key

  • Zero hash - If no key is registered, get_key_hash returns 32 zero bytes

See Also

Last updated