This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { ethers } from "ethers"; | |
interface AccountInfo { | |
address: string; | |
balance: string; | |
transactionCount: number; | |
} | |
async function getAccountInfo(address: string): Promise<AccountInfo | null> { | |
try { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
NewerOlder