0

I am trying to send payments to another account but I keep getting this message

window.addEventListener('load', async () => {
  if (window.ethereum) {
    window.web3 = new Web3(ethereum);
    try {
      await ethereum.enable();
      initPayButton()
    } catch (err) {
      $('#status').html('User denied account access', err)
    }
  } else if (window.web3) {
    window.web3 = new Web3(web3.currentProvider)
    initPayButton()
  } else {
    $('#status').html('No Metamask (or other Web3 Provider) installed')
  }
})

const initPayButton = () => {
  $('.pay-button').click(() => {
    // paymentAddress is where funds will be send to
    const paymentAddress = '0x5EF7395FE1de8cbCA95df3B328Db3Ffc3F7727b7'
    const amountEth = '1'

    web3.eth.sendTransaction({
      from:web3.eth.accounts.wallet,
      to: paymentAddress,
      value: web3.utils.toWei(amountEth, 'ether')
    }, (err, transactionId) => {
      if  (err) {
        console.log('Payment failed', err)
        $('#status').html('Payment failed')
      } else {
        console.log('Payment successful', transactionId)
        $('#status').html('Payment successful')
      }
    })
  })
}
1
  • 1
    @Ismael: "Ii am trying""I am trying" Aug 1, 2021 at 9:26

1 Answer 1

0

Try to print the value of web3.eth.accounts.wallet. I think this is giving an undefined value.

console.log(web3.eth.accounts.wallet)

See if it is giving a wallet address or not. In some cases, it is not able to fetch accounts.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.