Skip to content

Instantly share code, notes, and snippets.

View wwarodom's full-sized avatar

Warodom Werapun wwarodom

View GitHub Profile
@wwarodom
wwarodom / page.tsx
Last active March 25, 2024 04:49
Todo list
'use client';
import { useState } from "react"
export default function Todo() {
const [todos, setTodos] = useState([
{ id: 1, name: "Go to Fitness", time: 1.5 },
{ id: 2, name: "Have lunch", time: 1 },
{ id: 3, name: "Writing code", time: 2 },
@wwarodom
wwarodom / Token.sol
Last active June 26, 2022 04:53
Create Token and Admin transfer
// SPDX-License-Identifier: MIT
// File: @openzeppelin/contracts/utils/Context.sol
// OpenZeppelin Contracts v4.4.1 (utils/Context.sol)
pragma solidity ^0.8.0;
/**
@wwarodom
wwarodom / Dog.sol
Created June 9, 2022 16:23
Create and Create2 with Dog Example
//SPDX-License-Identifier: MIT
pragma solidity ^0.8.14;
import "@openzeppelin/contracts/utils/Create2.sol";
contract Dog {
uint8 public age;
constructor(uint8 _age) {
age = _age;
}
}
@wwarodom
wwarodom / Hello-ether.js
Created April 4, 2022 03:30
Read - write - ethers transfer contract example
import { useState, useEffect } from 'react'
import {ethers} from 'ethers';
// import './App.css'
const ADDRESS = "0x95657033f1aafebd1fd539de36964ce0e1eb1cfe";
const ABI = [
{
"inputs": [],
"name": "donate",
"outputs": [],
@wwarodom
wwarodom / lineNotification.js
Last active March 21, 2022 09:48
Line Notification Backend (NextJS) pages/api/index.js
// Next.js API route support: https://nextjs.org/docs/api-routes/introduction
// ./pages/api/index.js
// dependency: npm i -s line-notify-nodejs
// You can get Token URL here:
// https://notify-bot.line.me/my/
// Generate token and copy it
const lineNotify = require('line-notify-nodejs')('ap...REPLACE WITH YOUR TOKEN....JY');
export default async function handler(req, res) {
const message = "Send test 12";
@wwarodom
wwarodom / websocket.js
Created March 21, 2022 09:01
Pull Cryprice from Binance WebSocket (NextJS)
import { useState, useEffect } from 'react';
let isStop = false;
export default function Home() {
const [price, setPrice] = useState(0);
useEffect(() => {
const ws = new WebSocket("wss://stream.binance.com:9443/ws/btcusdt@trade");
@wwarodom
wwarodom / Create2Example.sol
Created March 9, 2022 13:13
Put this example in Remix
// Create2: Pre-compute contract address, we can knew deployed contract address, cannot duplicated deploy)
// Get bytecode of contract to be deploy
// creationCode => bytecode using contract deployment
// runtimeCode => bytecode using runtime
// bytes memory contract_byte = type(Dog).creationCode
// ต่อด้วย constructor parameter: abi.encode(_age)
// abi.encodePacked(type(Dog).creationCode, abi.encode(_age))
@wwarodom
wwarodom / MySwap.sol
Created October 27, 2021 14:32
Swap contract DAI -> USDC -> WETH9
// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity 0.7.6;
pragma abicoder v2;
import "../libraries/TransferHelper.sol";
import "../interfaces/ISwapRouter.sol";
contract MySwap {
// For the scope of these swap examples,
// we will detail the design considerations when using
@wwarodom
wwarodom / deploy-swap-contract.ts
Created October 27, 2021 14:29
Swap by contract to call swap router
import { parseEther } from "@ethersproject/units";
import { constants } from "ethers";
import { ethers } from "hardhat";
import { ERC20__factory } from "../typechain";
import { MySwap } from "../typechain";
async function main() {
const factory = await ethers.getContractFactory("MySwap");
const contract: MySwap = (await factory.deploy()) as MySwap;
@wwarodom
wwarodom / swap-by-router.ts
Created October 27, 2021 14:26
Swap token with swap Router
import { constants } from "ethers";
import { ethers } from "hardhat";
import { ERC20__factory, SwapRouter__factory } from "../typechain";
import { parseFixed } from "@ethersproject/bignumber";
async function main() {
const SWAP_V3_ROUTER = "0xE592427A0AEce92De3Edee1F18E0157C05861564";
const DAI = "0x5592ec0cfb4dbc12d3ab100b257153436a1f0fea";