How to Approve spend of one Token with Web3.js ?

Hello guys.

I am currently using an html page that is available to my users. I need to set up a button that allows the spending of BUSD or other stablecoin tokens on the same page.

Once the button is clicked I want Metamask to open and ask the user if they want to approve the address (for example: 0xe9e7CEA3DedcA5984780Bafc599bD69ADd087D56) for the BUSD token spending.

I found an approach that works well for connecting and loading the wallet. BUT the transaction for the approve function does not work. Here is my code:

async function connectMetamask() {
const web3 = new Web3('https://bsc-dataseed1.binance.org:443');
await window.web3.currentProvider.enable();
const proxy = "BuyerAdress"; // spender adress 
const TOLaddress = "MyTokenAddress";//my coin adress
const value = "100"; // value
approve(proxy, 0); //i need approve one time for client adress
     
     }

Thank you very much for your help, I’m stuck for some time on this problem.

Thank you very much for your help, I’m stuck for some time on this problem.

You can use executeFunction. Or you can use web3, but how it is done is pretty different from how you have went about it

Thank you for your quick response. It gives me some hope. I’m willing to change the way things work as long as it works.

I’ve been working on this small code for a while now and I’ve been blocking since …

Is it possible for you to help me to adapt the code to this function?

Thanks a lot for your help!

Yeah sure, basically if you check the executeFunction docs you see what parameters you’ll have to pass in: a contract address, a contract abi, the function name and parameters, so first I suggest you get all of those