argentlabs / argent-x

ArgentX browser extension for StarkNet - made with ❤️ by Argent
https://github.com/argentlabs/argent-x
Other
626 stars 273 forks source link

Account Class Hash in wallet_addStarknetChain #2132

Open rsodre opened 6 months ago

rsodre commented 6 months ago

Hello,

I'm adding a custom network (local and L3) to ArgentX from my dapp using wallet_addStarknetChain. There is no specification for account class hash in AddStarknetChainParameters, but it is important to specify it.

Trying to pass accountClassHash or classHash does not have any effect (just being hopeful...):

const params = {
  "id": "LOCAL_KATANA",
  "chainId": "LOCAL_KATANA",
  "chainName": "Katana Local",
  "baseUrl": "http://localhost:5050",
  "rpcUrl": "http://localhost:5050",
  "rpcUrls": ["http://localhost:5050"],
  "nativeCurrency": {
    "address": "0x049d36570d4e46f48e99674bd3fcc84644ddd6b96f7c741b1562b82f9e004dc7",
    "name": "Ether",
    "symbol": "ETH",
    "decimals": 18
  },
  "accountClassHash": "0x029927c8af6bccf3f6fda035981e765a7bdbf18a2dc0d630494f8758aa908e2b",
  "classHash": "0x029927c8af6bccf3f6fda035981e765a7bdbf18a2dc0d630494f8758aa908e2b"
}
window?.starknet?.request({ type: 'wallet_addStarknetChain', params })

Looking at ArgentX source code, it looks like you should accept the class hash in accountImplementation, but it results a strangeZodError. But something is happening! Only bugged, it seems

https://github.com/argentlabs/argent-x/blob/main/packages/extension/src/inpage/requestMessageHandlers/addStarknetChain.ts#L6-L22

const params = {
  "id": "LOCAL_KATANA",
  "chainId": "LOCAL_KATANA",
  "chainName": "Katana Local",
  "baseUrl": "http://localhost:5050",
  "rpcUrl": "http://localhost:5050",
  "rpcUrls": ["http://localhost:5050"],
  "nativeCurrency": {
    "address": "0x049d36570d4e46f48e99674bd3fcc84644ddd6b96f7c741b1562b82f9e004dc7",
    "name": "Ether",
    "symbol": "ETH",
    "decimals": 18
  },
  "accountImplementation": "0x029927c8af6bccf3f6fda035981e765a7bdbf18a2dc0d630494f8758aa908e2b"
}
window?.starknet?.request({ type: 'wallet_addStarknetChain', params })

the error...

[
  {
    "code": "invalid_union",
    "unionErrors": [
      {
        "issues": [
          {
            "code": "invalid_type",
            "expected": "object",
            "received": "string",
            "path": [
              "accountClassHash"
            ],
            "message": "Expected object, received string"
          }
        ],
        "name": "ZodError"
      },
      {
        "issues": [
          {
            "code": "invalid_type",
            "expected": "undefined",
            "received": "string",
            "path": [
              "accountClassHash"
            ],
            "message": "Expected undefined, received string"
          }
        ],
        "name": "ZodError"
      }
    ],
    "path": [
      "accountClassHash"
    ],
    "message": "Invalid input"
  }
]