You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
39 lines
1.2 KiB
39 lines
1.2 KiB
// import { ethers } from 'ethers';
|
|
import { ethers } from "https://cdn-cors.ethers.io/lib/ethers-5.6.9.esm.min.js";
|
|
|
|
// 设置 RPC URL
|
|
const providerUrl = 'https://dream-rpc.somnia.network';
|
|
const provider = new ethers.JsonRpcProvider(providerUrl);
|
|
|
|
// 替换为您的钱包私钥(发送方钱包)
|
|
const privateKey = '0x3991542110242368f4770716be904b0ca6d44a8dbe4501771833b1a3642198d1'; // 私钥
|
|
const wallet = new ethers.Wallet(privateKey, provider);
|
|
|
|
// 接收方钱包地址
|
|
const recipientAddress = '0x70D5EE1DfddD3726f0D71F4CD5a8ef43aC651a75';
|
|
|
|
// 发送代币的函数
|
|
async function sendToken() {
|
|
try {
|
|
const amountToSend = ethers.parseEther('0.0000000000001'); // 发送数量
|
|
|
|
// 构造交易对象
|
|
const tx = {
|
|
to: recipientAddress,
|
|
value: amountToSend
|
|
};
|
|
|
|
// 发送交易
|
|
const txResponse = await wallet.sendTransaction(tx);
|
|
console.log('Transaction hash:', txResponse.hash);
|
|
|
|
// 等待交易确认
|
|
const receipt = await txResponse.wait();
|
|
console.log('Transaction receipt:', receipt);
|
|
} catch (error) {
|
|
console.error('Error sending Token:', error);
|
|
}
|
|
}
|
|
|
|
// 调用发送Token的函数
|
|
sendToken(); |