Metamask-extension: Transactions failing with "Invalid From Address"

Created on 23 Oct 2018  Â·  17Comments  Â·  Source: MetaMask/metamask-extension

via Support:

I'm having a bug where my payable transactions have suddenly started failing with an "invalid from address" error.

In the console I'm getting

VM1525 inpage.js:1 MetaMask - RPC Error: Error: WalletMiddleware - Invalid "from" address.
at f (chrome-extension://nkbihfbeogaeaoehlefnkodbefgpgknn/background.js:1:931096) {code: -32603, message: "Error: WalletMiddleware - Invalid "from" address.↵…eogaeaoehlefnkodbefgpgknn/background.js:1:931096)"}

This is a new error - these functions previously worked fine, but late last week I switched to the new MetaMask connection protocol. I tested by moving my code back to the old connection, but it made no difference. Transactions work fine in Remix, so I'm wondering if maybe the protocol for calling these functions with web3 has changed? One of the functions with this issue is below.

const addToWhitelist = async () => {
try {
let user = await getUserAccount();
const chainId = await web3.eth.net.getId();
let owner = await factory.methods.owner().call();
const adding = await factory.methods.addToWhitelist(user).send({ from: owner, gas: gas, chainId });
const result = await verifyWhitelist();
}
catch (err) {
console.log('error adding to the whitelist', err)}}
L05-documentation N01-needsResearch T00-bug

Most helpful comment

you need to add ethereum.enable() before calling ethereum.send

MetaMask introduced a Privacy Mode that requires dapps to ask permission to view users’ accounts

All 17 comments

I'm having the exact same issue.

In case it helps anyone else, what caused this for me was calling web3.eth.sendTransaction with an address different from the address active in MetaMask. Can't say if this behavior is new, but doubt it since the last build was a week ago.

hey all - yep, this behavior was added in https://github.com/MetaMask/metamask-extension/pull/5491 and released in 4.16

the from parameter in eth.sendTransaction must match the user's address.

will leave this open for a couple days for others having the same issue.

Is there an approved protocol for a user to trigger a transaction where costs are borne by the contract owner?

I'm not sending a transaction from a different account than the one selected in Metamask and I still have this issue. I don't even see how I could do that, because Metamask would not be able to sign it.

In fact, after troubleshooting the issue for a bit, I noticed that the issue arises only in my React project using Drizzle. Could that be an incompatibility problem with Drizzle? Here are the versions I'm using in my project:

drizzle: ^1.2.2,
drizzle-react: ^1.1.1,
drizzle-react-components: ^1.2.0,

Hi, I am also facing the same issue while calling ERC20 transferFrom function from javascript. Approve is working but in transferFrom I am having trouble

Facing similar issue with send and sendAsync functions

async function sendETHWithMetamask(from) {
    console.log('sending tx')
    let transactionParameters = {
      to: '0xe58db6b23575a93c185f756618f8e42745d7292b',
      data: '0x00',
      gasLimit: '0x27100',
      gasPrice: '0x09184e72a000',
      value: '0xd',
    }
    console.log('sending tx from',from)
    ethereum.send({
      method: 'eth_sendTransaction',
      params: [transactionParameters],
      from: from,
    }, function(err, res){
      console.log({err})
      console.log({res})
    })
  }

from address is same as selected address in Metamask

you need to add ethereum.enable() before calling ethereum.send

MetaMask introduced a Privacy Mode that requires dapps to ask permission to view users’ accounts

@sarbogast did you have any luck finding a solution?

I'm having this same issue within a React project using Drizzle. I can successfully sign a transaction (SimpleStorage contract's public set function) from one account with MetaMask but I receive this error if I change my account in MetaMask & attempt the same interaction.

@asghaier76 I already did ethereum.enable(). Then users ethereum.selectedAddress as from in the param to sendETHWithMetamask. This does not help.

@prashantprabhakar
Using ethereum.enable() did MetaMask asked for approval.
Also did you make sure that your ethereum.send is waiting for the promise from ethereum.enable()

It seems to be not documented, but you have to include from in _transactionParameters_ hash as well:

    let transactionParameters = {
      from: ethereum.selectedAddress,
      ...
    }

It did the trick for me and I got this idea from here: https://metamask.github.io/metamask-docs/Examples/Low_Level_Ether_Transfer

FYI @sarbogast or any other Drizzle users out there... it appears that Drizzle's cacheSend uses the MetaMask account that's active on initial page load (when Drizzle is initialized) and does not update if you change MetaMask accounts during the session.

I solved this by overriding the from address, just like @dsemenovsky mentioned. cacheSend's last argument can be an options object that corresponds to web3's contract options

If you switch your user account on metamask, you need to ensure that the default account(i.e. from) is updated before doing anything else.

For non drizzle users, I wrote a simple async function which should work for any react dapp -

updateDefaultAccount = async () => {
    const web3 = this.state.web3;
    const accounts = await web3.eth.getAccounts();
    this.setState({defaultAccount: accounts[0].toString()});
};

As mentioned above, you must include a from address as part of the transactionParameters that matches the user's selected account. This is now included in our documentation here.

Still broken

Ignore me, I forgot to put the transactions in an array.. d'oh.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

johnerfx picture johnerfx  Â·  4Comments

aecc picture aecc  Â·  3Comments

estebanmino picture estebanmino  Â·  3Comments

MarkOSullivan94 picture MarkOSullivan94  Â·  3Comments

dpazdan picture dpazdan  Â·  3Comments