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 / .gitignore
Last active April 23, 2023 19:29
gitignore for Python projects
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class
# C extensions
*.so
# Distribution / packaging
.Python
@Aviksaikat
Aviksaikat / derive.py
Last active April 23, 2023 19:36
Generate Ethereum private key, public key, and address using Python code
import sha3
from ecdsa import SigningKey, SECP256k1
# Create a keccak_256 hash object
keccak = sha3.keccak_256()
# Generate a new private key using the SECP256k1 curve
private = SigningKey.generate(curve=SECP256k1)
# Get the corresponding public key in bytes format
@Aviksaikat
Aviksaikat / abi_encode.py
Last active May 20, 2024 07:44
Correct way to generate keccak256 hash of multiple data types using python
from brownie import web3
# wrong
print(web3.solidityKeccak(["uint256", "address", "uint256"],[2, "0x0000000000000000000000000000000000001337", 8948253]).hex())
# >> 0x7c251610f9474d6a5f00096d05e0ae40e433cae67c90e400cf88aad9f24398ef
# right
from eth_abi import encode
encoded_data = encode(
["uint256", "address", "uint256"],
[2, "0x0000000000000000000000000000000000001337", 8948253],
@Aviksaikat
Aviksaikat / network-config.yaml
Created May 6, 2023 12:54
Test locally on goerli-fork. Add this to your `network-config.yaml`
- cmd: ganache-cli
cmd_settings:
accounts: 10
evm_version: istanbul
fork: goerli
gas_limit: 12000000
mnemonic: brownie
port: 8545
host: http://127.0.0.1
id: goerli-fork-local
@Aviksaikat
Aviksaikat / ape-config.yaml
Last active May 15, 2023 19:46
Sample config file for ApeWorkX
name: simple_storage
plugins:
- name: solidity
version: 0.6.3 # version of the plugin
- name: ganache
- name: alchemy
- name: hardhat
# - name: ens
# - name: etherscan
ethereum:
@Aviksaikat
Aviksaikat / b32-u256.py
Last active May 20, 2024 07:43
bytes32 to int(uint256)
from brownie import web3
web3.toInt(bytes32Data)
# ape
from ape import convert
convert(bytes32Data, int)
@Aviksaikat
Aviksaikat / int_to_b32.py
Created May 15, 2023 13:27
convert an integer to bytes32
from brownie import web3
value = 1
# * convert it to bytes32
value = value.to_bytes(32, byteorder="big")
>>> value
b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01'
>>> value.hex()
@Aviksaikat
Aviksaikat / encodeWithSignature.py
Created May 16, 2023 23:51
How to do `abi.encodeWithSignature` in python
value = Contract.methodName.encode_input()
print(value)
# wrong
# >> '0xa7a7e4e8'
value = Contract.methodName.encode_input()
# add padding to make it 32 bytes
value = value + "0" * (66 - len(value))
print(value)
# correct
#>> '0xa7a7e4e800000000000000000000000000000000000000000000000000000000'
@Aviksaikat
Aviksaikat / update_docker_images.sh
Last active May 18, 2023 11:08
Update all your docker images
docker images --format "{{.Repository}}:{{.Tag}}" | xargs -L1 docker pull
# then remove the "<none>" tagged images
docker images | grep "<none>" | awk '{print $3}' | xargs docker rmi
@Aviksaikat
Aviksaikat / remove.sh
Created May 18, 2023 11:09
remove none tagged docker images
docker images | grep "<none>" | awk '{print $3}' | xargs docker rmi