[solved] Create autosigned transaction approval using ethers and metamask

Hi, I’m using metamask as web3provider. Have this code, that returns a token’s abi:

import abiErc20 from './abi-erc20.json'
import { ethers } from "ethers"

const abiObj = {
    erc20abi: (tokenForAbi) => {
        const provider = new ethers.providers.Web3Provider(window.ethereum)
        const signer = provider.getSigner()
        const contract = new ethers.Contract(tokenForAbi, abiErc20, signer)
        return contract
    },
    methods: {
        allowance: async (abi, wallet, router) => {
            const res = await abi.allowance(wallet, router)
            console.log('Allowance : ', res)
            return res
        },
        balance: async (abi, wallet) => {
            const res = await abi.balanceOf(wallet)
            console.log('Balance : ', res)
            return res
        },
        approve: async (abi, router, amount) => {
            const res = await abi.approve(router, amount)
            console.log('Approve : ', res)
            return res
        }
    }
}

export default abiObj

And this part code, for call functions:

async function Approve() {
      const abiFrom = abiObj.erc20abi('0xbb4cdb9cbd36b01bd1cbaebf2de08d9173bc095c')
      console.log('AbiFrom: ', abiFrom)
      setAbiFrom(abiFrom)
      const allowanceChecked = await abiObj.methods.allowance(abiFrom, userAddress, exchangeAddresses.pancakeAddress)
      // console.log(allowanceChecked)
      const fromBalance = await abiObj.methods.balance(abiFrom, userAddress)
      // console.log(fromBalance)
      const fromApprove = await abiObj.methods.approve(abiFrom, '0xbb4cdb9cbd36b01bd1cbaebf2de08d9173bc095c', '100', userAddress)
      console.log(fromApprove)
    }

Is there any way I can auto-sign the transaction approval, without the metamask pop-up?

this approval has to be signed by the wallet owner, if you own the wallet and you want to make that approval in backend then you can use the private key in backend in order to make a transaction without using metamask

in front end you can not sign a transaction without a wallet application unless you have full control of the wallet application

Got it, thanks.
How to close topic?

I marked to thread as [solved].

1 Like