Manifold Ethereum Provider
This section is for advanced users only. If you are just working on frontend integration, you can skip right to the Connect Widget documentation.
The Manifold Ethereum Provider is a wrapper around ethers that provides a number of convenience APIs for chain detection, wallet detection and automated provider switching (it will use the injected browser provider whenever possible).
The Manifold Ethereum Provider is typically instantiated by the Connect Widget and injected into your window as
window.ManifoldEthereumProvider
.The Manifold Ethereum Provider provides the following functions to interact with the blockchain
async initialize(network?: number, fallbackWebsocketHost?: string)
this initializes an instance of the the Manifold Ethereum Provider. If you are using the Connect Widget, there is no need to call this function, as it is automatically initiated by the widget.network
- specify which network (by chainId) your dApp works on. If you do not provide a network, means your dApp works on any network.- IMPORTANT: Make sure every call to initialize uses the same network. If you are using the Connect Widget or any other Manifold Widgets, they call initialize with the network prop provided.
fallbackWebsocketHost
- used when there is no detected browser provider.
async setSigningProvider(signingProvider: ethers.Provider)
explicitly set a provider for any contract interactions that require signing.
chainId()
gets the chain of currently connectionchainIsCorrect()
if you specified a network on initialization, tells you if the wallet is connected to the right networknetwork()
returns the network that was configured on initializationhasBrowserProvider()
returns whether or not a browser provider was detected (e.g. Metamask, Coinbase Wallet, Brave, etc.)provider(withSigner=false)
returns anethers.Provider
instance. The library will try to use the browser provider whenever possible.withSigner
- indicate if you want anethers.Provider
instance that can sign transactions. By default, it will give you a provider that can do read only operations.
selectedAddress()
returns the current connected wallet addressselectedENSName()
returns the ENS name of the current connected wallet address
async switchToCorrectChain()
if you specified a network on initialization, triggers the browser provider to switch to the configured networkasync connect()
trigger a prompt for the user to allow connection to your dApp. The Connect Widget calls this function when 'Connect' is clickedasync disconnect()
disconnects the user from the dApp.contractInstance(address, abi, signer=false)
get anethers.Contract
instance that is automatically connected to the most optimalethers.Provider
available.address
- the address of the smart contractabi
- the abi of the smart contractsigner
- whether or not you need to perform read only (signer=false) or write (signer=true) operations on the smart contract
contractFactoryInstance(abi, bytecode)
gets anethers.ContractFactory
instanceabi
- the abi of the smart contractbytecode
- the bytecode of the smart contract you wish to deploy
getOAuth(options: OAuthOptions)
get an authenticated session. Used for server-to-server authentication and to access Data Client API's via the Connect Widget (only need to be called if you are using thedata-delay-auth
prop)options
- OAuthOptions consisting of: { grantType: <one oftoken
orsignature
>; appName: string; clientId: string; }
Additionally, there are a number of events the Manifold Ethereum Provider will emit. You can listen to these events with a standard listener like this:
window.addEventListener(manifoldEthereumProvider.ADDRESS_CHANGED, (event) => {
// do something here
})
Here is a list of all events the provider emits:
ethereum-address-changed
- emitted when the user's address changes (including from undefined to 0x...)ethereum-provider-chain-changed
- emitted when the user changes chainethereum-provider-changed
- emitted when the user's provider changes
Last modified 2mo ago