test_contract_monad.mjs 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. import { ethers } from 'ethers';
  2. const providerUrl = 'https://testnet-rpc.monad.xyz';
  3. const provider = new ethers.JsonRpcProvider(providerUrl);
  4. const privateKeyList = [
  5. '2a185eae14ca82ac934a5f952e12e0d4a64043c911c33a19afd48ef1a1d70c46',
  6. // Add more private keys here
  7. // 'your_second_private_key',
  8. // 'your_third_private_key',
  9. ];
  10. const stakingContractAddress = '0xcBE623D259261FFa0CFAff44484bFF46c1b7D6c2';
  11. // Function to generate random delay between 5-10 seconds
  12. const getRandomDelay = () => {
  13. return Math.floor(Math.random() * (10000 - 5000 + 1)) + 5000;
  14. };
  15. // Function to handle staking for a single wallet
  16. async function stakeMon(wallet) {
  17. try {
  18. const balance = await provider.getBalance(wallet.address);
  19. console.log(`Wallet ${wallet.address} balance:`, ethers.formatEther(balance));
  20. const amountToStake = ethers.parseEther('0');
  21. if (balance < amountToStake) {
  22. throw new Error(`Insufficient balance for staking in wallet ${wallet.address}`);
  23. }
  24. const tx = await wallet.sendTransaction({
  25. to: stakingContractAddress,
  26. value: amountToStake,
  27. data: '0x7ab71841',
  28. gasLimit: 1000000,
  29. gasPrice: ethers.parseUnits('52', 'gwei')
  30. });
  31. console.log(`Stake transaction hash for ${wallet.address}:`, tx.hash);
  32. const receipt = await tx.wait();
  33. console.log(`Stake transaction receipt for ${wallet.address}:`, receipt);
  34. } catch (error) {
  35. console.error(`Error staking $MON for ${wallet.address}:`, error);
  36. }
  37. }
  38. // Function to process all wallets with delay
  39. async function processAllWallets() {
  40. for (const privateKey of privateKeyList) {
  41. const wallet = new ethers.Wallet(privateKey, provider);
  42. await stakeMon(wallet);
  43. // Add random delay between 5-10 seconds, except for the last wallet
  44. if (privateKey !== privateKeyList[privateKeyList.length - 1]) {
  45. const delay = getRandomDelay();
  46. console.log(`Waiting ${delay/1000} seconds before next wallet...`);
  47. await new Promise(resolve => setTimeout(resolve, delay));
  48. }
  49. }
  50. }
  51. processAllWallets();