Skip to content

Instantly share code, notes, and snippets.

View hayesgm's full-sized avatar

Geoff Hayes hayesgm

View GitHub Profile

Overview

To understand how constructors through Solidity works (that is, how do we go from the compiled contract's bin to a live deployed contract with a different deployedBytecode), I took a deep dive into how one simple contract worked.

The contract Simple.sol:

pragma solidity ^0.5.12;

contract Simple {
let Eth = {
read: (network, contract, fn, args, ethers=require('ethers')) =>
Object.entries(
new ethers.Contract(
contract,
[fn],
new ethers.providers.InfuraProvider(network)
).functions
)[0][1](...args),
write: (network, contract, fn, args, pk=process.env('ethereum'), ethers=require('ethers')) =>
pragma solidity ^0.6.8;
interface Comptroller {
function getCompAddress() external view returns (address);
function claimComp(address holder) external;
function transfer(address dst, uint256 amount) external returns (bool success);
}
interface Erc20 {
function symbol() external returns (string memory);
@hayesgm
hayesgm / flat.js
Last active September 9, 2020 20:16
#!env node
let path = require('path');
let fs = require('fs').promises;
async function run(build, contract) {
let buildJson = JSON.parse(await fs.readFile(build, 'utf8'));
let contracts = buildJson['contracts'];
@hayesgm
hayesgm / download.js
Last active March 4, 2021 07:23
Download File JS (No Deps)
const fs = require('fs').promises;
const path = require('path');
const http = require('http');
const https = require('https');
const { URL } = require('url');
function getOptions(url) {
let u = new URL(url);
return {
host: u.hostname,
QmSwPdeQcqfJ8w6eBUo8UcW4s2jk9ZRKGQ8t29WpL8Zukv