test_send_monad_token.mjs 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. import { ethers } from 'ethers';
  2. // 替换为您的节点URL
  3. const providerUrl = 'https://testnet-rpc.monad.xyz';
  4. const provider = new ethers.JsonRpcProvider(providerUrl);
  5. // 替换为您的钱包私钥(发送方钱包)
  6. const privateKey = '0x3991542110242368f4770716be904b0ca6d44a8dbe4501771833b1a3642198d1'; // 私钥
  7. const wallet = new ethers.Wallet(privateKey, provider);
  8. // 接收方钱包地址
  9. const recipientAddress = '0x70D5EE1DfddD3726f0D71F4CD5a8ef43aC651a75';
  10. // 发送代币的函数
  11. async function sendToken() {
  12. try {
  13. const amountToSend = ethers.parseEther('0.0000001'); // 发送数量
  14. // 构造交易对象
  15. const tx = {
  16. to: recipientAddress,
  17. value: amountToSend
  18. };
  19. // 发送交易
  20. const txResponse = await wallet.sendTransaction(tx);
  21. console.log('Transaction hash:', txResponse.hash);
  22. // 等待交易确认
  23. const receipt = await txResponse.wait();
  24. console.log('Transaction receipt:', receipt);
  25. } catch (error) {
  26. console.error('Error sending Token:', error);
  27. }
  28. }
  29. // 调用发送Token的函数
  30. sendToken();