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 / recover.py
Created April 13, 2023 21:48
Recover Public key from transaction hash
#!/usr/bin/python3
# https://www.reddit.com/r/ethdev/comments/poqlb4/recover_a_public_key_from_a_transaction/
from hexbytes import HexBytes
from coincurve import PublicKey as CCPublicKey
from eth_account._utils.signing import to_standard_v
from eth_account._utils.legacy_transactions import serializable_unsigned_transaction_from_dict
from eth_keys.datatypes import Signature
from eth_rlp import HashableRLP
from web3 import Web3
@Aviksaikat
Aviksaikat / fix_pipx.sh
Created April 15, 2023 10:39
fix Pipx errors
#!/bin/bash
if [ $# -ne 1 ]; then
echo "Error: Please provide exactly one argument."
echo "Usage: {0} <package name>"
exit 1
fi
rm -rf ~/.local/pipx/
# pip3 uninstall pipx
@Aviksaikat
Aviksaikat / solution.md
Created April 18, 2023 11:34
Find the Bytecode of Ethereum Smart Contract by just it's address

You can use the web3.py or brownie module of python to achieve this

  • web3.py
from web3 import Web3

# Connect to custom RPC network
rpc_url = 'http://localhost:8545'  # Replace with your custom RPC URL
#chain_id = 1337  # Replace with your custom chain ID
web3 = Web3(Web3.HTTPProvider(rpc_url))
@Aviksaikat
Aviksaikat / dump_storage.py
Created April 18, 2023 13:50
Dump the non-zero storage of an Ethereum contract
#!/usr/bin/python3
from brownie import web3
from hexbytes import HexBytes
def display_storage(address, height=100, width=100):
for i in range(100):
# Regular slots
rs = web3.eth.get_storage_at(address, i.to_bytes(32, byteorder="big")).hex()
if rs != "0x0000000000000000000000000000000000000000000000000000000000000000":
@Aviksaikat
Aviksaikat / get_keccak.py
Last active May 17, 2023 10:17
Various ways of getting the keccak256 hash in python
from brownie import web3
# but for mutile parameters this is not the correct way. This is the correct way https://gist.github.com/Aviksaikat/cc69acb525695e44db340d64e9889f5e
print(web3.soliditySha3(["uint8"], [0]).hex())
print(web3.solidityKeccak(["uint8"], [0]).hex())
print(web3.keccak(0).hex())
# using ape
from ape import networks
@Aviksaikat
Aviksaikat / address_uint16.py
Created April 21, 2023 23:16
Convert ethereum address to uint16
#!/usr/bin/python3
def convert(ethereum_address="0x233d4E26853B3A7b8157bbd9F41f280A0f1cEe9B"):
# ethereum_address = "0x233d4E26853B3A7b8157bbd9F41f280A0f1cEe9B"
# 61083
# Remove '0x' prefix and convert the address to bytes
address_bytes = bytes.fromhex(ethereum_address[2:])
@Aviksaikat
Aviksaikat / get_contract_addr.py
Created April 21, 2023 23:57
Find out in advance the address of the smart contract I am going to deploy?
#!/usr/bin/python3
from brownie import web3, accounts
import rlp
def get_addr(attacker):
# Convert from hex to bytes. Be sure to drop the leading 0x
sender = bytes.fromhex(attacker.address[2:])
# The nonce is just a number
@Aviksaikat
Aviksaikat / get_address.py
Created April 22, 2023 19:32
Get the public address of an EOA from private key
from brownie import web3
private_key = "0x5381b53e8e72bd93697d74c7b4581a7291392794e409d81367d2a90dd2fd7030"
PA = web3.eth.account.from_key(private_key)
# Get public address from a signer wallet
Public_Address = PA.address
print(Public_Address)
# 0xF4c5a911AdB8521d716d4d5824Fa19880D376eF6
@Aviksaikat
Aviksaikat / get_address.py
Last active May 19, 2024 18:42
Get the public address of an EOA from private key(randomly generated)
from eth_account import Account
# Generate a new Ethereum private key
private_key = Account.create()._private_key.hex()
# Print the private key
print("Private Key:", private_key)
# Derive the Ethereum address from the private key
address = Account.from_key(private_key).address
@Aviksaikat
Aviksaikat / uint160_to_uint16.py
Created April 22, 2023 20:58
Convert uin160 to uint16
#!/usr/bin/python3
def convert(val):
return (val % (2**16))
if __name__ == "__main__":
convert(111307528078210727017296793935765405223298045576)
# 38536