Search
 
SCRIPT & CODE EXAMPLE
 

HTML

javascript send ethereum

<form>
    <input id="eth" name="eth" type="number" value="0.01">
    <input id="recipient" name="recipient" type="text">
    <button>Send Ethereum</button>
</form>

<!-- Using Ethers.JS -->
<script src="https://unpkg.com/ethers@5.5.2/dist/ethers.umd.min.js"></script>
<script>
    (async function init(){ 

        if ( !window.ethereum ){
            throw new Error("No crypto wallet found!");
        }

        const form = document.querySelector("form");

        form.addEventListener("submit", async (e)=>{

            e.preventDefault();

            try {
                await window.ethereum.send("eth_requestAccounts");
                const provider = new ethers.providers.Web3Provider(window.ethereum);
                const signer = provider.getSigner();
                const recipient = ethers.utils.getAddress(form.recipient.value);
                const tx = await signer.sendTransaction({
                    to: recipient,
                    value: ethers.utils.parseEther(form.eth.value)
                });
                console.log({ 
                    from: tx.from,
                    to: tx.to,
                    hash: tx.hash 
                });

            } catch(e){

                console.error(e.message);

            }
        });

    }());
</script>
Comment

PREVIOUS NEXT
Code Example
Html :: html to pdf react 
Html :: a tag in html 
Html :: html table resize columns 
Html :: square in html 
Html :: btn-default class in bootstrap 4 
Html :: html form tag 
Html :: html code for star symbol 
Html :: starter bootstrap 
Html :: tabbing slider 
Html :: disabled button by attr 
Html :: aside html 
Html :: html autocomplete 
Html :: html to jpg 
Html :: angularjs call js function 
Html :: loader 
Html :: html cheetsheet.com 
Html :: html meta 
Html :: input name html 
Html :: metal gear 
Html :: toptal html interview questions 
Html :: html ssh terminal 
Html :: fil text are with select html textarea 
Html :: cdn 
Html :: half-star icon 
Html :: abanner html code 
Html :: html how to set class 
Html :: Adding multiple video content in HTML 
Html :: Open Dropdown pop up upwards forcely 
Html :: add img to botton 
Html :: html to editable react-draft-wysiwyg 
ADD CONTENT
Topic
Content
Source link
Name
9+5 =