Skip to content
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

Unknown Account #948

Closed
xmaysonnave opened this issue Jul 13, 2020 · 13 comments
Closed

Unknown Account #948

xmaysonnave opened this issue Jul 13, 2020 · 13 comments

Comments

@xmaysonnave
Copy link

Environment Metamask Mobile -> v0.2.19
Ethers -> 5.0.5

Remote debugged with Chrome DevTools
This issue do not happen on Firefox and Chrome desktop.
It occurs only on Metamask Mobile.

1 - Ethers is loaded dynamically :

Loaded $:/ipfs/library/ethers:
 https://cdn.jsdelivr.net/npm/ethers@5.0.5/dist/ethers.umd.min.js

2 - Ethers is instantiated with the metamask provider and the getAccount trick
The account is properly retrieved

// https://github.com/ethers-io/ethers.js/issues/433
const account = await this.getAccount(provider)
const web3 = new root.ethers.providers.Web3Provider(provider, 'any')

I use the 'any' parameter as advised here:
#899
I didn't do this test without this parameter though.

3 - Here is the code who crashes

const abi = ['function setContenthash(bytes32 node, bytes calldata hash)']
const iface = new window.ethers.utils.Interface(abi)
const data = iface.encodeFunctionData('setContenthash', [
  domainHash,
  encoded
])
const signer = web3.getSigner()
const tx = await signer.sendTransaction({ to: resolver, data: data })
await tx.wait()

Report:

1 - Ethers generates an exception :
Error: unknown account #0 (operation="getAddress", code=UNSUPPORTED_OPERATION, version=providers/5.0.4)
Minor remark -> the signature is still the 5.0.4 and not the 5.0.5

2 - Metamask Mobile generates as well an exception:
VM13:8 MetaMask: 'eth_accounts' unexpectedly updated accounts. Please report this bug.

Workaround :
const signer = web3.getSigner(account)
When I explicitly set the account while retrieving the signer both exceptions are gone.

Thanks

@ricmoo
Copy link
Member

ricmoo commented Jul 13, 2020

The versions are intentionally not synchronized, so the version of the sub-module is fine. :)

I’m not sure what this.getAccount is. Is that a function you added? Or part of a framework or MetaMask?

Is MetaMask enabled? Using the await window.ethereum.enable()? The MetaMask plug-in needs access enabled before any account operations can be used. This is an API I would eventually like to add, but need to coordinate a bit with the various client to make sure it works across the board.

@xmaysonnave
Copy link
Author

xmaysonnave commented Jul 13, 2020 via email

@ricmoo
Copy link
Member

ricmoo commented Oct 7, 2020

Is this still a problem? Was it a MetaMAsk issue?

@xmaysonnave
Copy link
Author

1 - I work around the issue when requesting a signer with an explicit selected account instead of the implicit selected account
provider.getSigner(account)
vs
provider.getSigner()

2 - Metamask Mobile issued several releases in the mean time.
I will do some testing to verify if the problem remains

Thanks for your support

@ricmoo
Copy link
Member

ricmoo commented Oct 7, 2020

(out of curiosity, how do you get the explicit account to use? provider.accounts?)

@xmaysonnave
Copy link
Author

As I work with Metamask I have several ways to achieve it.
1 - The first step is to use @metamask/detect-provider
Basically async on mobile, sync on desktop
2 - It's probably easier to let you browse the code:
https://github.com/xmaysonnave/tiddlywiki-ipfs/blob/795cc95a661442dce50dcdb0807ea2c7868a92cd/src/plugins/ipfs/ethereum-library/index.js#L332
Thanks

@ricmoo
Copy link
Member

ricmoo commented Apr 18, 2021

I'm going to close this now as stale. I haven't tested it, but I'm guessing there is also some issue with .enable(), which I assume that the module MetaMask forces you to use?

If this is still a problem though, please re-open.

Thanks! :)

@ricmoo ricmoo closed this as completed Apr 18, 2021
@chrisfranko
Copy link

Just to bring this back up, It is still an issue. At expanse we have a public load balanced node. Its load balanced between 6 nodes in various locations and server farms. When using hardhat for testing, everything is fine. When we start to use the live net we get this error when calling methods on contracts. I noticed that 5 out of 6 times it was failing. I thought it was me.

After like 4 hrs of debugging I realized the ONE difference on the ONE node was that it had a native account. That account is being used as account 0.

If I connect directly to the node that has a native account 0, everything works like it should 100% of the time.

Currently I'm doing..

const wallet = new ethers.Wallet(privkey, provider);
const signer = wallet.provider.getSigner();
let Contract = await ethers.getContractFactory("Menta", signer);
contract = await Contract.attach(contractAddress.mainnet);
balance = await contract.balanceOf(owner);
console.log(`BalanceOf: ${balance}`);

For some reason this only works if the provider im connecting to already has a local account even though I thought I was supplying one.

@chrisfranko
Copy link

This does work though

signer = wallet.provider.getSigner(wallet.address);

If the wallet.address isnt provided then it tries to use getAddress on account 0 on the provider youre using.

@ricmoo
Copy link
Member

ricmoo commented Jan 20, 2022

It probably doesn’t return a Signer that works though, does it?

If you are connected to a public node, all you are doing is connecting to a providers internal accounts, and by passing in an explicit address you are telling it to not bypass any checks. But once you try using this signer to sign anything or send a transaction it should fail.

@chrisfranko
Copy link

You're right, im a doofus.

So, passing it the entire wallet object works and lets you send a tx as well.

@lopeselio
Copy link

const loadWeb3 = () => {
    provider = new ethers.providers.Web3Provider(window.ethereum)
    window.ethereum.enable()
    signer = provider.getSigner()

    console.log('signer', signer);
}

@lopeselio
Copy link

const loadWeb3 = () => {
    provider = new ethers.providers.Web3Provider(window.ethereum)
    window.ethereum.enable()
    signer = provider.getSigner()

    console.log('signer', signer);
}

If you call window.ethereum.enable() , it works perfectly!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants