Last active
May 10, 2021 15:27
-
-
Save fakenickels/4047c4f0a0c9158862dda758d1527194 to your computer and use it in GitHub Desktop.
Et ririum quick snippets I took from https://fees.wtf/
This file contains hidden or 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
async function tip(amount) { | |
if(window.hasOwnProperty("ethereum") && window.ethereum.hasOwnProperty("isMetaMask")) { | |
const provider = new ethers.providers.Web3Provider(window.ethereum); | |
const signer = provider.getSigner(); | |
const tx = signer.sendTransaction({ | |
to: await provider.resolveName('feeswtf.eth'), | |
value: ethers.utils.parseEther(amount) | |
}) | |
} else { | |
return alert('Install MetaMask to use this cool feature. https://metamask.io') | |
} | |
} | |
$(document).on('click', '#tinytip', function (e) { | |
tip("0.001"); | |
e.preventDefault(); | |
}); | |
$(document).on('click', '#smalltip', function (e) { | |
tip("0.01"); | |
e.preventDefault(); | |
}); | |
$(document).on('click', '#bigtip', function (e) { | |
tip("0.1"); | |
e.preventDefault(); | |
}); | |
$(document).on('click', '#hugetip', function (e) { | |
tip("1"); | |
e.preventDefault(); | |
}); |
This file contains hidden or 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
window.addEventListener('load', async () => { | |
let params = getUrlVars(); | |
let address = params.address || params.a || null; | |
if (address == null) { | |
if(window.hasOwnProperty("ethereum") && window.ethereum.hasOwnProperty("isMetaMask")) { | |
let addresses = await ethereum.request({ method: 'eth_requestAccounts' }); | |
address = addresses[0]; | |
console.log('Connected to', address) | |
} else { | |
console.log('Specify an address via ?a= or ?address= url GET parameter, or sign into MetaMask.') | |
$('body').html('<p id="oops">Sign into <strong><a href="https://metamask.io">MetaMask</a></strong> or pass an address via the url (like <strong><a href="http://fees.wtf?address=0xcdd6a2b9dd3e386c8cd4a7ada5cab2f1c561182d">this</a></strong>).</p>') | |
return; | |
} | |
} | |
main(address) | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment