We’d like to present you our first code snippet utilizing Comet, a web3 supportive (native) web wallet which enables for the creation and distribution of dApps powered by the VeChainThor Blockchain.
As many people have been asking about this, we’re showing you a bare-bones and simple way of implementing a Comet Tip Button powered by the VeChainThor Blockchain to your website. With it you can specify the amount of VET you’d like to tip. Keep in mind, this is a code snippet meant as a quick and easy example. It is not meant to be used in a live environment without changing it according to your own needs.
We have two pieces of code. First, we have the <head> section which includes web3.min.js and then the <body> section to include the actual button that calls for our sendTippy() function. You’re able to change the amount of VET you wish to send across mainnet by changing the specified target address within the source code. It will show you a transaction link when your Comet tip was successful.
Play around with it, and enjoy!
- You’ll need to put the Account Privacy setting to ‘Automatically share with DApps’ in Comet (Settings > Account Privacy).
- This works for both mainnet and testnet. However, on testnet you’ll receive a tx URL that is meant for a mainnet transaction, and will thus be invalid.
This section imports the web3.min.js file, creates an addEventListener and declares all required variables. It also creates the actual sendTippy() function.
This section shows the actual label and button to fire the function sendTippy().
<body> // Let's throw in the body, intentionally coded so that it's extra ugly. We love using <center></center> for this purpose. <center> <br><br><br><br> <img src="comet_test.png" alt="Comet" style="width:128px;height:128px;"> <br><br><br><br> <div id="wrapper"> <div id="page-content-wrapper"> <div class="container-fluid"> // And finally the button that launches the sendTippy() function. <fieldset> <label> VET: // Input the VET amount you want to tip, refers to the sendTippy() to: within let AMOUNTVET. <input type="text" id="amount"></input> </label> <button onclick="sendTippy()">Donate</button> // Tie a response to allow the VeForge URL to make sense. We don't want to enter the Void. <div id="response"></div> </fieldset> </div> </div> </div> </center> </body>
We will be adding more code snippets that work, stay tuned!