0

I'm using Metamask for calling smart contract.I tried to call one of the smart contract payable method but I got this error "Returned error: unknown account".Everything was working fine, until Metamask brought new update.

async function init() {
  if (window.ethereum) {
    const web3 = new Web3('https://data-seed-prebsc-1-s1.binance.org:8545/'); //testnet 
    const accounts = await window.ethereum.send('eth_requestAccounts');
    const account = accounts['result'][0];
    web3.eth.defaultAccount = account;
    return new web3.eth.Contract(abi, contractAddress);
  }
}

on trying to call the deposit method

const contract = await init();
const accounts = await window.ethereum.send('eth_requestAccounts');
const account = accounts['result'][0];
await contract.methods.deposit(amount).send({from: account})

Output - "Returned error: unknown account"

Expected Output - "Metamask Popup and ask for confirmation"

Any help would be appreciated

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.