-
-
Notifications
You must be signed in to change notification settings - Fork 60
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Property 'request' does not exist on type 'MetaMaskEthereumProvider'.ts(2339) #68
Comments
Hi @GerLC, that's a great point. We should update that example so that it works out of the box. Minimally we should export MetaMaskEthereumProvider so that you can extend it if you like: import detectEthereumProvider, { MetaMaskEthereumProvider } from '@metamask/detect-provider';
type RequestArguments = {
method: string;
params?: unknown[] | Record<string, unknown>;
}
type Provider = MetaMaskEthereumProvider & {
request<T>: (args: RequestArguments) => Promise<T>;
}
async function accessDecentralizedWeb() {
const provider = await detectEthereumProvider<Provider>();
if (provider) {
// Now you can access the decentralized web! For instance:
const chainId = await provider.request({ 'eth_chainId' });
// ... do something with the chain ID ...
} else {
// If the provider is not detected, detectEthereumProvider() resolves to null.
// You may want to inform the user to install MetaMask somehow, but for now:
console.error('Please install MetaMask!');
}
}
accessDecentralizedWeb(); |
Hello @mcmire thank you so much for your response, but the problem with importing { MetaMaskEthereumProvider } is that it says: Module '"@metamask/detect-provider"' has no exported member 'MetaMaskEthereumProvider'. Maybe it is not exporting the interface MetaMaskEthereumProvider only detectEthereumProvider |
Absolutely — that's not something we're doing right now, but that's something that we would need to do in order to make that possible. |
Is there a solution to this issue? If not then this library doesn't seem like a viable solution if this is an issue. The library looked promising so please do tell if there is a workaround... |
@mydungeon Yes, in lieu of importing that type, you can always copy it from the source code. Here's an example that should work today: type MetaMaskEthereumProvider = {
isMetaMask?: boolean;
once(eventName: string | symbol, listener: (...args: any[]) => void): this;
on(eventName: string | symbol, listener: (...args: any[]) => void): this;
off(eventName: string | symbol, listener: (...args: any[]) => void): this;
addListener(eventName: string | symbol, listener: (...args: any[]) => void): this;
removeListener(eventName: string | symbol, listener: (...args: any[]) => void): this;
removeAllListeners(event?: string | symbol): this;
}
type Provider = MetaMaskEthereumProvider & {
request<T>: (args: RequestArguments) => Promise<T>;
}
async function accessDecentralizedWeb() {
const provider = await detectEthereumProvider<Provider>();
if (provider) {
// Now you can access the decentralized web! For instance:
const chainId = await provider.request({ 'eth_chainId' });
// ... do something with the chain ID ...
} else {
// If the provider is not detected, detectEthereumProvider() resolves to null.
// You may want to inform the user to install MetaMask somehow, but for now:
console.error('Please install MetaMask!');
}
}
accessDecentralizedWeb(); With regard to this library in general, we rely in part on community contributions, so if there's anything missing, do feel free to submit a pull request and we will be happy to merge it :) |
why is |
I am still getting the same error. Is there any progress on this issue? |
Yes, we are actively working on adding a better type here. It's a bit tricky because we have to make it aligned with other parts of MetaMask. We'll post more when we have it. |
Hmm, looks like already fixed, but not published |
I am getting this using the request similar to the preview example:
The text was updated successfully, but these errors were encountered: