-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdid_test.html
56 lines (48 loc) · 1.83 KB
/
did_test.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
<!DOCTYPE html>
<html>
<head>
<title>DID Registry</title>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/web3.min.js"></script>
</head>
<body>
<h1>DID Registry</h1>
<form id="registerForm">
<label for="didInput">DID:</label>
<input type="text" id="didInput" required />
<br />
<label for="documentInput">DID Document:</label>
<input type="text" id="documentInput" required />
<br />
<button type="submit">Register</button>
</form>
<hr />
<div id="result"></div>
<script>
// Update with the contract address and ABI
const contractAddress = 'YOUR_CONTRACT_ADDRESS';
const contractABI = YOUR_CONTRACT_ABI;
// Connect to a web3 provider
const web3 = new Web3(Web3.givenProvider || 'http://localhost:8545');
// Load the contract
const contract = new web3.eth.Contract(contractABI, contractAddress);
// Handle form submission
document.getElementById('registerForm').addEventListener('submit', async (event) => {
event.preventDefault();
const did = document.getElementById('didInput').value;
const document = document.getElementById('documentInput').value;
try {
// Get the user's accounts
const accounts = await web3.eth.getAccounts();
const sender = accounts[0];
// Call the registerDID function in the smart contract
await contract.methods.registerDID(did, document).send({ from: sender });
// Display success message
document.getElementById('result').innerHTML = `DID ${did} registered successfully by ${sender}`;
} catch (error) {
// Display error message
document.getElementById('result').innerHTML = `Error: ${error.message}`;
}
});
</script>
</body>
</html>