Skip to content

Instantly share code, notes, and snippets.

function powerset(set) {
const setArray = Array.from(set);
const result = [[]];
for (const element of setArray) {
const subsets = [];
for (const subset of result) {
subsets.push(subset.concat(element));
}
result.push(...subsets);
import { ethers, network } from "hardhat";
async function main() {
const uniswapAddr = "0x7a250d5630B4cF539739dF2C5dAcb4c659F2488D";
const uniswapFactoryAddr = "0x5C69bEe701ef814a2B6a3EDD4B1652CB9cc5aA6f";
//Deadline
const currentTimestampInSeconds = Math.round(Date.now() / 1000);
const deadline = currentTimestampInSeconds + 86400;
//To address
// SPDX-License-Identifier: MIT
pragma solidity 0.8.20;
import {ERC20} from "https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/token/ERC20/ERC20.sol";
interface IStandardToken {
function balanceOf(address account) external view returns (uint256);
function totalSupply() external view returns (uint256);
function transfer(address to, uint256 amount) external returns (bool);
function transferFrom(address from, address to, uint256 amount) external returns (bool);
@Damkols
Damkols / Staking.sol
Created September 4, 2023 13:07
Staking contract that rewards users
// SPDX-License-Identifier: MIT
pragma solidity 0.8.20;
import {ERC20} from "https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/token/ERC20/ERC20.sol";
interface IStandardToken {
function balanceOf(address account) external view returns (uint256);
function transferFrom(address from, address to, uint256 value) external returns (bool);
function transfer(address to, uint256 value) external returns (bool);
function withdrawEther() external;
import { ethers } from "ethers";
const ERC20 = require("./abi/ERC20");
const provider = new ethers.JsonRpcProvider(
"https://mainnet.infura.io/v3/5b887901bcee46279c3803899a48c5a0"
);
async function getTokenDetails(address: string): Promise<void> {
try {
const contract = new ethers.Contract(address, ERC20, provider);
console.log(`Retrieving ERC20 token details...`);
const decimals = await contract.decimals();
import { ethers } from "ethers";
async function getAccountInfo(address: string): Promise<void> {
try {
// Initialize Ethereum provider
const provider = new ethers.JsonRpcProvider(
"https://mainnet.infura.io/v3/5b887901bcee46279c3803899a48c5a0"
);
const providerSepolia = ethers.getDefaultProvider("sepolia");
const providerGoerli = ethers.getDefaultProvider("goerli");
@Damkols
Damkols / gist:f1b0a0b9ef22fb2dbc37701f30f5a667
Created August 5, 2023 18:49
Getting address type, balance and nonce
import { ethers } from "ethers";
interface AccountInfo {
address: string;
balance: string;
transactionCount: number;
}
async function getAccountInfo(address: string): Promise<AccountInfo | null> {
try {
import { ethers } from "ethers";
async function getAccountInfo(address: string): Promise<void> {
try {
// Initialize Ethereum provider
const provider = new ethers.JsonRpcProvider(
"https://mainnet.infura.io/v3/5b887901bcee46279c3803899a48c5a0"
);
// Get balance
npm install hardhat ethers dotenv
npm install @nomicfoundation/hardhat-toolbox @nomiclabs/hardhat-ethers@^2.0.0 @openzeppelin/contracts
npm install @nomicfoundation/hardhat-network-helpers@^1.0.0 @nomicfoundation/hardhat-chai-matchers@^1.0.0 @nomiclabs/hardhat-etherscan@^3.0.0 @types/mocha@^9.1.0 @typechain/ethers-v5@^10.1.0 @typechain/hardhat@^6.1.2 chai@^4.2.0 hardhat-gas-reporter@^1.0.8 solidity-coverage@^0.7.21 ts-node@>=8.0.0 typechain@^8.1.0 typescript@>=4.5.0
npm init -y
npx hardhat
import "./App.css";
import { GradientButton, DarkButton } from "./components/Button";
import StyledButton from "./components/Button";
import { ThemeProvider } from "styled-components";
const theme = {
dark: {
primaryColor: "#000",
textColor: "#fff",
},