Skip to content

Instantly share code, notes, and snippets.

@wissalHaji
Created December 28, 2020 10:13
Show Gist options
  • Save wissalHaji/0942576897466ade3c402ef18c527672 to your computer and use it in GitHub Desktop.
Save wissalHaji/0942576897466ade3c402ef18c527672 to your computer and use it in GitHub Desktop.
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