UNPKG

@arcblock/www-wallet

Version:

Start experiencing your digital world with ABT Wallet

78 lines (68 loc) 2.57 kB
/* eslint-disable compat/compat */ /* eslint-disable no-plusplus */ /* eslint-disable no-await-in-loop */ /* eslint-disable no-console */ require('dotenv').config(); require('@abtnode/util/lib/error-handler'); const fs = require('fs'); const ForgeSDK = require('@arcblock/forge-sdk'); const { verifyAccountAsync } = require('@arcblock/tx-util'); const { wallet } = require('../libs/auth'); const env = require('../libs/env'); const sleep = timeout => new Promise(resolve => setTimeout(resolve, timeout)); // Check for application account const ensureAccountDeclared = async chainId => { const { state } = await ForgeSDK.getAccountState({ address: wallet.toAddress() }, { conn: chainId }); if (!state) { console.error('Application account not declared on chain'); const hash = await ForgeSDK.declare( { moniker: 'wallet_demo', wallet, }, { conn: chainId } ); console.log(`Application declared on chain ${chainId}`, hash); return { balance: 0, address: wallet.toAddress() }; } return state; }; (async () => { try { if (env.chainId) { await ensureAccountDeclared(env.chainId); await verifyAccountAsync({ chainId: env.chainId, chainHost: env.chainHost, address: wallet.toAddress() }); // if (!env.courseId()) { // console.log('start create course asset'); // const [hash, assetAddress] = await ForgeSDK.createAsset({ // moniker: 'ABT Wallet Demo Course', // readonly: true, // transferrable: false, // parent: '', // address: '', // data: { // typeUrl: 'json', // value: { // model: 'Course', // title: 'Robert on DID and ABT Wallet', // coverImage: 'https://arcblock.oss-cn-beijing.aliyuncs.com/videos/what-is-did-to-me-everyone.png', // videoUrl: 'https://arcblock.oss-cn-beijing.aliyuncs.com/videos/did-robert-20190520.mp4', // }, // }, // wallet, // }); // console.log('Course asset tx sent', { hash, assetAddress }); // await sleep(5000); // const { code } = await ForgeSDK.getTx({ hash }); // console.log('Course asset create status', code); // fs.writeFileSync(`${process.env.BLOCKLET_DATA_DIR}/courseId`, assetAddress); // } else { // console.log('skip create course asset'); // } } process.exit(0); } catch (err) { console.error('wallet-demo pre-start error', err); process.exit(1); } })();