Skip to content

Instantly share code, notes, and snippets.

View petejkim's full-sized avatar
💭
I may be slow to respond.

Pete Kim petejkim

💭
I may be slow to respond.
View GitHub Profile
@petejkim
petejkim / ethereumjs-abi.d.ts
Last active August 24, 2020 23:35
standalone ethereumjs-abi
export function eventID(name: string, types: string[]): Buffer;
export function methodID(name: string, types: string[]): Buffer;
export function rawEncode<Values = any[]>(types: string[], values: T): Buffer;
export function rawDecode<Values = any[]>(
types: string[],
data: Buffer
): Values;
export function simpleEncode<Args = any[]>(
method: string,
...args: Args
@petejkim
petejkim / transferUSDC.js
Created July 14, 2020 21:16
Introduction to Building on DeFi with Ethereum and USDC  - Part 1 - transferUSDC.js
const ethers = require("ethers");
const wallet = require("./wallet");
const provider = require("./provider");
async function main(args) {
const account = wallet.connect(provider);
// Define balanceOf and transfer functions in the contract
const usdc = new ethers.Contract(
"0x68ec573C119826db2eaEA1Efbfc2970cDaC869c4",
@petejkim
petejkim / transferETH.js
Created July 14, 2020 21:12
Introduction to Building on DeFi with Ethereum and USDC  - Part 1 - transferETH.js
const ethers = require("ethers");
const wallet = require("./wallet");
const provider = require("./provider");
async function main(args) {
const account = wallet.connect(provider);
let to, value;
// Parse the first argument - recipient address
try {
@petejkim
petejkim / getBalance.js
Created July 14, 2020 21:06
Introduction to Building on DeFi with Ethereum and USDC  - Part 1 - getBalance.js - 2
const ethers = require("ethers");
const wallet = require("./wallet");
const provider = require("./provider");
async function main() {
const account = wallet.connect(provider);
// Define contract interface
const usdc = new ethers.Contract(
"0x68ec573C119826db2eaEA1Efbfc2970cDaC869c4",
@petejkim
petejkim / getTestnetUSDC.js
Created July 14, 2020 21:03
Introduction to Building on DeFi with Ethereum and USDC  - Part 1 - getTestnetUSDC.js
const ethers = require("ethers");
const wallet = require("./wallet");
const provider = require("./provider");
async function main() {
const account = wallet.connect(provider);
const usdc = new ethers.Contract(
"0x68ec573C119826db2eaEA1Efbfc2970cDaC869c4",
["function gimmeSome() external"],
@petejkim
petejkim / getBalance.js
Created July 14, 2020 21:00
Introduction to Building on DeFi with Ethereum and USDC  - Part 1 - getBalance.js
const ethers = require("ethers");
const wallet = require("./wallet");
const provider = require("./provider");
async function main() {
const account = wallet.connect(provider);
const balance = await account.getBalance();
console.log(`ETH Balance: ${ethers.utils.formatUnits(balance, 18)}`);
}
@petejkim
petejkim / provider.js
Created July 14, 2020 20:57
Introduction to Building on DeFi with Ethereum and USDC  - Part 1 - provider.js
const ethers = require("ethers");
const provider = ethers.getDefaultProvider("ropsten", {
// Replace the following with your own INFURA API key
infura: "0123456789abcdef0123456789abcdef",
});
module.exports = provider;
@petejkim
petejkim / wallet.js
Last active July 14, 2020 20:54
Introduction to Building on DeFi with Ethereum and USDC  - Part 1 - wallet.js
const ethers = require("ethers");
// Replace the following with your own mnemonic
const mnemonic =
"rabbit enforce proof always embrace tennis version reward scout shock license wing";
const wallet = ethers.Wallet.fromMnemonic(mnemonic);
console.log(`Mnemonic: ${wallet.mnemonic.phrase}`);
console.log(`Address: ${wallet.address}`);
@petejkim
petejkim / createWallet.js
Last active July 14, 2020 20:54
Introduction to Building on DeFi with Ethereum and USDC  - Part 1 - createWallet.js
const ethers = require("ethers");
const wallet = ethers.Wallet.createRandom();
console.log(`Mnemonic: ${wallet.mnemonic.phrase}`);
console.log(`Address: ${wallet.address}`);
@petejkim
petejkim / walletlink.ts
Last active August 21, 2019 21:45
WalletLink Snippet