-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathindex.js
More file actions
37 lines (28 loc) · 1.05 KB
/
index.js
File metadata and controls
37 lines (28 loc) · 1.05 KB
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
import { ApiPromise, WsProvider } from '@polkadot/api';
import { Keyring } from '@polkadot/keyring';
const provider = new WsProvider('ws://127.0.0.1:9944');
async function substrate() {
console.log('connect...');
const api = await ApiPromise.create({
provider: provider,
types: {
// Register custom type
Metalog: {
did: "Vec<u8>",
unique_name: "Vec<u8>"
},
},
});
// For console testing
window.substrateApi = api;
document.getElementById("button").addEventListener("click", async function () {
let did = document.getElementById("did").value;
let unique_name = document.getElementById("name").value;
const keyring = new Keyring({ type: 'sr25519' });
const alice = keyring.addFromUri('//Alice');
const transfer = await api.tx.template.createMetalog(did, unique_name);
const hash = await transfer.signAndSend(alice);
console.log('Transfer sent with hash', hash);
});
}
window.onload = substrate();