x402 icon indicating copy to clipboard operation
x402 copied to clipboard

`network` property should accept chain ids instead of arbitrary strings

Open gskril opened this issue 6 months ago • 6 comments

Chain IDs are a well-established standard for referencing a specific EVM network. Using arbitrary strings like "base-sepolia" and "avalanche-fuji" makes for a frustrating developer experience (people agree), and makes it feel like x402 is a closed system where new chains have to get approved by Coinbase.

This file should not need to exist, but instead network should just be of type number (or bigint, i always forget the correct way to represent them but you get the point) https://github.com/coinbase/x402/blob/main/typescript/packages/x402/src/types/shared/network.ts

The error invalid_network already exists, which servers/facilitators can throw in the case that a given chain id isn't supported.

gskril avatar Jun 29 '25 06:06 gskril

Adding on to this, we may want to use something like CAIP-2 as we add support for non-evm chains.

And for assets, perhaps CAIP-2 + CAIP-19

notorious-d-e-v avatar Jul 14 '25 13:07 notorious-d-e-v

@notorious-d-e-v @gskril There was some discussion previously, see https://github.com/coinbase/x402/issues/137#issuecomment-2867663321

ukstv avatar Jul 14 '25 14:07 ukstv

@notorious-d-e-v @gskril There was some discussion previously, see https://github.com/coinbase/x402/issues/137#issuecomment-2867663321

Nice thanks!

notorious-d-e-v avatar Jul 15 '25 04:07 notorious-d-e-v

seconding this. was gonna open an issue asking for the same thing.

understand that chain ids can look evm centric, but we really need a way to define a chain (and asset) generically instead of hardcoding a set of constants.

a simple non-breaking change would be to accept integers for the network property as well as string.

integer = chain id = no mapping required string = network slug = requires mapping to id

wdyt @erikreppel-cb ?

joaquim-verges avatar Sep 19 '25 02:09 joaquim-verges

Not Erik, but seems like it just adds complexity. We should choose one way and stick with it.

notorious-d-e-v avatar Sep 19 '25 06:09 notorious-d-e-v

Note, that this is currently a blocker outside of just facilitator support. Even if a facilitator supports a custom network; the issue is actually created within the x402 based shared package on the network check.

Proposed Solution: allow the network support to be handled by the server & facilitator and remove from the client. Confirming that this does work with Faremeter's implementation as well both with string names (base-sepolia) and with CAIP-2

https://github.com/coinbase/x402/blob/2daa42f6a0e5a36c1bb19677fda2a74a6b466b06/typescript/packages/x402/src/shared/network.ts#L17

TheGreatAxios avatar Oct 28 '25 00:10 TheGreatAxios