Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URLs added here will be added as <link>s in order, and before the CSS in the editor. You can use the CSS from another Pen by using its URL and the proper URL extension.

+ add another resource

JavaScript

Babel includes JSX processing.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

Auto Save

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                <!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css"
        rel="stylesheet" 
        integrity="sha384-eOJMYsd53ii+scO/bJGFsiCZc+5NDVN2yr8+0RDqr0Ql0h+rP48ckxlpbzKgwra6" 
        crossorigin="anonymous">
    <title>Safle Keyless</title>
</head>
<body class="bg-light">
    <div class="px-4 py-5 my-5 text-center">
        <img class="d-block mx-auto mb-4" width="250" height="200" src="https://app.getsafle.com/assets/img/svg/safle-logo.svg">
        <br />
        <div class="col-lg-6 mx-auto">
            <div class="d-grid gap-2 d-sm-flex justify-content-sm-center">
            <button type="button" class="btn btn-primary px-4 me-sm-3"  style="background-color: #007AFF" onclick="runSafle()" id="loginButton">Login</button>
          </div>
        </div>

        <div id="afterLoginDiv" class="col-lg-3 mx-auto" style="display: none;">
            <div>
                SafleID: <span id="safleIdSpan"></span><br>
            </div>
            <div>
                PublicAddress: <span id="userAddressSpan"></span><br>
            </div>
            <div>
                Wallet Balance: <span id="ethBalanceSpan"></span><br>
            </div>
            <br>
    
            <form id="transferForm">
                <div class="row">
                    <div class="col-md-4">
                        <label for="recipient" class="form-label">Recipient Address</label>
                    </div>
                    <div class="col-md-6">
                        <div class="form-group">
                            <input type="text" class="form-control" id="recipient" placeholder="to 0x......"/>
                        </div>
                    </div>
                </div>
                <br>
                <div class="row">
                    <div class="col-md-4">
                        <label for="value" class="form-label">Amount</label>
                    </div>
                    <div class="col-md-6">
                        <div class="form-group">                            
                            <input type="text" class="form-control" id="value" placeholder="value"/>
                        </div>
                    </div>
                </div>
                <br>
                <button class="btn btn-primary" style="background-color: #007AFF;margin:auto; display:block" id="submitTransferFrom">Submit Form</button>
            </form>    
        </div>
    </div>    
    <script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"
        integrity="sha384-JEW9xMcG8R+pH31jmWH6WWP0WintQrMb4s7ZOdauHnUtxwoG2vI5DkLtS3qm9Ekf" 
        crossorigin="anonymous"></script>
    <script src="https://unpkg.com/@getsafle/[email protected]/dist/keyless.min.js"></script>
</body>
</html>

              
            
!

CSS

              
                
              
            
!

JS

              
                var afterLoginDiv = document.getElementById('afterLoginDiv');
var safleIdSpan = document.getElementById('safleIdSpan');
var userAddressSpan = document.getElementById('userAddressSpan');
var ethBalanceSpan = document.getElementById('ethBalanceSpan');
var loginButton = document.getElementById('loginButton');
var userData;
var gasPrice;
var gasLimit = 30000;
var keylessWidget;
async function runSafle() {
    
    keylessWidget = new safle.safle.Widget({
            env: 'test',
            rpcURL: 'https://ropsten.infura.io/v3/b3a845111c5f4e3eaf646c79bcb4d4c0',
    });

    keylessWidget.initLogin();

    // listening to successfull widget initialisation event
    keylessWidget.on(keylessWidget.EVENTS.KEYLESS_WIDGET_INITIALISED, (data) => {
      console.log(data)
    });

    // Listening to login success event.
    keylessWidget.on(keylessWidget.EVENTS.LOGIN_SUCCESS, (widgetData) => {
        if (widgetData.status) {
            userData = widgetData.data;            
            // show values on html page
            safleIdSpan.innerHTML = userData.safleId;
            userAddressSpan.innerHTML = userData.publicAddress;
            
            // show ethBalanceSpan
            afterLoginDiv.style.display = 'block';
            // hide login button
            loginButton.style.display = 'none';
            wallet();
        }        
    });  
}
async function wallet() {
    const web3 = new safle.Web3(
        new safle.Web3.providers.HttpProvider('https://ropsten.infura.io/v3/b3a845111c5f4e3eaf646c79bcb4d4c0')
    );
    let walletBalance = await web3.eth.getBalance(userData.publicAddress);
    let ethBalance = web3.utils.fromWei(walletBalance, 'ether');
    gasPrice = await web3.eth.getGasPrice();
    ethBalanceSpan.innerHTML = ethBalance;
}

let form  = document.getElementById('transferForm');

form.addEventListener('submit', (event) => {
    // stop form submission
    event.preventDefault();
    const web3 = new safle.Web3(
        new safle.Web3.providers.HttpProvider('https://ropsten.infura.io/v3/b3a845111c5f4e3eaf646c79bcb4d4c0')
    );
    var recipient = document.getElementById('recipient').value;
    var value = document.getElementById('value').value; 
    value = web3.utils.toWei(value, 'ether')
    var rawTx = {
      to: recipient,
      value,
      gasPrice: gasPrice ,   
      gasLimit: gasLimit,
    }

    keylessWidget.initSendTransaction(rawTx);
    
    keylessWidget.on(keylessWidget.EVENTS.SIGN_AND_SEND_TRANSACTION_SUCCESSFUL, (data) => {
        console.log(data)
    });

    keylessWidget.on(keylessWidget.EVENTS.SIGN_AND_SEND_TRANSACTION_FAILED, (data) => {
      console.log(data)
    });
});
              
            
!
999px

Console