-
Notifications
You must be signed in to change notification settings - Fork 0
/
BridePriceEscrow.html
126 lines (119 loc) · 3.09 KB
/
BridePriceEscrow.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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Bare Bones HTML Interface for Escrow Contract</title>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/web3.min.js"></script>
<script src="https://cdn.ethers.io/lib/ethers-5.4.umd.min.js"></script>
<script>
window.addEventListener('load', async () => {
if (window.ethereum) {
window.web3 = new Web3(window.ethereum);
try {
await window.ethereum.enable();
} catch (error) {
console.error("User denied account access")
}
}
else if (window.web3) {
window.web3 = new Web3(window.web3.currentProvider);
}
else {
console.error("No Ethereum browser extension detected, install MetaMask on desktop or visit from a dApp browser on mobile.")
}
});
</script>
</head>
<body>
<h1>Escrow Contract</h1>
<p>Amount in escrow: <span id="amount"></span> ETH</p>
<p>Current account: <span id="account"></span></p>
<p><button id="depositButton" onclick="deposit()">Deposit</button></p>
<p><button id="withdrawButton" onclick="withdraw()">Withdraw</button></p>
<script>
let contractAddress = "YOUR_CONTRACT_ADDRESS";
let contractABI = [
{
"inputs": [
{
"internalType": "address payable",
"name": "bride",
"type": "address"
},
{
"internalType": "address payable",
"name": "thirdParty",
"type": "address"
}
],
"name": "initialize",
"outputs": [],
"stateMutability": "payable",
"type": "function"
},
{
"inputs": [],
"name": "description",
"outputs": [
{
"internalType": "string",
"name": "",
"type": "string"
}
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [],
"name": "getAmount",
"outputs": [
{
"internalType": "uint256",
"name": "",
"type": "uint256"
}
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [],
"name": "withdraw",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [],
"name": "deposit",
"outputs": [],
"stateMutability": "payable",
"type": "function"
}
];
let provider = new ethers.providers.Web3Provider(web3.currentProvider);
let signer = provider.getSigner();
let contract = new ethers.Contract(contractAddress, contractABI, signer);
async function updateAmount() {
let amount = await contract.getAmount();
document.getElementById("amount").textContent = ethers.utils.formatEther(amount);
}
async function updateAccount() {
let accounts = await signer.getAddress();
document.getElementById("account").textContent = accounts;
}
async function deposit() {
let value = ethers.utils.parseEther(prompt("Enter the amount of ETH to deposit:"));
await contract.deposit({value: value});
await updateAmount();
}
async function withdraw() {
await contract.withdraw();
await updateAmount();
}
updateAmount();
updateAccount();
</script>
</body>
</html>