http://waxjs.js Below is a basic example of WaxJS functionality. To use this demo, click WAX Login (if you’re not automatically logged in), then click Sign Transaction. Auto-login Feature
If your blockchain information displays below, you’re automatically logged in to WaxJS, and you don’t need to click WAX Login. This eliminates the need for multiple clicks and popups!
WAX Login
Use this if you’re not automatically logged in. Note that if you are auto-logged in, clicking this does not open a popup and the userAccount is still returned.
WAX Login
Sign Transaction
Click once you’re logged in.
Sign Transaction
Transaction Response
const wax = new waxjs.WaxJS(‘https://wax.greymass.com’, null, null, false); //automatically check for credentials autoLogin(); //checks if autologin is available async function autoLogin() { let isAutoLoginAvailable = await wax.isAutoLoginAvailable(); if (isAutoLoginAvailable) { let userAccount = wax.userAccount; let pubKeys = wax.pubKeys; let str = ‘AutoLogin enabled for account: ‘ + userAccount + ‘
Active: ‘ + pubKeys[0] + ‘
Owner: ‘ + pubKeys[1] document.getElementById(‘autologin’).insertAdjacentHTML(‘beforeend’, str); } else { document.getElementById(‘autologin’).insertAdjacentHTML(‘beforeend’, ‘Not auto-logged in’); } } //normal login. Triggers a popup for non-whitelisted dapps async function login() { try { //if autologged in, this simply returns the userAccount w/no popup let userAccount = await wax.login(); let pubKeys = wax.pubKeys; let str = ‘Account: ‘ + userAccount + ‘
Active: ‘ + pubKeys[0] + ‘
Owner: ‘ + pubKeys[1] document.getElementById(‘loginresponse’).insertAdjacentHTML(‘beforeend’, str); } catch (e) { document.getElementById(‘loginresponse’).append(e.message); } } async function sign() { if(!wax.api) { return document.getElementById(‘response’).append(‘* Login first *’); } try { const result = await wax.api.transact({ actions: [{ account: ‘eosio’, name: ‘delegatebw’, authorization: [{ actor: wax.userAccount, permission: ‘active’, }], data: { from: wax.userAccount, receiver: wax.userAccount, stake_net_quantity: ‘0.00000001 WAX’, stake_cpu_quantity: ‘0.00000000 WAX’, transfer: false, memo: ‘This is a WaxJS/Cloud Wallet Demo.’ }, }] }, { blocksBehind: 3, expireSeconds: 30 }); document.getElementById(‘response’).append(JSON.stringify(result, null, 2)) } catch(e) { document.getElementById(‘response’).append(e.message); } }