Skip to content

Instantly share code, notes, and snippets.

View swkim109's full-sized avatar
🍊
Stale

swkim109

🍊
Stale
View GitHub Profile
@swkim109
swkim109 / publicKey.js
Last active December 15, 2023 21:41
Public Key
/**
* "@ethereumjs/tx": "^5.1.0",
* "@ethereumjs/util": "^9.0.1",
*/
const { hexToBytes, bytesToHex } = require('@ethereumjs/util');
const { ecrecover } = require('@ethereumjs/util');
const { TransactionFactory } = require('@ethereumjs/tx');
// https://etherscan.io/tx/0x5ad6831e50960ffda005fc59c1970ce8fafaa3cff8b9d6695cd1f65cb3c2acf9
@swkim109
swkim109 / layout.txt
Created March 13, 2023 01:03
mapping storage
mapping 타입의 스토리지 해시
저장되는 슬롯 번호 = keccak256(key || slot No.)
(예)
mapping(address => uint256) public m;
m[0x5B38Da6a701c568545dCfcB03FcB875f56beddC4] = 100;
슬롯번호는
ethers.utils.keccak256("0x0000000000000000000000005B38Da6a701c568545dCfcB03FcB875f56beddC40000000000000000000000000000000000000000000000000000000000000000")
@swkim109
swkim109 / accessList.js
Created February 1, 2023 05:11
AccessList
const abi = [
"function get()",
"function set(uint256)"
];
const interface = new ethers.utils.Interface(abi);
const calldata = interface.encodeFunctionData("set", [10]);
const from = "0xAd36301E8C66bB2Af80c63DA5a99BdF2c202c9a1";
const to = "0x35F61C2b5815426cBA1b1B0385624118391B9C49";
@swkim109
swkim109 / create2.js
Created December 27, 2022 12:02
CREATE2 address
const prefix = "0xff";
const address = "0x13b0D85CcB8bf860b6b79AF3029fCA081AE9beF2";
const salt = "Kate";
const bytecode = "0x608060405260405161031d38038061031d833981810160405281019061002591906100cf565b80600160006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff160217905550506100fc565b600080fd5b600073ffffffffffffffffffffffffffffffffffffffff82169050919050565b600061009c82610071565b9050919050565b6100ac81610091565b81146100b757600080fd5b50565b6000815190506100c9816100a3565b92915050565b6000602082840312156100e5576100e461006c565b5b60006100f3848285016100ba565b91505092915050565b6102128061010b6000396000f3fe60806040526004361061002d5760003560e01c80638da5cb5b146100e0578063928012301461010b57610034565b3661003457005b34801561004057600080fd5b506000600160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff16905060006127109050600080368080601f016020809104026020016040519081016040528093929190818152602001838380828437600081840152601f19601f820116905080830192505050505050
@swkim109
swkim109 / abi.js
Last active November 11, 2023 05:45
Function calldata
const abi = [
"function withdraw(address,uint256)"
];
const iface = new ethers.utils.Interface(abi);
const calldata = iface.encodeFunctionData("withdraw", ["0x0000000000000000000000000000000000000000", ethers.BigNumber.from("10000000000000000")]);
console.log(calldata)
// Solidity
address _addr = 0x0000000000000000000000000000000000000000;
uint256 _val = 100;
@swkim109
swkim109 / rawTx.js
Last active December 7, 2022 10:02
Transaction structure
const ethers = require("ethers");
const jsonRpcProvider = new ethers.providers.JsonRpcProvider("https://goerli.infura.io/v3/");
const privateKey = "5de6...";
const to = "0x547d73355A851079E0395aDB2C647821b74C7eAF"; // Kate
const value = ethers.utils.parseEther("0.003");
const gasLimit = 21000
const maxFeePerGas = 20000000000 //20 gwei
const maxPriorityFeePerGas = 1000000000 //1 gwei
@swkim109
swkim109 / Dockerfile
Created November 12, 2022 11:54
Jenkins docker image
FROM ubuntu:focal
ENV HOME /root
ENV TZ Asia/Seoul
RUN rm /bin/sh && ln -s /bin/bash /bin/sh
RUN echo 'debconf debconf/frontend select Noninteractive' | debconf-set-selections
RUN apt-get update \
&& apt-get install openjdk-11-jdk -y \
@swkim109
swkim109 / convert.js
Created October 15, 2022 01:15
parseEther
// ether를 wei 단위로 변경하기
ethers.utils.parseEther("0.000001").toString();
// 임의의 단위를 wei 단위로 변경하기
ethers.utils.parseUnits("0.000001", "ether").toString();
ethers.utils.parseUnits("1", "gwei").toString();
ethers.utils.parseUnits("1", "mwei").toString();
ethers.utils.parseUnits("1", "kwei").toString();
// wei를 임의의 단위로 변경하기
@swkim109
swkim109 / blocks.txt
Last active October 11, 2022 01:47
Werrd Block
// 엉클 블록 포함
https://etherscan.io/block/15489644
// 트랜잭션이 하나도 없는 블록
https://etherscan.io/block/12987627
https://www.blockchain.com/btc/block/492972
// 트랜잭션이 하나 뿐인 블록
https://etherscan.io/block/14401440
@swkim109
swkim109 / timer.js
Created September 7, 2022 00:55
Timer
const timer = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
(async () => {
await timer(5000);
})();