-
Notifications
You must be signed in to change notification settings - Fork 0
/
example.html
72 lines (64 loc) · 2.3 KB
/
example.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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Arweave JS dApp Example</title>
<script src="https://unpkg.com/arweave/bundles/web.bundle.js"></script>
<script>
var testTransaction;
const arweave = Arweave.init({
host: 'arweave.net',// Hostname or IP address for a Arweave host
port: 443, // Port
protocol: 'https', // Network protocol http or https
timeout: 20000, // Network request timeouts in milliseconds
logging: false, // Enable network request logging
});
arweave.network.getInfo().then(console.log);
function createTransaction() {
if(arweave) {
arweave.createTransaction({
target: 'W46vSpKFlVnYyEzCn39bcwGzHslfucPZhcBsmed5uQU',
quantity: arweave.ar.arToWinston('0.00005')
}, 0).then(function(tx) {
console.log("Transaction created!", tx);
testTransaction = tx;
updateUI();
// We can now call signTransaction(tx);
});
}
}
function signTransaction(tx) {
console.log("Signing...", tx);
arweave.transactions.sign(tx).then((response) => {
console.log("Transaction signed: ", response, tx);
testTransaction = response;
updateUI();
});
}
function postTransaction(tx) {
console.log("Posting.....", tx);
arweave.transactions.post(tx).then((response) => {
console.log("Transaction posted! ", response);
testTransaction = response;
updateUI();
});
}
function updateUI() {
document.getElementById("transaction-preview").innerHTML = JSON.stringify(testTransaction);
}
</script>
</head>
<body>
<br />
1. The login button: <script type="module" src="/js/embed.js" id="weaveid-include"></script> will appear wherever you place the <code><script></code> tag. Click it to get started.
<br /><br />
2.
<button onclick="createTransaction();">Create transaction</button> and then
<button onclick="signTransaction(testTransaction);">Sign transaction</button> and finally
<button onclick="postTransaction(testTransaction);">Post transaction</button>
<br /><br />
<b>Transaction Preview:</b><br />
<div id="transaction-preview">null</div>
<br /><br />
</body>
</html>