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.
 
 
 

46 lines
1.5 KiB

import { ethers } from 'ethers';
// Monad 测试网 RPC URL
const providerUrl = 'https://testnet-rpc.monad.xyz';
const provider = new ethers.JsonRpcProvider(providerUrl);
// 钱包私钥
const privateKey = '0x3991542110242368f4770716be904b0ca6d44a8dbe4501771833b1a3642198d1';
const wallet = new ethers.Wallet(privateKey, provider);
// 质押合约地址
const stakingContractAddress = '0x2c9c959516e9aaedb2c748224a41249202ca8be7';
// 质押 $MON
async function stakeMon() {
try {
// 检查原生代币余额
const balance = await provider.getBalance(wallet.address);
console.log('Native balance:', ethers.formatEther(balance));
// 质押金额
const amountToStake = ethers.parseEther('0.0001'); // 0.0001 原生代币
if (balance < amountToStake) {
throw new Error('Insufficient balance for staking');
}
// 低级调用,发送交易
const tx = await wallet.sendTransaction({
to: stakingContractAddress,
value: amountToStake,
data: '0xd5575982', // 函数选择器
gasLimit: 100000,
gasPrice: ethers.parseUnits('50', 'gwei')
});
console.log('Stake transaction hash:', tx.hash);
// 等待交易确认
const receipt = await tx.wait();
console.log('Stake transaction receipt:', receipt);
} catch (error) {
console.error('Error staking $MON:', error);
}
}
// 调用质押函数
stakeMon();