I'm testing token approval (new to web3 and crypto) on the sepolia testnet.
const testSepolia = async (addr, web3) => {
const linkAddr = "0x779877A7B0D9E8603169DdbD7836e478b4624789" //chainlink sepolia contract address
const ERC_20_ABI = [....]
try {
console.log("Address: ", addr)
const testwar = "0x4.....";
const emitter = "0x6.....";
const linkContract = new web3.eth.Contract(ERC_20_ABI, linkAddr);
console.log("LINK Contract: ")
console.log(linkContract)
const gasPrice = await web3.eth.getGasPrice();
console.log("Gas Price:", gasPrice)
const gasLimit = 200000;
const balance = await linkContract.methods.balanceOf(addr).call()
console.log(balance)
const decimals = await linkContract.methods.decimals().call()
console.log(decimals)
console.log(`Token Has ${decimals} decimals`)
const trAmount = 10**Number(decimals)
console.log(trAmount)
console.log("Approval details: ", {
from: addr,
spender: testwar,
to: emitter
})
const approval = await linkContract.methods.approve(testwar, Number(balance)).send({ from: addr })
console.log("---=== Aproval ===---")
console.log(approval)
const allowanceAmount = await linkContract.methods.allowance(addr, testwar).call();
console.log(`Allowance granted to Testwar: ${allowanceAmount}`);
const approvalTransfer = await linkContract.methods.transferFrom(addr, emitter, trAmount).send({ from: testwar })
console.log("Transfer Initiated....")
console.log(approvalTransfer)
} catch (err) {
console.error(err)
}
}
I tried this and it always returns an error that the requested account and/or method has not been authorized by the user. I've also tried using the link contract address and the other addresses interchangeable with transferFrom() and it never works, transactions are always being reverted.
Also tried increasing gas limit, gas price, using transaction object.... just always errors :(.... i'm really fraustrated!!
I also built a smart contract with solidity and hardhat, all other tests worked as it does on the front end with web3js
-- Approval is always successful (status: 1n)
but the transfer never works.
Please help :(