Skip to content

Instantly share code, notes, and snippets.

View traderbagel's full-sized avatar

traderbagel traderbagel

View GitHub Profile
@traderbagel
traderbagel / add-upstream.md
Created March 11, 2018 01:16 — forked from sgnl/add-upstream.md
So you've forked a Repository and you want updates...

#tl;dr

setting up a branch to track a repo

pre: assuming you have forked a repo and cloned your fork to your computer

  1. git remote add [maintainer's name] [paste URL here]
  2. git fetch --all
  3. git branch --track [maintainer's name]_[branch] [remote name from step 1]/[branch you want to track] At this point you may watch to checkout to your newly create branch and issue a git pull command.
@traderbagel
traderbagel / initial_web3.py
Last active July 21, 2018 07:46
Initial web3.py
>>> from web3 import HTTPProvider, Web3
>>> from web3.utils.datastructures import AttributeDict
>>> FULL_NODE_HOSTS = 'https://mainnet.infura.io/v3/5ed2f03bbff64000b84fef413614c437'
>>> provider = HTTPProvider(FULL_NODE_HOSTS)
>>> web3 = Web3(provider)
>>> web3.eth.blockNumber
6002659
>>> web3.eth.getBlock(6002459, full_transactions=False)
AttributeDict({
'difficulty': 3255237383587626,
'extraData': HexBytes('0x73656f34'),
'gasLimit': 8000029,
'gasUsed': 7987264,
'hash': HexBytes('0x611b64517783220be6f16efa1323330b689e65eff2205bd1a11ab2ea2bb556da'),
'logsBloom': HexBytes('0x10124481002d1900ad57e104804042200000304c4822002020c00011a18e4100a1a20020c9a04808a8605100801949502801280e21205414067010017f2181ca40817a51520100100140200900828a066040281c1440818010b163253a803c023320b04262dcc08c8830851010a2c9c414999020c50444812016035a4b016014000219010852029028d47c46b60390880481c8800058c0425000dc400a9215010281802830e240055000215111008324821a308100000810502541882a2040006d1602224bd0001682e61020cc000000803060a201ea185d00100404522424440411424000020240448984b3090058270405120244908b4224238a1910004818'),
'miner': '0xb2930B35844a230f00E51431aCAe96Fe543a0347',
'mixHash': HexBytes('0x737dc90705193a13819025afe1526cd4ba2eab72cb3e6b7cc1436dfaecee7642'),
@traderbagel
traderbagel / web3_query_transaction.py
Created July 21, 2018 08:00
web3.py query transaction
>>> web3.eth.getTransaction('0x0580de11247af326aa6e71d8e3b9cb5dc23fca864bc77c0efe486110f5a8feff')
AttributeDict({'blockHash': HexBytes('0x611b64517783220be6f16efa1323330b689e65eff2205bd1a11ab2ea2bb556da'),
'blockNumber': 6002459,
'from': '0x5f779Da58fF7a374e0d89E0FE65390aEeE3E44e4',
'gas': 21000,
'gasPrice': 7000000000,
'hash': HexBytes('0x0580de11247af326aa6e71d8e3b9cb5dc23fca864bc77c0efe486110f5a8feff'),
'input': '0x',
'nonce': 827,
'r': HexBytes('0x82a76f3db1f2ae27fdef70d34437db49e2a0505b55569344a48ad884bb21ce8c'),
@traderbagel
traderbagel / web3_query_receipt.py
Created July 21, 2018 08:01
web3.py query receipt
>>> web3.eth.getTransactionReceipt('0x0580de11247af326aa6e71d8e3b9cb5dc23fca864bc77c0efe486110f5a8feff')
AttributeDict({'blockHash': HexBytes('0x611b64517783220be6f16efa1323330b689e65eff2205bd1a11ab2ea2bb556da'),
'blockNumber': 6002459,
'contractAddress': None,
'cumulativeGasUsed': 7966264,
'from': '0x5f779da58ff7a374e0d89e0fe65390aeee3e44e4',
'gasUsed': 21000,
'logs': [],
'logsBloom': HexBytes('0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000'),
'status': 1,
@traderbagel
traderbagel / crawl_eth_transaction.py
Last active July 21, 2018 10:16
Crawl Ethereum Transaction
import time
import concurrent.futures
from collections import namedtuple
latest_height = 6002659
safe_height = latest_height - 30
begin_height = safe_height - 1000
Eth_transaction = namedtuple('Eth_transactions', ['from_address', 'to_address', 'amount'])
@traderbagel
traderbagel / build_graph_from_transactions.py
Last active July 21, 2018 12:25
build graph from transactions
from collections import defaultdict
from decimal import Decimal
import networkx as nx
edges = defaultdict(lambda :defaultdict(Decimal))
for tx in eth_transactions:
edges[tx.from_address][tx.to_address] += tx.amount
G = nx.DiGraph()
G.add_weighted_edges_from([(f, t, edges[f][t]) for f
@traderbagel
traderbagel / visualize_txs_network.py
Last active July 21, 2018 12:25
visualize txs network
import matplotlib.pyplot as plt
from matplotlib.pyplot import figure
figure(num=None, figsize=(20, 16), dpi=80, facecolor='w', edgecolor='k')
import networkx as nx
import math
pos = nx.spring_layout(G)
# Draw Nodes
@traderbagel
traderbagel / web3_query_transaction_with_logs.py
Created September 4, 2018 10:54
web3_query_transaction_with_logs.py
>>> web3.eth.getTransactionReceipt('0xba48fc0e658bfd927370ae0dda6fd37793e504e90289cd8216e986ebf714699b')
AttributeDict({
'blockHash': HexBytes('0xf16ea2ee219d8ae91ce7dae021cfd9a5a9e959bd85d78b74be1ca4444e994a81'),
'blockNumber': 6259346,
'contractAddress': None,
'cumulativeGasUsed': 7095293,
'from': '0x98702707fe04c38ce752afad9c392f4a46289274',
'gasUsed': 22514,
'logs': [AttributeDict({
'address': '0xB8c77482e45F1F44dE1745F52C74426C631bDD52',
@traderbagel
traderbagel / crawl_bnb_transaction.py
Created September 4, 2018 11:04
crawl_bnb_transaction.py
import datetime
import concurrent.futures
from collections import namedtuple
BNB_transaction = namedtuple('BNB_transactions', ['hash', 'created_at', 'block', 'from_address', 'to_address', 'amount'])
def get_receipt(tx):
if isinstance(tx, AttributeDict):
tx = tx.hash
return web3.eth.getTransactionReceipt(tx)