I'm using web3-react@^5.0.5
to interact with web3 from my react app. I can connect to metamask just fine.
I set the library to ethers.js
and connected to metmask. Connecting worked fine, but almost none of ethers.js's methods are there. For example, useWeb3Context().library.ContractFactory
doesn't exist.
Is this normal?
Code
Root component:
...
return (
<Web3Provider connectors={connectors} libraryName="ethers.js">
...
</Web3Provider>
);
...
connectors
object:
const { InjectedConnector } = Connectors;
// Initially support Ropsten and Mainnet
const MetaMask = new InjectedConnector({ supportedNetworks: [1, 3] });
export const connectors = { MetaMask };
Subcomonent:
function SubComponent() {
const web3 = useWeb3Context();
function connect() { /* Connect to MetaMask, works fine */ }
async function deployContract() {
// Fails:
// TypeError: web3.library.ContractFactory is not a constructor
const factory = new web3.library.ContractFactory(ABI, BINARY);
}
return (/* ... */);
}
web3-react
andethers.js
was done here: github.com/Uniswap/interface – Finalist