Unexpected behaviour difference between setProvider
and setRpcProvider
in TezosToolkit
#2845
Labels
breaking change
A change that will break API or smart contract interactions
bug
Something isn't working
triage
Issue requires triage
ux/dx
Related to Developer Experience
Consider the following code:
This will output the following:
but the network request from the final line is still sent to
https://mainnet.smartpy.io/
, ie the previous rpc before we calledsetRpcProvider
Interestingly,
this.tezosToolkit.setProvider({ rpc: this.rpcNodes[0] })
works as expected.Here we have an unexpected difference between the two APIs.
By looking at the source code of
setProvider
, we can see that this difference is indeed unexpected:The field
rpc
of the input parameter is only used inthis.setRpcProvider(rpc);
The reason we have this difference is in the call to:
this.setReadProvider(readProvider);
:When a
readProvider
is not provided,TezosToolkit
will use therpc
.In general, any call to the
setProvider
will call all theset***Provider
s, even if the calling code has not passed anything.In my opinion, when someone passes only
rpc
to thesetProvider
, they expect onlyrpcProvider
to be updated, and no other side effect.How we can solve this problem?
One possible solution is to update the individual calls in
setProvider
like:But this will be a breaking change: If an existing dApp called
setProvider
with onlyrpc
and relied (without knowing) on the behavior thatreadProvder
is also updated, their implementation will be broken.The text was updated successfully, but these errors were encountered: