export function addrTo32Bytes(addr: string): Buffer {
const hex20 = ethers.utils.getAddress(addr).slice(2);
const padded = hex20.padStart(64, "0"); // 32 bytes ⇒ 64 hex
return Buffer.from(padded, "hex"); // length === 32
}
async function main() {
const [owner] = await ethers.getSigners();
const SEPOLIA_USDT0 = "0xc4DCC311c028e341fd8602D8eB89c5de94625927";
const SEPOLIA_USDT0_OAPP = "0xc099cD946d5efCC35A99D64E808c1430cEf08126"
const RECEIVER_EID = 40374;
const usdt0 = await ethers.getContractAt("ERC20", SEPOLIA_USDT0);
await usdt0.approve(SEPOLIA_USDT0_OAPP, ethers.utils.parseEther("1"));
const options = Options.newOptions().addExecutorLzReceiveOption(0, 0).toBytes();
const amount = ethers.utils.parseEther("1"); // 将此更改为您所需的数量
const OFTAdapter = await ethers.getContractAt("OFTAdapter", SEPOLIA_USDT0_OAPP);
const sendParams = {
dstEid: RECEIVER_EID,
to: addrTo32Bytes(owner.address),
amountLD: amount,
minAmountLD: amount,
extraOptions: options,
composeMsg: Buffer.from(""),
oftCmd: Buffer.from(""),
};
const fee = await OFTAdapter.quoteSend(sendParams, false);
await OFTAdapter.send(
sendParams,
fee,
owner.address,
{
value: fee.nativeFee,
}
)
}