0

I am trying to send an ERC20 token with the following code via web3.js. It was working until a week ago and then it stopped. Am I doing something wrong? Upon clicking it no longer interacts with Metamask. Thanks in advance for the help. Moses.

<script>
    window.addEventListener('load', function() {
    // Check if Web3 has been injected by the browser:
    if (typeof web3 !== 'undefined') {
        // You have a web3 browser! Continue below!
        startApp(web3);
        //alert("Web3");
    } else {
        //alert("No hay web3");
    }
})
const abi = [{
    "constant": false,
    "inputs": [
        {
            "name": "_to",
            "type": "address"
        },
        {
            "name": "_value",
            "type": "uint256"
        }
    ],
    "name": "transfer",
    "outputs": [
        {
            "name": "success",
            "type": "bool"
        }
    ],
    "payable": false,
    "type": "function"
}]
const contract_address = '0x89d24A6b4CcB1B6fAA2625fE562bDD9a23260359'
const etherValue = web3.toWei(10, 'ether');
var addr = '0xd7B9A9b2F665849C4071Ad5af77d8c76aa30fb32'
var amount = '200'
function startApp(web3) {
    //alert("entro");
    const eth = new Eth(web3.currentProvider)
    const token = eth.contract(abi).at(contract_address);
    listenForClicks(token,web3)
}
function listenForClicks (miniToken, web3) {
    var button = document.querySelector('button.transfer')
    web3.eth.getAccounts(function(err, accounts) { console.log(accounts); address = accounts.toString(); })
    button.addEventListener('click', function() {
        miniToken.transfer(addr, amount, { from: address })
            .then(function (txHash) {
            console.log('Transaction sent')
            console.dir(txHash)
            waitForTxToBeMined(txHash)
        })
            .catch(console.error)
    })
}
async function waitForTxToBeMined (txHash) {
    let txReceipt
    while (!txReceipt) {
        try {
            txReceipt = await eth.getTransactionReceipt(txHash)
        } catch (err) {
            return indicateFailure(err)
        }
    }
    indicateSuccess()
}
</script>
<br>
<button class="transfer">Send 200 tokens!</button>
</center>

edited: Edited to fix typo

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.