Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions eip155/caip10.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ eip155:137:0x0495766CD136138FC492DD499B8DC87A92D6685B
[CAIP-21]: https://github.com/ChainAgnostic/CAIPs/blob/master/CAIPs/caip-21.md
[CAIP-22]: https://github.com/ChainAgnostic/CAIPs/blob/master/CAIPs/caip-22.md
[EIP155]: https://eips.ethereum.org/EIPS/eip-155
[EIP55]: https://eips.ethereum.org/EIPS/eip-55
[ERC20]: https://eips.ethereum.org/EIPS/eip-20
[ERC721]: https://eips.ethereum.org/EIPS/eip-721

Expand Down
33 changes: 33 additions & 0 deletions starknet/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
---
namespace-identifier: starknet
title: StarkNet Ecosystem
author: Argent Labs
discussions-to:
status: Draft
type: Informational
created: 2022-12-04
updated: 2022-12-04
replaces: CAIP-28
---

# Namespace for StarkNet

## Introduction

This document describes the syntax and structure of the namespace for StarkNet.

## Syntax

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

[Cairo field elements][] are one of the more novel aspects of Cairo's [Type system][], although future interfaces may not require any special knowledge or handling of field elements. ([More on field elements][].)

## References

[Type system]: https://starknet.io/docs/reference/syntax.html#type-system
Comment thread
bumblefudge marked this conversation as resolved.
[Cairo field elements]: https://starknet.io/docs/how_cairo_works/cairo_intro.html#field-elements
[More on field elements]: https://medium.com/nethermind-eth/field-elements-all-the-way-down-59f02387d1d6

## Copyright

Copyright and related rights waived via [CC0](https://creativecommons.org/publicdomain/zero/1.0/).
62 changes: 62 additions & 0 deletions starknet/caip-10.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
---
namespace-identifier: starknet-caip10
title: StarkNet Namespace - Addresses
author: Argent Labs
discussions-to:
status: Draft
type: Standard
created: 2022-11-18
updated: 2022-11-18
requires: ["CAIP-2", "CAIP-10"]
supersedes: CAIP-5
---

# CAIP-10

*For context, see the [CAIP-10][] specification.*

## Rationale

The address of a StarkNet account is represented by an element of a field, whose maximum
value is slightly less than `2**256 - 1`. Because of this, 32-byte hex representations of
these addresses always have a leading zero.

## Syntax

Like on Ethereum, StarkNet addresses begin with `0x` followed by 64 hexadecimal characters
representing the zero-padded address number, totaling 66 characters.

It's recommended to checksum the address using capitalization according to
[EIP55][], as is common elsewhere on EVM systems.

## Test Cases

```
# StarkNet mainnet alpha (valid/checksummed)
starknet:SN_MAIN:0x02DdfB499765c064eaC5039E3841AA5f382E73B598097a40073BD8B48170Ab57

# StarkNet mainnet alpha (may not validate in checksum-conformant systems)
starknet:SN_MAIN:0x02ddfb499765c064eac5039e3841aa5f382e73b598097a40073bd8b48170ab57

# StarkNet goerli alpha
starknet:SN_GOERLI:0x02DdfB499765c064eaC5039E3841AA5f382E73B598097a40073BD8B48170Ab57
```


## References

- [addresses][]: Address format on StarkNet
- [Length of addresses][]: Decision fixing the length of addresses on StarkNet

[addresses]: https://starknet.io/docs/how_cairo_works/cairo_intro.html#field-elements
[Length of addresses]: https://github.com/starkware-libs/starknet-specs/pull/58
[CAIP-2]: https://github.com/ChainAgnostic/CAIPs/blob/master/CAIPs/caip-2.md
[CAIP-10]: https://github.com/ChainAgnostic/CAIPs/blob/master/CAIPs/caip-10.md
[CAIP-19]: https://github.com/ChainAgnostic/CAIPs/blob/master/CAIPs/caip-19.md
[CAIP-21]: https://github.com/ChainAgnostic/CAIPs/blob/master/CAIPs/caip-21.md
[CAIP-22]: https://github.com/ChainAgnostic/CAIPs/blob/master/CAIPs/caip-22.md
[EIP55]: https://eips.ethereum.org/EIPS/eip-55

## Rights

Copyright and related rights waived via CC0.
76 changes: 76 additions & 0 deletions starknet/caip-2.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
---
namespace-identifier: starknet-caip2
title: StarkNet Namespace - Chains
author: Argent Labs
discussions-to:
status: Draft
type: Standard
created: 2022-11-18
updated: 2022-11-18
requires: CAIP-2
supersedes: CAIP-5
---

# 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][Transaction structure]), 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:

```python
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.

[Transaction structure]: https://docs.starknet.io/documentation/develop/Blocks/transactions/#chain-id
[Making requests]: https://docs.infura.io/infura/networks/starknet/make-requests
[CAIP-2]: https://github.com/ChainAgnostic/CAIPs/blob/master/CAIPs/caip-2.md
[CAIP-10]: https://github.com/ChainAgnostic/CAIPs/blob/master/CAIPs/caip-10.md
[CAIP-19]: https://github.com/ChainAgnostic/CAIPs/blob/master/CAIPs/caip-19.md
[CAIP-21]: https://github.com/ChainAgnostic/CAIPs/blob/master/CAIPs/caip-21.md
[CAIP-22]: https://github.com/ChainAgnostic/CAIPs/blob/master/CAIPs/caip-22.md

## Rights

Copyright and related rights waived via CC0.