Skip to content

Instantly share code, notes, and snippets.

View JacobThaDev's full-sized avatar
😀
coding and doing things...

Jacob Smith JacobThaDev

😀
coding and doing things...
View GitHub Profile
@JacobThaDev
JacobThaDev / UpdateState.tsx
Created March 16, 2024 15:03
How to update the state from previous case study
const update = () => {
// can not be within 5 seconds of each other.
if (account.getLastUpdate() - new Date().getTime() < 5000) {
return;
}
// update account then reset the state so it updates!
account.update().then((returnedScope: any) => {
let currentTime = new Date().getTime();
setAccount(returnedScope); // update account data!
@JacobThaDev
JacobThaDev / AccountContext.tsx
Last active March 16, 2024 15:12
NextJS maintain state across scopes
const [ account, setAccount ] = useState<AccountData>();
const [ startUpdater, setStartUpdater ] = useState<boolean>(false);
const [ activeTimer, setActiveTimer ] = useState<any>(null);
// export this in your context to make a refresh button also. just call it.
// hence the 5 second throttle. lol. could possibly do some refining here on an edge case
// of where the auto-refresh comes close to the manual refesh.
const update = () => {
// can not be within 5 seconds of each other.
if (account.getLastUpdate() - new Date().getTime() < 5000) {
@JacobThaDev
JacobThaDev / GlowToken Lotto Bot
Created March 27, 2022 02:52
A quick code snippet of how the discord bot draws a random address to receive the lottery.
/**
* Transparency Notice:
* This snippet was stripped and modified from the actual bot in a way
* so it's easier to explain. The bot functions the same. -OGKingFox
*/
// this will sync all of the people that have ever touched glow to a database.
// once stored, we can then select a random one. BscScan limits to 10,000 entries so
// if you're an old token, you're gonna need to run this first a few times...
@JacobThaDev
JacobThaDev / tokenprice.js
Last active March 1, 2022 07:05
How to get the value of a token.
const Web3 = require("web3");
const web3 = new Web3(new Web3.providers.HttpProvider("https://bsc-dataseed1.binance.org:443"));
const mini_abi = [{"inputs":[],"stateMutability":"nonpayable","type":"constructor"},{"inputs":[{"internalType":"address","name":"account","type":"address"}],"name":"balanceOf","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"decimals","outputs":[{"internalType":"uint8","name":"","type":"uint8"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"totalSupply","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"}];
const aggregator = [{"inputs":[],"name":"decimals","outputs":[{"internalType":"uint8","name":"","type":"uint8"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"description","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalTyp