Im trying to create a basic static html page to send a transaction using metamask. It looks like web3 is not being injected into the page at all even though i have metamask installed.

I would have expected metamask to be able to see when i change networks via its gui etc but it doesnt seem to even notice. anyone got some pointers of to do this using web3 v1.0

        <title>Introduction to Dapps. Simple MetaMask example.</title>

    <div id="meta-mask-required"></div>
        <label> Ether:
        <input type="text" id="amount"></input>
        <button onclick="send()">Donate to the Author</button>
        <div id="response"></div>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
    <script src="https://rawgit.com/ethereum/web3.js/1.0/dist/web3.min.js"></script>
        // MetaMask injects the web3 library for us.
        window.onload = function() {
        if (typeof window.web3 === 'undefined') {
            document.getElementById('meta-mask-required').innerHTML = 'You need <a href="https://metamask.io/">MetaMask</a> browser plugin to run this example'
        function send() {
            from: web3.eth.coinbase,
            to: '0xE767aEB31dAAF66366999F72FB5De2CEEA76c277',
            value: web3.toWei(document.getElementById("amount").value, 'ether')
        }, function(error, result) {
            if (!error) {
            document.getElementById('response').innerHTML = 'Success: <a href="https://testnet.etherscan.io/tx/' + result + '"> View Transaction </a>'
            } else {
            document.getElementById('response').innerHTML = '<pre>' + error + '</pre>'

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.