Created
December 28, 2020 10:13
-
-
Save wissalHaji/0942576897466ade3c402ef18c527672 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const displayGreeting = async (greeting, contract) => { | |
greeting = await contract.methods.sayHello().call(); | |
$("h2").html(greeting); | |
}; | |
const updateGreeting = (greeting, contract, accounts) => { | |
let input; | |
$("#input").on("change", (e) => { | |
input = e.target.value; | |
}); | |
$("#form").on("submit", async (e) => { | |
e.preventDefault(); | |
await contract.methods | |
.updateGreeting(input) | |
.send({ from: accounts[0], gas: 40000 }); | |
displayGreeting(greeting, contract); | |
}); | |
}; | |
async function greetingApp() { | |
const web3 = await getWeb3(); | |
const accounts = await web3.eth.getAccounts(); | |
const contract = await getContract(web3); | |
let greeting; | |
displayGreeting(greeting, contract); | |
updateGreeting(greeting, contract, accounts); | |
} | |
greetingApp(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment