Skip to content

Conversation

tdelabro
Copy link
Collaborator

@tdelabro tdelabro commented Oct 6, 2025

Add the type ChainId

What is the new behavior?

The ChainId type allows for representing the two starknet chains, SN_MAIN and SN_SEPOLIA.
It offers type conversion from and into Felt, ShortString, String.

A new Rust feature devnet allows adding a custom local devnet with any valid ShortString as name (eg. SN_DEVNET).

Also, add a new short_string! macro, for compile-time creation of ShortStrings

Does this introduce a breaking change?

Yes. Replace TryFrom<&str> for ShortString by FromStr for ShortString.
More idiomatic

@tdelabro tdelabro added the enhancement New feature or request label Oct 6, 2025
@tdelabro tdelabro force-pushed the feat-chain-id branch 2 times, most recently from 4133d80 to 037d445 Compare October 6, 2025 23:07
Comment on lines 25 to 31
if value.as_ref() == SN_MAIN_STR {
ChainId::Mainnet
} else if value.as_ref() == SN_SEPOLIA_STR {
ChainId::Sepolia
} else {
ChainId::Devnet(value)
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if value.as_ref() == SN_MAIN_STR {
ChainId::Mainnet
} else if value.as_ref() == SN_SEPOLIA_STR {
ChainId::Sepolia
} else {
ChainId::Devnet(value)
}
match value.as_ref() {
SN_MAIN_STR => ChainId::Mainnet,
SN_SEPOLIA_STR => ChainId::Sepolia,
_ => ChainId::Devnet(value),
}

Also, why does conversion from ChainId to ShortString is possible but not the other way around if feature devnet is disabled?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It becomes failable when no feature devnet, so we implement TryFrom instead.
See below:
impl TryFrom<ShortString> for ChainId

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So this means that without the devnet feature we only can convert a ShortString to ChainId with try_into and not with into? Even if the ShortString may be SN_MAIN_STR or SN_SEPOLIA_STR

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants