Skip to content

Instantly share code, notes, and snippets.

View miohtama's full-sized avatar
🏠
https://tradingstrategy.ai

Mikko Ohtamaa miohtama

🏠
https://tradingstrategy.ai
View GitHub Profile
@miohtama
miohtama / get_all_erc_20_approve_transactions_using_bigquery.sql
Created April 2, 2021 10:00
Get all ERC-20() transactions using BigQuery public dataset
-- Get all approve() transaction
-- Web3.utils.keccak256("approve(address,uint256)").slice(0, 10);
-- '0x095ea7b3'
WITH txdata as (
SELECT tx.hash as txid, tx.block_timestamp as block_timestamp, cast(tx.receipt_gas_used as numeric) * cast(tx.gas_price as numeric) as cost FROM
bigquery-public-data.crypto_ethereum.transactions as tx
where
tx.input
LIKE "0x095ea7b3%")
SELECT (SUM(cost) / POWER(10, 18)) as eth_cost from txdata;
@miohtama
miohtama / example.py
Created March 26, 2021 10:51
Solidity and Ethereum int256 for Python, SQLAlchemy and SQL Databases, efficiently as 32 bytes blobs
class LiquidityChanged(TransactionEvent):
"""A sampled liquidity at any moment."""
__tablename__ = "liquidity"
delta0 = sa.Column(Int257, nullable=False, index=False)
"""A stateful event scanner for Ethereum-based blockchains using web3.py.
With the stateful mechanism, you can do one batch scan or incremental scans,
where events are added where the scanner left last time.
Copyright 2021 Mikko Ohtamaa, https://twitter.com/moo9000, licensed under MIT
"""
import datetime
import time
@miohtama
miohtama / bigquery.sql
Created January 28, 2021 11:47
How to get the total cost of approve() function calls on Ethereum blockchain
-- Web3.utils.keccak256("approve(address,uint256)").slice(0, 10);
-- '0x095ea7b3'
WITH txdata as (
SELECT tx.hash as txid, cast(tx.receipt_gas_used as numeric) * cast(tx.gas_price as numeric) as cost FROM
bigquery-public-data.crypto_ethereum.transactions as tx
where
tx.input
LIKE "0x095ea7b3%")
SELECT (SUM(cost) / POWER(10, 18)) as eth_cost from txdata;
#!/bin/sh
#
# This is a faux solc stub that runs a dockerized solc
#
VERSION=$SOLC_VERSION
# Docker complains about abs paths
ME=`dirname "$0"`
ME=`realpath $ME`

Completed the exercise.

Added a sign up component.

Time spent: 4 hours.

@miohtama
miohtama / good-pr.md
Created November 9, 2020 10:24
Good PR
@miohtama
miohtama / transaction-helper.component.ts
Created May 26, 2020 16:39
TypeScript + Angular Ethereum transaction progress bar component
import { Component, OnInit, Input, ViewChild, Output, EventEmitter } from '@angular/core';
import { Web3Service, WalletState, WalletType } from '../web3.service';
import Web3 from 'web3';
import { waitTransaction, isSuccessfulTransaction } from '../transactionwait';
import { isRequired, checkRequired } from '../requiredInput';
import { EthereumProgressBarComponent } from '../ethereum-progress-bar/ethereum-progress-bar.component';
import { Subscription } from 'rxjs';
import { NGXLogger } from 'ngx-logger';
// Called before creating a tranaction.
@miohtama
miohtama / launch.json
Created February 13, 2020 22:29
Launching Jest e2e+NestJS from Visual Studio Code - so you can hit breakpoints
// https://github.com/microsoft/vscode-recipes/tree/master/debugging-jest-tests
{
"version": "0.2.0",
"configurations": [
{
"type": "node",
"request": "launch",
"name": "Jest All",
"program": "${workspaceFolder}/node_modules/.bin/jest",
"args": [
{
"version": "0.2.0",
"configurations": [
{
"type": "node",
"request": "launch",
"name": "Launch user.e2e test",
"runtimeExecutable": "npm",
"cwd": "${workspaceFolder}",
"runtimeArgs": [