repl.it
@fortmatic/

demo-wallet

HTML, CSS, JS

No description

fork
loading
Files
  • index.html
  • init.js
  • logo.svg
  • style.css
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
<!DOCTYPE html>
<html>

<head>
	<title>Demo Wallet</title>
	<meta charset="utf-8">
	<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
	<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/web3.min.js"></script>
  <script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/jquery.min.js"></script>
  <script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/fortmatic.js"></script>
	<link href="style.css" rel="stylesheet" type="text/css" />
	<script>
    let fm = new Fortmatic('pk_test_53D49050103F2885');
    web3 = new Web3(fm.getProvider());

    let setUserInfo = async () => {
      web3.eth.getAccounts((err, accounts) => {
        if (err) throw err;
        let address = accounts[0];
        console.log(address);
        $('#user-address').text(address);
      });
      // Get user balance (includes ERC20 tokens as well)
      let balances = await fm.user.getBalances();
      console.log(balances);
      let ethBalance = balances.find((e) => {
        return e.crypto_currency == 'ETH';
      });
      $('#user-balance').text(ethBalance.crypto_amount_display + ' ETH');
    };
  
    let handleSendTransaction = () => {
      fm.transactions.send((err, txnHash) => {
        if (err) throw err;
        setUserInfo();
      });
    };

    let handleLogin = async () => {
      // Authenticate user
      let accounts = await fm.user.login();
      if (accounts.length > 0) {
        $('#section-login').hide();
        $('#section-account').show();
        setUserInfo();
      }
    };

    let handleLogout = () => {
      fm.user.logout();
      $('#section-login').show();
      $('#section-account').hide();
    };
    
	</script>
</head>

<body>
	<div class="container">
		<img alt="logo" src="logo.svg" />
		<h1>Your Favorite Ethereum Wallet 💎</h1>
		<div class="divider"></div>
    <div id="section-login">
      <a id="btn-login" class="btn">Login with SMS</a>
    </div>
    <div id="section-account">
      <div id="user-address"></div>
      <div id="user-balance"></div>
      <a id="btn-send" class="btn">Send Transaction</a>
      <a id="btn-logout" class="btn">Logout</a>
    </div>
	</div>
	<script src="init.js"></script>
</body>

</html>
result
console