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.

30 lines
641 B

1 month ago
  1. ---
  2. title: eth_requestAccounts
  3. description: 连接钱包
  4. ---
  5. ---
  6. ### 参数
  7. - 该方法不接受任何参数
  8. ---
  9. ### 返回值
  10. - <div>AddressList<span style={{marginLeft:10,color:'#707070'}}>array</span></div>
  11. ---
  12. ### Request
  13. ```js
  14. async function connectWallet() {
  15. if (window.ethereum) {
  16. try {
  17. const accounts = await window.ethereum.request({ method: 'eth_requestAccounts' });
  18. console.log('钱包连接成功',accounts);
  19. } catch (error) {
  20. console.error('用户拒绝了连接请求', error);
  21. }
  22. } else {
  23. console.error('请安装 MetaMask 钱包');
  24. }
  25. }
  26. ```