1. 连接小狐狸钱包
    2. const getAddressa = async (res) => {
    3. if (window.ethereum) {
    4. try {
    5. // 请求账号授权
    6. const provider = new ethers.providers.Web3Provider(window.ethereum)
    7. await provider.send("eth_requestAccounts", []);
    8. const signer = provider.getSigner()
    9. return {provider,signer};
    10. } catch (error) {}
    11. }
    12. };
    13. //获取地址签证
    14. const open = async () => {
    15. const {provider,signer} = await getAddressa();
    16. stote.provider = provider
    17. stote.signer=signer
    18. stote.Address = await toRaw(stote.signer).getAddress();
    19. console.log(stote.Address);
    20. };
    21. //查询余额
    22. const select =async () => {
    23. stote.balance= await toRaw(stote.provider).getBalance(stote.Address);
    24. stote.balance=ethers.utils.formatEther(stote.balance.toString())
    25. console.log(stote.balance);
    26. };
    27. //交易
    28. const go = async() => {
    29. let amount = ethers.utils.parseEther(numberser.value);
    30. let tx = await toRaw(stote.signer).sendTransaction({
    31. to: toAddress.value,
    32. value: amount,
    33. gasLimit: 21000,
    34. gasPrice: ethers.utils.parseUnits("10", "gwei"),
    35. });
    36. console.log(tx);
    37. };