连接小狐狸钱包
const getAddressa = async (res) => {
if (window.ethereum) {
try {
// 请求账号授权
const provider = new ethers.providers.Web3Provider(window.ethereum)
await provider.send("eth_requestAccounts", []);
const signer = provider.getSigner()
return {provider,signer};
} catch (error) {}
}
};
//获取地址签证
const open = async () => {
const {provider,signer} = await getAddressa();
stote.provider = provider
stote.signer=signer
stote.Address = await toRaw(stote.signer).getAddress();
console.log(stote.Address);
};
//查询余额
const select =async () => {
stote.balance= await toRaw(stote.provider).getBalance(stote.Address);
stote.balance=ethers.utils.formatEther(stote.balance.toString())
console.log(stote.balance);
};
//交易
const go = async() => {
let amount = ethers.utils.parseEther(numberser.value);
let tx = await toRaw(stote.signer).sendTransaction({
to: toAddress.value,
value: amount,
gasLimit: 21000,
gasPrice: ethers.utils.parseUnits("10", "gwei"),
});
console.log(tx);
};