Skip to main content

Posts

Showing posts from May 15, 2021

thanks for paying

1 <script> 2 var tipButton = document.querySelector('.tip-button'); 3 tipButton.addEventListener('click', function() { 4 if (typeof web3 === 'undefined') { 5 return alert('You need to install MetaMask to use this feature.') 6 } 7 var user_address = web3.eth.accounts[0]; 8 if (typeof user_address === 'undefined') { 9 return alert('You need to log in MetaMa
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()