React:Dapp开发

AptosWallet:@manahippo/aptos-wal

2022-10-21  本文已影响0人  精神病患者link常

安装

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()
上一篇下一篇

猜你喜欢

热点阅读