synthetix-js icon indicating copy to clipboard operation
synthetix-js copied to clipboard

have an easy way to inject a custom provider

Open oleiba opened this issue 5 years ago • 1 comments

Currently, it seems there's no straight forward way to inject a provider when initializing SynthetixJS.

One can inject a signer, which can accept a provider in its constructor, but in order for the provider to implement the needed interface - it seems we must use either of ethers' provider classes. The problem is that the only field exported by SynthetixJS from ethers is utils. I suggest to also export providers from ethers, so one can easily inject its own custom provider:

const provider = new SynthetixJs.providers.InfuraProvider('ropsten', projectId);
const signer = new SynthetixJs.signers.PrivateKey(
    provider,
    networkId,  // Ropsten
    privateKey
);
const snxjs = new SynthetixJs({ networkId, signer });

oleiba avatar Jan 27 '20 20:01 oleiba

Actually the provider should additionally be passed as a property itself in the constructor argument:

const snxjs = new SynthetixJs({ networkId, provider, signer })

See here: https://github.com/Synthetixio/synthetix-js/blob/master/src/contractSettings.js#L22

But your point still stands - we can export the providers from Infura to make them more useful. This is especially important after the change from Infura that no longer allows access to archive nodes by default - see https://github.com/ethers-io/ethers.js/issues/715.

Thanks for filing, I'll keep this open until we can prioritize and address it. cc @clementbalestrat

jjgonecrypto avatar Jan 28 '20 03:01 jjgonecrypto