-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.js
35 lines (35 loc) · 1.11 KB
/
index.js
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
// importing the ethers.js library
const ethers = require('ethers');
// importing hyperapp
import { h, app } from "hyperapp";
// Create a wallet object with privateKey and address attributes with a default state set to null.
const state = {
wallet: {
privateKey: null,
address: null
}
}
// Create a generateWallet action in wallet, that calls the ethers.js library wallet.createRandom() method and returns a newly created privateKey and address. Set the created privateKey and address to the app state.
const actions = {
wallet: {
generateWallet: () => state => {
const wallet = ethers.Wallet.createRandom();
return {
privateKey: wallet.privateKey,
address: wallet.address
};
},
},
};
// Displays the wallet address and privateKey states.
// Create a button that calls the generateWallet action.
const view = (state, actions) => (
<div>
<h1>Address:{state.wallet.address}</h1>
<h1>Private Key:{state.wallet.privateKey}</h1>
<button onclick={() => actions.wallet.generateWallet()}>
Generate Wallet
</button>
</div>
);
app(state, actions, view, document.body)