import { Contract, ContractFactory } from '@ethersproject/contracts'; import { ExternalProvider, JsonRpcProvider, Web3Provider } from '@ethersproject/providers'; import { EthereumNetwork } from './network'; import { IOAuthSignatureHandler, OAuthConfig, OAuthOptions } from './oAuth'; /** * @dev InitializeOptions are the options that can be passed to initialize * @param network The network you wish to run on. If false, there is no preference * @param fallbackHost The fallbackHost for a provider (useful for browsers with no metamask) * or an object {[network: number]: [fallbackHost: string]} * @param signingProvider Initialize with a signing provider. Network must match the network parameter * @param browserProviderOverride Must implement EventEmitter and ExternalProvider. Used when you wish * to ignore the built in window.ethereum and use an overriden implementation instead. * Useful for iframe -> parent provider bridging * @param browserProviderTimeout Timeout to wait for a browserProvider to become available, in ms. Default to 1000. * @param browserProviderIgnoreDisconnect Whether or not to ignore the disconnect event for a browser provider. Default to false. */ export interface InitializeOptions { network?: EthereumNetwork | number; fallbackHost?: string | { [key: number]: string; }; signingProvider?: Web3Provider; browserProviderOverride?: ExternalProvider; browserProviderTimeout?: number; browserProviderIgnoreDisconnect?: boolean; } export declare enum EthereumProviderErrorName { EthereumProviderMultipleChains = "EthereumProviderMultipleChains", WindowEthereumConnectionError = "WindowEthereumConnectionError" } export declare const MANIFOLD_ETHEREUM_INITIALIZED = "manifold-ethereum-initialized"; export declare const MANIFOLD_ETHEREUM_EXISTS = "manifold-ethereum-exists"; export declare const ADDRESS_CHANGED = "ethereum-address-changed"; export declare const PROVIDER_CHANGED = "frontend-provider-changed"; export declare const CHAIN_CHANGED = "frontend-provider-chain-changed"; /** * @dev EthereumProvider is a singleton that allows all apps to interact with the ethereum chain * * ALL COMPONENTS MUST USE THE SAME NETWORK!!! * * Every application/component that wishes to call web3 functions or access the wallet should * first subscribe to the ADDRESS_CHANGED and PROVIDER_CHANGED events, then call initialize. * * Every application/component MUST call initialize first. * * When you wish to perform any write operations, the application/component must call connect. This * will either result in an ADDRESS_CHANGED (and optionally PROVIDER_CHANGED) on success, OR it will * throw an EthereumProviderNotConnected failure (if metamask is not installed, if the network is defined without a * fallbackProvider and the wallet network is on the wrong chain, or if the user rejects the connection request.) * * After calling initialize, you will have a provider to the correct network (and usage of web3 to the right network). * However, this does NOT mean that the installed wallet is on the right network. To check that, use the * chainIsCorrect function. * * CATCHING ERRORS * --------------- * If you are trying to catch an error thrown by the EthereumProvider, you must NOT use instanceof, because * class bindings are lost during compilation. To see if a specific error type is thrown, use error name comparison * against the EthereumProviderErrorName enum values. e.g. * try { * ... * } catch (e) { * if (e.name == EthereumProviderErrorName.WindowEthereumConnectionError) { * // Do something * } else { * throw e * } * } * */ export declare class EthereumProvider { static initialized: boolean; /** * Every class that uses EthereumProvider should call initialize * * If you pass in network and fallbackHost, we assume that the fallbackHost is * on the same network as the one desired * * @param network The network you wish to run on. If false, there is no preference * @param fallbackHost The fallbackHost for a provider (useful for browsers with no metamask) * or an object {[network: number]: [fallbackHost: string]} * @param signingProvider Initialize with a signing provider. Network must match the network parameter * @param browserProviderOverride Must implement EventEmitter and ExternalProvider. Used when you wish * to ignore the built in window.ethereum and use an overriden implementation instead. * Useful for iframe -> parent provider bridging * @param browserProviderTimeout Timeout to wait for a browserProvider to become available, in ms. Default to 1000. */ static initialize(options: InitializeOptions): Promise; /** * Whether or not a browser provider has been set * * @returns true if there is a browser provider (such as Metamask), false otherwise */ static hasBrowserProvider(): boolean; /** * Get the injected browser provider fif available * * @returns ethers.Provider instance */ static browserProvider(): JsonRpcProvider | undefined; /** * Get the chain ID of browser provider * * @returns the chain ID of the connected network */ static browserChainId(): number | undefined; /** * Set a browser provider (e.g. walletconnect or any others) * * @param provider A Web3Provider instance. * Must match network if EthereumProvider was initialized with a network */ static setSigningProvider(provider: Web3Provider): Promise; /** * Call to request login (for browser provider) * * @param browserProviderOverride Override the default browser provider. Use this in the case * where there are multiple injected providers and you want to use a * specific one */ static connect(browserProviderOverride?: any): Promise; /** * Call to logout */ static disconnect(strictAuth?: boolean): void; /** * Get a provider instance * * @param withSigner Whether or not we want a provider that can only do read operations (false) * Or one that can do read/write operations (true) * @returns ethers.Provider instance */ static provider(withSigner?: boolean): JsonRpcProvider | undefined; /** * Get an ethers.Contract instance * * @param address The address of the contract * @param abi The abi of the contract * @param withSigner Whether or not we want a provider that can only do read operations (false) * Or one that can do read/write operations (true) * @param unchecked Use unchecked signer. Useful in cases where you want to bypass current block number check * A good example is when you are using Wallet Connect without a connected node * @returns ethers Contract instance */ static contractInstance(address: string, abi: any[], withSigner?: boolean, unchecked?: boolean): Contract | undefined; /** * Get an ethers.ContractFactory instance * * @param abi The abi of the contract * @param bytecode The contract bytecode * @param unchecked Use unchecked signer. Useful in cases where you want to bypass current block number check * A good example is when you are using Wallet Connect without a connected node * @returns ethers ContractFactory instance */ static contractFactoryInstance(abi: any[], bytecode: string, unchecked?: boolean): ContractFactory | undefined; /** * Get the current connected wallet address * * @returns selected address (undefined if not logged in) */ static selectedAddress(): string | undefined; /** * Get the current connected wallet address' ENS name * * @returns selected ENS name (undefined if not logged in) */ static selectedENSName(): string | undefined; /** * Get the EthereumProvider's configured network * * @returns the configured network if any */ static network(): EthereumNetwork | number | undefined; /** * Get the chain ID of the current connected network * * @returns the chain ID of the connected network */ static chainId(): number | undefined; /** * Asks the user to switch to the given chain. Only works if there is a browser provider. * * @param chainId The chain we want to switch to */ static switchToChain(chainId: number): Promise; /** * Asks user to switch to the correct chain */ static switchToCorrectChain(): Promise; /** * Returns true if: * You specified a signing provider * There is no detected browser chain * There is no network specified * You are connected and your browser provider is using the same chain as the network * * Primarily use this after you connect. * Use this to check a user is on the right chain for WRITE functions. * Use this to show a warning if they're on the wrong chain AND connected * * @returns chainIsCorrect: bool */ static chainIsCorrect(): boolean; /** * Get an oauth nonce for the current user * @param options: defined in OAuthOptions * * @returns the oauth nonce for the current user * @throws `Invalid grant type` if grant type is not `siwe` */ static getOAuthNonce(config: OAuthConfig): Promise; /** * Get the oauth token for the current user * @param options: defined in OAuthOptions * * @returns the oauth token for the current user * @throws `Invalid grant type` if grant type is not a recognized type */ static getOAuth(config: OAuthConfig, options: OAuthOptions): Promise; /** * Retrieve and validate an existing oauth token for the current user. If there is * no oauth token, the user will not be prompted to authenticate. Useful for checking if a user * is currently authenticated or not. This is the same as calling `getOAuth` with `delayAuth` set to true. */ static getOAuthReadOnly(strictAuth?: boolean): Promise; /** * Get an OAuthSignatureHandler instance, particular for modular authentication * e.g. an integration with Rainbowkit * * @returns the oauth token for the current user * @throws 'Custom `message` can only be used with the `signature` grant type' * @throws `Invalid grant type` if grant type is not `signature` or `token` */ static OAuthSignatureHandler: new (options: Omit, userAddress: string) => IOAuthSignatureHandler; }