StarkNet Namespace - Chains

Author Argent Labs
Status Draft
Type Standard
Created 2022-11-18
Updated 2022-11-18
Requires CAIP-2

CAIP-2

For context, see the CAIP-2 specification.

Rationale / Syntax

The namespace starknet refers to the StarkNet Layer 2 on Ethereum.

StarkNet currently represents its chains with string identifiers such as SN_MAIN and SN_GOERLI. Internally, these strings are encoded as field elements (according to a transformation documented in the system’s core documentation), but using the case-sensitive root string identifiers simplifies interoperability by sidestepping type system interoperability around integers.

Resolution Method

To resolve a reference for the StarkNet namespace, make a JSON-RPC request to a StarkNet Pathfinder node with method starknet_chainId, for example:

import requests

response = requests.post(
  url=f"https://starknet-goerli.infura.io/v3/{API_KEY}",
  json={"jsonrpc": "2.0", "method": "starknet_chainId", "params": [], "id": 1},
)

hex_chain_id = response.json()["result"]              # "0x534e5f474f45524c49"
chain_id = bytes.fromhex(hex_chain_id[2:]).decode()   # "SN_GOERLI"

The response will return a base-16-encoded field element that should be converted to a string to express a StarkNet-compatible reference.

Test Cases

This is a list of manually composed examples:

# StarkNet mainnet alpha
starknet:SN_MAIN

# StarkNet goerli alpha
starknet:SN_GOERLI

References

  • Transaction structure: StarkNet’s documentation on chainIDs used in transaction.
  • Making requests: Infura’s documentation on how to call their Ethereum-style RPC endpoints for StarkNet.

Rights

Copyright and related rights waived via CC0.

Citation

Please cite this document as:

Argent Labs, "namespaces/starknet-caip2: StarkNet Namespace - Chains [DRAFT]," Chain Agnostic Namespaces, starknet-caip2, November 2022 / November 2022. [Online serial]. Available: https://github.com/ChainAgnostic/namespaces/starknet-caip2.md