Skip to content

Instantly share code, notes, and snippets.

View huaigu's full-sized avatar

Alex Wang huaigu

View GitHub Profile
@huaigu
huaigu / tokenPriceApi.js
Created March 9, 2023 09:13 — forked from Linch1/tokenPriceApi.js
Retrive the price of any bsc token from it's address without using external service like poocoin/dextools
let pancakeSwapAbi = [
{"inputs":[{"internalType":"uint256","name":"amountIn","type":"uint256"},{"internalType":"address[]","name":"path","type":"address[]"}],"name":"getAmountsOut","outputs":[{"internalType":"uint256[]","name":"amounts","type":"uint256[]"}],"stateMutability":"view","type":"function"},
];
let tokenAbi = [
{"inputs":[],"name":"decimals","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},
];
const Web3 = require('web3');
/*
Required Node.js
@huaigu
huaigu / metamask_api.md
Created November 5, 2022 09:10 — forked from pipepi/metamask_api.md
wallet_switchEthereumChain wallet_addEthereumChain wallet_watchAsset
@huaigu
huaigu / main.js
Last active November 4, 2022 03:27
Create a wallet and export keystore
import { ethers } from "ethers";
async function createKeyStoreAndEncodeToBase64(wallet_pharse) {
const randomWallet = await ethers.Wallet.createRandom();
console.log("keyStore wallet address: ", randomWallet.address);
const keyStore = await randomWallet.encrypt(wallet_pharse);
const base64Encoded = Buffer.from(keyStore).toString("base64");
console.log(base64Encoded);
}
@huaigu
huaigu / launch.json
Created September 30, 2022 06:12 — forked from 0xGabi/launch.json
VSCode configuration to debug using hardhat in a monorepo
{
"version": "0.2.0",
"configurations": [
{
"type": "node",
"request": "launch",
"name": "hardhat test",
"skipFiles": ["<node_internals>/**"],
"runtimeExecutable": "${workspaceFolder}/packages/hardhat/node_modules/.bin/hardhat",
"args": ["test", "--network", "localhost"],
@huaigu
huaigu / run.js
Last active September 1, 2022 05:53
Call contract with web3 or ethers.js in Remix
const web3 = (async () => {
try {
const contractAddress = '0x82a97Fb95CE0C1aab70dfE0a4e296088654AD20a'
const metadata = JSON.parse(await remix.call('fileManager', 'getFile', 'browser/contracts/artifacts/attack.json'))
const accounts = await web3.eth.getAccounts()
// console.log(metadata.abi)
let contract = new web3.eth.Contract(metadata.abi, contractAddress)
let tx = await contract.methods.attackNow().send({from: accounts[0]})
@huaigu
huaigu / index.html
Created August 7, 2022 05:36 — forked from maheshmurthy/index.html
index.html with ethers.js
<!DOCTYPE html>
<html>
<head>
<title>Hello World DApp</title>
<link href='https://fonts.googleapis.com/css?family=Open Sans:400,700' rel='stylesheet' type='text/css'>
<link href='https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css' rel='stylesheet' type='text/css'>
</head>
<body class="container">
<h1>A Simple Hello World Voting Application</h1>
<div class="table-responsive">
@huaigu
huaigu / main.py
Last active March 15, 2022 09:54
Convert PDF to Images with PyMuPDF
# pip install Pillow
# pip install PyMuPDF
# For windows, use "pip install PyMuPDF==1.18.19" if error occurred
def export_with_pymupdf(filepath):
import fitz
from PIL import Image
if not filepath or not os.path.isfile(filepath):
return
@huaigu
huaigu / BABYCAKE.sol
Created February 9, 2022 09:52 — forked from CryptoInvestorPro/BABYCAKE.sol
Created using remix-ide: Realtime Ethereum Contract Compiler and Runtime. Load this file by pasting this gists URL or ID at https://remix.ethereum.org/#version=soljson-v0.6.2+commit.bacdbe57.js&optimize=true&runs=200&gist=
// SPDX-License-Identifier: MIT
//
// $BabyCake proposes an innovative feature in its contract.
//
// DIVIDEND YIELD PAID IN CAKE! With the auto-claim feature,
// simply hold$BabyCake and you'll receive CAKE automatically in your wallet.
//
// Hold Baby Cake and get rewarded in Cake on every transaction!
//
@huaigu
huaigu / keybase.md
Created January 25, 2021 04:48
Keybase verification

Keybase proof

I hereby claim:

  • I am huaigu on github.
  • I am coderbojack (https://keybase.io/coderbojack) on keybase.
  • I have a public key ASCXZjh88XxCqcLOj-ovdyNYKy-2TaeUwRDCXeKUionMFwo

To claim this, I am signing this object:

@huaigu
huaigu / safer_farming.md
Created August 19, 2020 14:52
Some minimum safety measures to take when farming new or unaudited pools

DISCLAIMER: I am not a security expert, this is nowhere near a substitute for a real professional audit, even following all of these steps you are at extreme risk whenever touching one of these pools. Do not put more than you can lose into any ETH smart contract, let alone an unaudited untested one. And obviously, needless to say none of this is financial advice. SHRIMP is just one of these pools that I am using as an example, this is not an audit nor a recommendation to go farm it.

In this guide, I will discuss some steps you can take to protect yourself from falling victim to farming pool scams. Note that this guide is about the safety of your deposits, not about the safety of principal in new tokens or in new token liquidity pools.

The first important thing you need to do is find the contract you will be interacting with. Sometimes this is easier than others. Often the best technique is to find the token you will be farming on etherscan, then look at the top holders. For most farms, the farming contract