starknet-io / get-starknet

StarkNet wallet <-> dApp bridge
MIT License
155 stars 110 forks source link

Provider type problem #170

Closed PhilippeR26 closed 3 months ago

PhilippeR26 commented 1 year ago

Hello, I found a problem about provider. User is expecting a provider of type ProviderInterface (imported from starknet.js) :

StarknetWindowObject.ts :

export interface ConnectedStarknetWindowObject extends IStarknetWindowObject {
  isConnected: true
  account: AccountInterface
  provider: ProviderInterface
  selectedAddress: string
  chainId: string
}

But in the window object, in starknet_argentX or in starknet-braavos, provider are not the same and are not with ProviderInterface type. In starknet_braavos, the provider is a SequencerProvider (imported from starknet.js). In starknet_argentX, the provider is a specific l type. Capture d’écran du 2023-01-23 09-40-45

On user side, if you use this command : const starknet = await connect({ modalMode: "alwaysAsk", modalTheme: "dark" }); , starknet.provider is not a ProviderInterface, it's the type of the window.starknet_* object : Capture d’écran du 2023-01-23 10-37-50 Fortunately, starknet.js succeeds to process such data, using the Provider class (including a private provider:SequencerProvider). But you have access only to the methods of a Provider class. You have not access to specific methods of SequencerProvider and RpcProvider classes of starknet.js (like getClassAt, estimateMessageFee or getEvents). And the only data available for the user to try to create a new SequencerProvider or RpcProvider is starknet.sequencer.chainId. If your wallet is connected to starknet-devnet, the chainId is not sufficient to create correctly the new provider.

I think that get-starknet should :

  1. return a provider conform to the ProviderInterface type.
  2. return also in a different object the following data (to allow the user to create an other provider including the methods he needs) :
    baseUrl:'http://localhost:5050'
    chainId:'0x534e5f474f45524c49'
    feederGatewayUrl:'http://localhost:5050/feeder_gateway'
    gatewayUrl:'http://localhost:5050/gateway'