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?