-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
50 lines (46 loc) · 1.89 KB
/
index.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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>NFT Swap DApp</title>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/web3.min.js"></script>
<script type="text/javascript">
// Set up Web3
if (window.ethereum) {
window.web3 = new Web3(window.ethereum);
window.ethereum.enable();
} else if (window.web3) {
window.web3 = new Web3(window.web3.currentProvider);
} else {
alert('Non-Ethereum browser detected. You should consider trying MetaMask!');
}
// Contract ABI
const contractABI = [
// Define contract functions here
// e.g., { "constant": true, "inputs": [], "name": "myFunction", "outputs": [{"name": "","type": "uint256"}], "payable": false, "stateMutability": "view", "type": "function" }
];
// Contract address
const contractAddress = '0xb56504262b19578400C90B9B980Bcd2aCC7FE3cD';
// Instantiate contract
const contract = new web3.eth.Contract(contractABI, contractAddress);
// Function to swap NFT and receive ERC20 tokens
async function swapNFT(tokenId) {
try {
// Call the smart contract method
await contract.methods.swapNFT(tokenId).send({from: ethereum.selectedAddress});
alert('NFT swapped successfully!');
} catch (error) {
console.error(error);
alert('Error swapping NFT. Check the console for details.');
}
}
</script>
</head>
<body>
<h1>NFT Swap DApp</h1>
<p>Enter the ID of the NFT you want to swap:</p>
<input type="text" id="tokenId" placeholder="Enter NFT ID">
<button onclick="swapNFT(document.getElementById('tokenId').value)">Swap NFT</button>
</body>
</html>