Skip to content

Instantly share code, notes, and snippets.

View confirmEtherTransaction.js
function confirmEtherTransaction(txHash, confirmations = 10) {
setTimeout(async () => {
// Get current number of confirmations and compare it with sought-for value
const trxConfirmations = await getConfirmations(txHash)
console.log('Transaction with hash ' + txHash + ' has ' + trxConfirmations + ' confirmation(s)')
if (trxConfirmations >= confirmations) {
// Handle confirmation event according to your business logic
View watchTokenTransfers.js
function watchTokenTransfers() {
// Instantiate web3 with WebSocketProvider
const web3 = new Web3(new Web3.providers.WebsocketProvider('wss://'))
// Instantiate token contract object with JSON ABI and address
const tokenContract = new web3.eth.Contract(
(error, result) => { if (error) console.log(error) }
dodikk / getConfirmations.js
Created Oct 2, 2018 — forked from dsemenovsky/getConfirmations.js
Get Ethereum transaction confirmations count
View getConfirmations.js
async function getConfirmations(txHash) {
try {
// Instantiate web3 with HttpProvider
const web3 = new Web3('')
// Get transaction details
const trx = await web3.eth.getTransaction(txHash)
// Get current block number
const currentBlock = await web3.eth.getBlockNumber()
View watchEtherTransfers.js
function watchEtherTransfers() {
// Instantiate web3 with WebSocket provider
const web3 = new Web3(new Web3.providers.WebsocketProvider('wss://'))
// Instantiate subscription object
const subscription = web3.eth.subscribe('pendingTransactions')
// Subscribe to pending transactions
subscription.subscribe((error, result) => {
if (error) console.log(error)
dodikk / 0
Created Sep 27, 2018 — forked from chriseth/0
Formal verification for re-entrant Solidity contracts
View 0

This gist shows how formal conditions of Solidity smart contracts can be automatically verified even in the presence of potential re-entrant calls from other contracts.

Solidity already supports formal verification of some contracts that do not make calls to other contracts. This of course excludes any contract that transfers Ether or tokens.

The Solidity contract below models a crude crowdfunding contract that can hold Ether and some person can withdraw Ether according to their shares. It is missing the actual access control, but the point that wants to be made

View upgradeable.sol
* Base contract that all upgradeable contracts should use.
* Contracts implementing this interface are all called using delegatecall from
* a dispatcher. As a result, the _sizes and _dest variables are shared with the
* dispatcher contract, which allows the called contract to update these at will.
* _sizes is a map of function signatures to return value sizes. Due to EVM
* limitations, these need to be populated by the target contract, so the
* dispatcher knows how many bytes of data to return from called functions.
View gist:6e4b5fdc141025d609756f8aa5a20d63
"nonce": "0x0000000000000042",
"difficulty": "0x40000",
"alloc": {
"balance": "10015200000000000000000"
"mixhash": "0x0000000000000000000000000000000000000000000000000000000000000000",
"coinbase": "0x0000000000000000000000000000000000000000",
dodikk /
Created Jun 25, 2018 — forked from stevedonovan/
An ergonomic way of saying Rc<RefCell>
use std::rc::Rc;
use std::cell::{RefCell,Ref, RefMut};
use std::ops::Deref;
use std::fmt;
struct Shared<T> {
v: Rc<RefCell<T>>
dodikk / debounce-throttle.swift
Created Feb 21, 2018 — forked from simme/debounce-throttle.swift
Swift 3 debounce & throttle
View debounce-throttle.swift
// debounce-throttle.swift
// Created by Simon Ljungberg on 19/12/16.
// License: MIT
import Foundation
extension TimeInterval {
dodikk / NSObject+Debounce.h
Created Feb 21, 2018 — forked from berzniz/NSObject+Debounce.h
Debounce method for Objective C
View NSObject+Debounce.h
@interface NSObject (Debounce)
- (void)debounce:(SEL)action delay:(NSTimeInterval)delay;