3

You're right, the contract can't call itself the "approve" method. Instead you can write a script. An exemple with web3js 1.2 could be : var erc20Instance = new web3.eth.Contract(abi,Token_address); erc20Instance.methods.approve(contractAddress, amount).send({from: userAddress}, function(err, transactionHash) { //some code }); with : abi : the abi of ...


2

There is typo in your code. Replace: window.web3 = new Web3(window.etheruem) With: window.web3 = new Web3(window.ethereum) Also if your connection between metamask and the local project is set properly you should be able to access the current account by using ethereum.selectedAddress.


1

The approve function is used to set allowance for the current sender. If you would call it from your own contract, you would approve spending the tokens for your own contract. Instead of calling approve through a smart contract, you have to send the transaction directly from the user to the ERC-20 contract, with the address of your own smart contract ...


1

I found out that its a problem with the Ledger Nano S firmware. It doesn't sign transactions when you connect through RPC to an Ethereum network. I followed the same steps on a Trezor wallet and it just works.


1

Try window.ethereum.on('networkChanged', handleChainChanged) From what I know, the new MetaMask api (which will change this command to 'chainChanged') is not yet live.


1

Gas fee = gasLimit * gasPrice + value. In your case, it is 21000 * 0.00001 + value. The gas fee that metamask shows you implies that 21000 * 0.00001 + value == 0.21. This implies that value == 0 (i.e., you are not sending any ether in the transaction). Subsequently, the gas fee turns out as 21000 * 0.00001 + 0 == 0.21. So there is no contradiction ...


1

I'd like to return to the first issue: Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at http://localhost:8545/. (Reason: CORS request did not succeed). If you're trying to connect to localhost:8545, I assume that you're trying to connect MetaMask to a local node. Essentially, MetaMask is trying to connect to ...


1

MetaMask is a browser extension so you would need to open a web browser by definition. Instead try WalletConnect.org


1

Most likely your transaction is underpriced and it wasn't added in any block yet. This is why it is stuck in pending mode. At this moment the network is "clogged". There is a website where you can check the recommended transaction gas pricing. https://ethgasstation.info/


Only top voted, non community-wiki answers of a minimum length are eligible