@iexec/dataprotector
Version:
This product enables users to confidentially store data–such as mail address, documents, personal information ...
25 lines (22 loc) • 660 B
text/typescript
import { AbstractProvider, AbstractSigner, Eip1193Provider } from 'ethers';
import { IExecNetworkModule } from 'iexec';
import { DEFAULT_CHAIN_ID } from '../config/config.js';
type EthersCompatibleProvider =
| string
| AbstractProvider
| AbstractSigner
| Eip1193Provider;
export async function getChainIdFromProvider(
ethProvider: EthersCompatibleProvider
): Promise<number> {
try {
const networkModule = new IExecNetworkModule({
ethProvider,
});
const { chainId } = await networkModule.getNetwork();
return Number(chainId);
} catch (e) {
console.warn('Failed to detect chainId:', e);
}
return DEFAULT_CHAIN_ID;
}