starknet-react icon indicating copy to clipboard operation
starknet-react copied to clipboard

Custom RPC endpoint for calls

Open Pet3ris opened this issue 3 years ago • 1 comments

Is there a way to configure calls to route to a custom endpoint, for example, the Cartridge powered node: https://twitter.com/cartridge_gg/status/1524391388841975808.

As a follow-up - is there a way to specify a cascading set of endpoints => if one fails to respond, the other will be used as a back-up.

Pet3ris avatar Aug 02 '22 20:08 Pet3ris

It's possible if you have a version of starknet.js that supports rpc providers. Just specify the rpc provider as defaultProvider.

<StarknetProvider defaultProvider={new RpcProvider(...)}>
 ...
</StarknetProvider>

As for the second question, it should be an option in starknet.js I think.

fracek avatar Aug 02 '22 21:08 fracek

Hi! Not sure if I should create a separate issue. I have provided a defaultProvider.

<StarknetConfig defaultProvider={provider} connectors={connectors}>
...
</StarknetProvider>

Where provider is testnet-2:

new Provider({
    sequencer: { 
        baseUrl: "https://alpha4-2.starknet.io",
        feederGatewayUrl:"https://alpha4-2.starknet.io/feeder_gateway",
        gatewayUrl: "https://alpha4.starknet.io/gateway"
    }
})

It's working well when the page is loaded. When I connect a wallet, the provider is updated with the provider of the wallet which is fine. But when I disconnect my wallet the defaultProvider is back to testnet-1 where it should be back to testnet-2.

schwepps avatar Nov 29 '22 15:11 schwepps

This looks like a bug @schwepps! The culprit is this line where the provider should be set to the default provider.

fracek avatar Dec 08 '22 11:12 fracek

Thanks @fracek. Do you want me to open a PR with the fix?

schwepps avatar Dec 12 '22 15:12 schwepps

Yes please! I don't have the time to write a fix but happy to review a pr.

fracek avatar Dec 12 '22 15:12 fracek

I encounter the same issue. When using mainnet, after disconnecting we're back to testnet, which leads to really flaky UI...

gabsn avatar Dec 14 '22 09:12 gabsn

@gabsn I opened a PR to fix it: #199

schwepps avatar Dec 14 '22 09:12 schwepps

Fixed in #199.

fracek avatar Dec 15 '22 09:12 fracek