您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

recover.ts 3.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. import * as dotevnv from "dotenv"
  2. import {toUtf8String,parseUnits,ContractFactory, parseEther,JsonRpcProvider, Contract, JsonRpcSigner, Wallet,ContractTransactionResponse, MaxInt256
  3. ,Transaction,formatEther,
  4. ZeroHash,ethers,keccak256
  5. } from 'ethers'
  6. // import {ethers} from 'hardhat';
  7. // import {Calulator} from "../inc/calc";
  8. import {
  9. SecurityToken,
  10. SecurityToken__factory,
  11. } from '../typechain'
  12. import { HardhatEthersSigner } from "@nomicfoundation/hardhat-ethers/signers";
  13. import {checkReceipt,checkReceipt2, setProvider,getDeploymentAddresses, getElapsed, sleep} from '../inc/util'
  14. import { stringify } from "querystring";
  15. import { sign } from "crypto";
  16. dotevnv.config();
  17. if (!process.env.RPCURL) {
  18. console.log(`No rpcur value specified...`)
  19. }
  20. console.log(`목적 서버 : ${process.env.RPCURL}`);
  21. async function getNonce(addr: string): Promise<number> {
  22. const nonce = await provider.getTransactionCount(addr);
  23. return nonce;
  24. }
  25. async function sendDirect(wallet: Wallet, to: string, amount: string,nonce: number) : Promise<string> {
  26. //const wallet = new Wallet(fromKey);
  27. //console.log(`sender = ${wallet.address}`);
  28. const tx = {
  29. to: to,
  30. value: parseEther(amount.toString()),
  31. gas: 800000000000,
  32. gasLimit: 21000000000, //21000으로 고정권장(너무 높으면 속도가 느려짐)
  33. maxPriorityFeePerGas: parseUnits("5","gwei"),
  34. maxFeePerGas: parseUnits("20", "gwei"),
  35. nonce: nonce,
  36. type: 2,
  37. chainId: 1337, // Corresponds to ETH_GOERLI
  38. };
  39. const signed = await wallet.signTransaction(tx);
  40. const txid = await provider.send('eth_sendRawTransaction',[signed]);
  41. return txid;
  42. }
  43. async function Recover(privKey: string , count: number,nc: number = 0) {
  44. // let from = '0xfe3b557e8fb62b89f4916b721be55ceb828dbd73';
  45. // let fromKey = '0x8f2a55949038a9610f50fb23b5883af3b4ecb3c3bb792cbcefbd1542c692be63';
  46. const wallet = new Wallet(privKey);
  47. const from = wallet.address;
  48. let to = '0x627306090abaB3A6e1400e9345bC60c78a8BEf57';
  49. let nonce = nc;
  50. if(nonce == 0)
  51. nonce = await getNonce(from);
  52. let txids = [];
  53. let startTime = 0;
  54. for(let i = 0; i < count; i++) {
  55. try {
  56. console.log(`nonce = ${nonce}`);
  57. let txid = await sendDirect(wallet,to,'0.1',nonce++);
  58. // start time setting
  59. if(i == 0) {
  60. startTime = Date.now();
  61. }
  62. // console.log(txid);
  63. txids.push({txid});
  64. } catch(ex) {
  65. console.log(ex);
  66. //break;
  67. }
  68. }
  69. // let txid = await sendTx(to,'0.1',nonce++);
  70. await checkReceipt(txids, 'check receipt....');
  71. let tx = await provider.send('eth_getTransactionByHash',[txids[0].txid]);
  72. const firstBlock = await provider.getBlock(tx.blockNumber);
  73. tx = await provider.send('eth_getTransactionByHash',[txids[count-1].txid]);
  74. const lastBlock = await provider.getBlock(tx.blockNumber);
  75. }
  76. const rpcUrl = process.env.RPCURL;
  77. const provider = new JsonRpcProvider(rpcUrl);
  78. setProvider(provider);
  79. async function main() {
  80. console.log('recover... pending nonce');
  81. Recover('0x8f2a55949038a9610f50fb23b5883af3b4ecb3c3bb792cbcefbd1542c692be63',100);
  82. // for(let i = 13489; i < 13492; i++ ) {
  83. // try {
  84. // await send(i);
  85. // } catch(ex) {
  86. // console.log(ex);
  87. // }
  88. // await sleep(10);
  89. // }
  90. }
  91. main();