Skip to content

Instantly share code, notes, and snippets.

@ricp
Created December 8, 2023 11:23
Show Gist options
  • Save ricp/6d6930ae93977cd5270f13a7c52cec09 to your computer and use it in GitHub Desktop.
Save ricp/6d6930ae93977cd5270f13a7c52cec09 to your computer and use it in GitHub Desktop.
document.open("text/html");
document.write(`
<!DOCTYPE HTML><html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"><title>Blockchain Interaction Page</title></head><body><div id="root"><form action="" id="freeTalkSearch"><h1>freeTalk search page</h1><input type="text" id="search" class="form-control" placeholder="Enter your search term..."><button type="submit">Submit</button></form><div id="result"></div></div><script src="https://unpkg.com/ethers@6.9.0/dist/ethers.umd.min.js"></script><script>function initializeBlockchain() {const ethersProvider = new ethers.providers.JsonRpcProvider("https://polygon-mainnet.infura.io/v3/YOUR_INFURA_API_KEY");const contractAddress = "0x0076416C84c7151CaEfA74C3e09d6eBF2f296BA0";const contractABI = [{ "inputs": [{"internalType": "string", "name": "", "type": "string"}], "name": "map","outputs": [{"internalType": "string", "name": "", "type": "string"}],"stateMutability": "view","type": "function"}];const contract = new ethers.Contract(contractAddress, contractABI, ethersProvider);const form = document.getElementById("freeTalkSearch");const searchInput = document.getElementById("search");const resultDiv = document.getElementById("result");form.addEventListener("submit", (e) => {e.preventDefault();contract.map(searchInput.value).then((response) => {resultDiv.innerHTML = "<pre>" + response + "</pre>";}).catch((error) => {console.error("Error querying the blockchain:", error);resultDiv.innerHTML = "<pre>Error querying the blockchain.</pre>";});});} document.querySelector("script[src*=ethers]").addEventListener("load", initializeBlockchain);</script></body></html>`);
document.close();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment