-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
44 lines (37 loc) · 1.5 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
36
37
38
39
40
41
42
43
44
import { BeaconWallet } from "@taquito/beacon-wallet";
import { Tezos } from "@taquito/taquito";
const contractAddress = "";
window.onload = () => {
document.getElementById("init-wallet").onclick = initWallet;
};
const updateInnerText = (id, text) =>
(document.getElementById(id).innerText = text);
const initWallet = async () => {
try {
Tezos.setProvider({ rpc: `https://carthagenet.SmartPy.io` });
const options = {
name: "Beacon SDK Integration"
};
const wallet = new BeaconWallet(options);
const network = {
type: "carthagenet"
};
await wallet.requestPermissions({ network });
Tezos.setWalletProvider(wallet);
// Update dapp interface with user metadata
userAddress = wallet.permissions.address;
userBalance = await Tezos.tz.getBalance(userAddress);
contractInstance = await Tezos.wallet.at(contractAddress);
const storage = await cntractInstance.storage();
// Hides "connect" button
document.getElementById("connection").style.display = "none";
// Shows and populates the contract interface
document.getElementById("interface").style.display = "block";
updateInnerText("user-address", userAddress);
updateInnerText("user-balance", userBalance / 1000000);
updateInnerText("current-message", storage.message);
updateInnerText("current-value", storage.integer);
} catch (error) {
console.log(error);
}
}