| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115 |
- import * as dotevnv from "dotenv"
- import {toUtf8String,parseUnits,ContractFactory, parseEther,JsonRpcProvider, Contract, JsonRpcSigner, Wallet,ContractTransactionResponse, MaxInt256
- ,Transaction,formatEther,
- ZeroHash,ethers,keccak256
- } from 'ethers'
- // import {ethers} from 'hardhat';
- // import {Calulator} from "../inc/calc";
-
- import {
- SecurityToken,
- SecurityToken__factory,
- } from '../typechain'
- import { HardhatEthersSigner } from "@nomicfoundation/hardhat-ethers/signers";
- import {checkReceipt,checkReceipt2, setProvider,getDeploymentAddresses, getElapsed, sleep} from '../inc/util'
- import { stringify } from "querystring";
- import { sign } from "crypto";
- dotevnv.config();
- if (!process.env.RPCURL) {
- console.log(`No rpcur value specified...`)
- }
-
-
- console.log(`목적 서버 : ${process.env.RPCURL}`);
-
- async function getNonce(addr: string): Promise<number> {
- const nonce = await provider.getTransactionCount(addr);
- return nonce;
- }
-
-
- async function sendDirect(wallet: Wallet, to: string, amount: string,nonce: number) : Promise<string> {
- //const wallet = new Wallet(fromKey);
- //console.log(`sender = ${wallet.address}`);
- const tx = {
- to: to,
- value: parseEther(amount.toString()),
- gas: 800000000000,
- gasLimit: 21000000000, //21000으로 고정권장(너무 높으면 속도가 느려짐)
- maxPriorityFeePerGas: parseUnits("5","gwei"),
- maxFeePerGas: parseUnits("20", "gwei"),
- nonce: nonce,
- type: 2,
- chainId: 1337, // Corresponds to ETH_GOERLI
- };
- const signed = await wallet.signTransaction(tx);
- const txid = await provider.send('eth_sendRawTransaction',[signed]);
- return txid;
- }
-
- async function Recover(privKey: string , count: number,nc: number = 0) {
- // let from = '0xfe3b557e8fb62b89f4916b721be55ceb828dbd73';
- // let fromKey = '0x8f2a55949038a9610f50fb23b5883af3b4ecb3c3bb792cbcefbd1542c692be63';
- const wallet = new Wallet(privKey);
- const from = wallet.address;
- let to = '0x627306090abaB3A6e1400e9345bC60c78a8BEf57';
-
- let nonce = nc;
- if(nonce == 0)
- nonce = await getNonce(from);
-
-
- let txids = [];
-
-
- let startTime = 0;
-
- for(let i = 0; i < count; i++) {
- try {
- console.log(`nonce = ${nonce}`);
- let txid = await sendDirect(wallet,to,'0.1',nonce++);
- // start time setting
- if(i == 0) {
- startTime = Date.now();
- }
- // console.log(txid);
- txids.push({txid});
- } catch(ex) {
- console.log(ex);
- //break;
- }
-
- }
-
- // let txid = await sendTx(to,'0.1',nonce++);
- await checkReceipt(txids, 'check receipt....');
-
- let tx = await provider.send('eth_getTransactionByHash',[txids[0].txid]);
- const firstBlock = await provider.getBlock(tx.blockNumber);
-
- tx = await provider.send('eth_getTransactionByHash',[txids[count-1].txid]);
- const lastBlock = await provider.getBlock(tx.blockNumber);
- }
-
-
- const rpcUrl = process.env.RPCURL;
- const provider = new JsonRpcProvider(rpcUrl);
- setProvider(provider);
-
- async function main() {
-
- console.log('recover... pending nonce');
- Recover('0x8f2a55949038a9610f50fb23b5883af3b4ecb3c3bb792cbcefbd1542c692be63',100);
- // for(let i = 13489; i < 13492; i++ ) {
- // try {
- // await send(i);
- // } catch(ex) {
- // console.log(ex);
- // }
- // await sleep(10);
- // }
-
- }
-
- main();
|