美文网首页React:Dapp开发
AptosWallet:@manahippo/aptos-wal

AptosWallet:@manahippo/aptos-wal

作者: 精神病患者link常 | 来源:发表于2022-10-21 21:58 被阅读0次

    安装

    yarn add @manahippo/aptos-wallet-adapter

    使用

    
    # 官方地址
    - https://www.npmjs.com/package/@manahippo/aptos-wallet-adapter
    
    # AptosWallet开源项目地址
    - https://github.com/hippospace/hippo-frontend
    - https://github.com/Amovane/aptos-NFT-marketplace
    - https://github.com/martian-dao/aptos-nft-marketplace
    
    # Aptos学习
    - https://fullnode.devnet.aptoslabs.com/v1/spec#/operations/get_account
    - https://aptos.dev/
    
    import {
      HippoWalletAdapter,
      WalletProvider,
      AptosWalletAdapter,
      HippoExtensionWalletAdapter,
      MartianWalletAdapter,
      FewchaWalletAdapter,
      PontemWalletAdapter,
      SpikaWalletAdapter,
      RiseWalletAdapter,
      FletchWalletAdapter,
    } from '@manahippo/aptos-wallet-adapter';
    const wallets = [
      new HippoWalletAdapter(),
      new MartianWalletAdapter(),
      new AptosWalletAdapter(),
      new FewchaWalletAdapter(),
      new HippoExtensionWalletAdapter(),
      new PontemWalletAdapter(),
      new SpikaWalletAdapter(),
      new RiseWalletAdapter(),
      new FletchWalletAdapter(),
    ];
    <WalletProvider
    wallets={wallets}
    autoConnect={true} /** allow auto wallet connection or not **/
    onError={(error: Error) => {
      console.log('Handle Error Message', error);
    }}>
      <Provider store={store}>
        ...
      </Provider>
    </WalletProvider>
    

    钱包操作

    import { useWallet,Wallet } from '@manahippo/aptos-wallet-adapter';
    const walletInfo = useWallet()
    /*
      ** walletInfo **
    
      wallets: Wallet[]; - Array of wallets
      wallet: Wallet | null; - Selected wallet
      account: AccountKeys | null; - Wallet info: address, 
      network: NetworkInfo - { name, chainId, api }
      publicKey, authKey
      connected: boolean; - check the website is connected yet
      connect(walletName: string): Promise<void>; - trigger connect popup
      disconnect(): Promise<void>; - trigger disconnect action
      signAndSubmitTransaction(
        transaction: TransactionPayload
      ): Promise<PendingTransaction>; - function to sign and submit the transaction to chain
    */
    
    • 链接钱包
    async function onConnect(){
        let installName = ''
        // wallets 所有的钱包列表
        walletInfo.wallets.map((wallet: Wallet, i) => {
          // 如果安装了一个钱包,直接链接
          if (wallet.readyState == 'Installed'){
            installName = wallet.adapter.name
          }
        })
        if (installName){
          // 📢📢📢📢📢📢📢📢注意链接是 select 不是connect.........
          await walletInfo.select(installName)
        }else {
          message.warn('Install Aptos Wallet')
        }
      }
    
    • 断开钱包
    await walletInfo.disconnect()
    

    相关文章

      网友评论

        本文标题:AptosWallet:@manahippo/aptos-wal

        本文链接:https://www.haomeiwen.com/subject/ldmbzrtx.html