Skip to content

Instantly share code, notes, and snippets.

View Aviksaikat's full-sized avatar
💭
I tell people secrets, it makes them like me

Saikat Karmakar Aviksaikat

💭
I tell people secrets, it makes them like me
View GitHub Profile
@Aviksaikat
Aviksaikat / set_balance.py
Created May 17, 2025 18:10
Set accounts with native gas tokens in anvil fork on any Chain
def wallet_with_native_token(web3_fork: Web3, test_address: HexAddress) -> None:
# Directly set test_address’s balance to 100 ETH
amount_wei = 100 * 10**18
web3_fork.provider.make_request(
"anvil_setBalance",
[test_address, hex(amount_wei)]
)
assert web3_fork.eth.get_balance(test_address) == amount_wei
@Aviksaikat
Aviksaikat / README.md
Created April 17, 2025 08:34
How to fund wallet with WAVAX in anvil fork
# 1st
anvil --fork-url $AVALANCHE_RPC

# 2nd using anvil's default account at index 0
cast send 0xb31f66aa3c1e785363f0875a1b74e27b85fd66c7 "deposit()" --value $(cast to-wei 1 ether) --unlocked \ 
--from 0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266 --rpc-url http://localhost:8545

# 3rd chceck balance
cast balance --erc20 0xB31f66AA3C1e785363F0875A1B74E27b85FD66c7 0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266 \ 
@Aviksaikat
Aviksaikat / square_root.rs
Created November 12, 2024 08:40
Find square root of U256 or any integers
use alloy::primitives::U256;
fn integer_sqrt(n: U256) -> U256 {
// https://en.wikipedia.org/wiki/Integer_square_root
if n < U256::from(2) {
return n;
}
let small_candidate = integer_sqrt(n >> 2) << 1;
@Aviksaikat
Aviksaikat / convert.rs
Created November 11, 2024 13:53
convert U256 to f64
use alloy::primitives::U256;
fn main() {
let reserve_ratio: f64 = pool.reserve0.to::<f64>() / pool.reserve1.to::<f64>();
}
@Aviksaikat
Aviksaikat / get_pending_tx.rs
Created October 18, 2024 15:30
Get pending transactions using Rust
use web3::transports::WebSocket;
use web3::Web3;
def main() {
let rpc_url: String = "http://localhost:8545" //"Your RPC URL"
// Initialize WebSocket transport
let ws = WebSocket::new(&rpc_url).await?;
let w3 = Web3::new(ws);
info!("Successfully connected to WebSocket RPC.");
@Aviksaikat
Aviksaikat / pyproject.toml
Last active July 6, 2024 07:38
Add custom files and folders to ship with your pip package
## Using hatch but should be similar for other tools
# https://hatch.pypa.io/latest/config/build/#pyprojecttoml_5
# Build configs
[tool.hatch.build.targets.sdist]
include = [
"src/**/*.py",
".configs/*"
]
@Aviksaikat
Aviksaikat / get_token_balances.py
Created May 16, 2024 07:47
get tokens associated with a token account (EOA account)
from solders.pubkey import Pubkey
from solana.rpc.api import Client
from solders.pubkey import Pubkey
from solders.keypair import Keypair
from solana.rpc.types import TokenAccountOpts
from rich.pretty import pprint
# You can use async client as well
http_client = Client("https://api.mainnet-beta.solana.com")
private_key = Keypair.from_bytes(bytes(key))
@Aviksaikat
Aviksaikat / get_decimals_sol.py
Last active July 17, 2024 07:33
Get decimals of a token from SOLANA chain from a given address
from spl.token._layouts import MINT_LAYOUT
from solana.rpc.api import Client, Pubkey
http_client = Client("https://api.mainnet-beta.solana.com")
# USDC token address
addr = Pubkey.from_string("EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v")
info = http_client.get_account_info(addr)
decimals = MINT_LAYOUT.parse(info.value.data).decimals
@Aviksaikat
Aviksaikat / pipx_upgrade.sh
Created April 9, 2024 15:59
one liner to upgrade all pipx packages
pipx list --short | cut -d ' ' -f1 | while read line; do pipx upgrade $line; done
@Aviksaikat
Aviksaikat / Filecoin-Station.desktop
Created March 5, 2024 19:06
desktop file for Filecoin Station AppImage
[Desktop Entry]
Name=Filecoin Station
Comment=Filecoin Station
Exec=/home/avik/tools/filecoin-station-linux-x86_64.AppImage
Icon=/home/avik/tools/icons-for-appImage/file-coin-station.jpg
Terminal=false
Type=Application
Categories=Development;