Skip to content

Instantly share code, notes, and snippets.

What's happening?

Adrian Li adrianmcli

What's happening?
Block or report user

Report or block adrianmcli

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
adrianmcli / web3_error_log.txt
Created Nov 5, 2019
Error log from Web3.js install on Node v13
View web3_error_log.txt
> keccak@1.4.0 install /Users/adrianli/dev/temp/node_modules/keccak
> npm run rebuild || echo "Keccak bindings compilation fail. Pure JS implementation will be used."
> keccak@1.4.0 rebuild /Users/adrianli/dev/temp/node_modules/keccak
> node-gyp rebuild
CXX(target) Release/
../src/ error: too few arguments to function call, single argument 'context' was not specified
unsigned int rate = info[0]->IntegerValue();
adrianmcli / counter-composition.js
Last active Feb 5, 2019
An example of using plain functions and composing them to make state containers.
View counter-composition.js
// state container definition
const useState = initVal => {
let val = initVal;
const get = () => val;
const set = x => (val = x);
return Object.freeze({ get, set });
adrianmcli / counter.js
Created Jan 6, 2019
Example of encapsulating state with a function that return objects.
View counter.js
const makeCounter = (initVal = 0) => {
let count = initVal;
const get = () => count;
const set = x => (count = x);
const inc = () => count++;
const dec = () => count--;
return Object.freeze({
adrianmcli / compile.js
Last active Jan 14, 2020
Programmatically compile and deploy Solidity smart contracts for your tests
View compile.js
const path = require("path");
const fs = require("fs");
const TruffleCompile = require("truffle-compile");
// Promisify truffle-compile
const truffleCompile = (...args) =>
new Promise(resolve => TruffleCompile(...args, (_, data) => resolve(data)));
const compile = async filename => {
const sourcePath = path.join(__dirname, "../contracts", filename);
View helpers.js
const Web3 = require("web3") // import web3 v1.0 constructor
// use globally injected web3 to find the currentProvider and wrap with web3 v1.0
const getWeb3 = () => {
const myWeb3 = new Web3(web3.currentProvider)
return myWeb3
// assumes passed-in web3 is v1.0 and creates a function to receive contract name
const getContractInstance = (web3) => (contractName) => {
View newTests.js
const { getWeb3, getContractInstance } = require("./helpers")
const web3 = getWeb3()
const getInstance = getContractInstance(web3)
contract("Counter", (accounts) => {
it("should initialize with a count of 0", async () => {
const counter = getInstance("Counter")
const count = await counter.methods.get().call()
const expected = 0
View oldTests.js
const Counter = artifacts.require("Counter")
contract("Counter", (accounts) => {
it("should initialize with a count of 0", async () => {
const counter = await Counter.deployed()
const count = await
const expected = 0
assert.equal(count, expected, "count was not initialized with 0")
adrianmcli / output.txt
Last active May 22, 2018
script for tracking network requests from a website
View output.txt
adrianmcli / transform.js
Last active May 9, 2018
just a simple function to transform a typical 0x order object into the form we need.
View transform.js
const transform = ({
}) => ({
exchangeContractAddress: exchangeContract,
expirationUnixTimestampSec: expiration,
adrianmcli /
Last active Feb 21, 2018
Concrete use-case examples for


Please note that WETH and ETH will be used interchangeably in the following discussion.

The b0x network allows anyone with ERC20 tokens to loan it out for interest on a margin trading platform.

Example 1: Alice holds a lot of ETH tokens and instead of letting it sit, she wants to lend it to traders who are looking to borrow money so that they can trade on margin. Alice creates a b0x order specifying the type of token she is lending out (i.e. loanToken) and the type of token that she wants the interest to be paid in (i.e. interestToken).

The lender can specify the specific margin amounts that the borrower must have in order to fill the order and maintain the loan.

You can’t perform that action at this time.