Skip to content

Latest commit

 

History

History
 
 

awgmi

@pancakeswap/awgmi

Connect to Aptos with similar wagmi React hooks.

Support Aptos Wallet Connectors:

  • Petra
  • Martian
  • Pontem
  • Fewcha
  • SafePal
  • Trust Wallet
import {
  createClient,
  AwgmiConfig,
  useConnect,
  getDefaultProviders,
  defaultChains,
} from '@pancakeswap/awgmi';
import { PetraConnector } from '@pancakeswap/awgmi/connectors/petra'
import { MartianConnector } from '@pancakeswap/awgmi/connectors/martain'
import { SafePalConnector } from '@pancakeswap/awgmi/connectors/safePal'
import { BloctoConnector } from '@pancakeswap/awgmi/connectors/blocto'
import { FewchaConnector } from '@pancakeswap/awgmi/connectors/fewcha'

 // import { mainnet, testnet } from '@pancakeswap/awgmi/core'
const chains = defaultChains // mainnet, testnet, devnet

export const client = createClient({
  connectors: [
    new PetraConnector({ chains }),
    new MartianConnector({ chains }),
    new PetraConnector({ chains, options: { name: 'Trust Wallet', id: 'trustWallet' } }),
    new SafePalConnector({ chains }),
    new BloctoConnector({ chains, options: { appId: BLOCTO_APP_ID } }),
    new FewchaConnector({ chains }),
  ],
  provider: getDefaultProviders,
  autoConnect: true,
});


function App() {
  return (
    <AwgmiConfig client={client}>
      <YourApp />
    </AwgmiConfig>
  )
}

Connector

import { useConnect, useDisconnect } from '@pancakeswap/awgmi'

function ConnectButton() {
  const { connect, connectors } = useConnect()

  return (
    <div>
      {connectors.map((connector) => (
        <button type="button" key={connector.id} onClick={() => connect({ connector, networkName: 'mainnet' })}>
          {connector.name}
        </button>
      ))}
    </div>
  )
}

Hooks

import {
  useAccountBalance,
  useAccountBalances,
  useAccountResource,
  useAccountResources,
  useCoin,
  useCoins,
  useNetwork,
  useSendTransaction,
  useSimulateTransaction,
  useTableItem,
} from '@pancakeswap/awgmi'

Balance

const { data } = useAccountBalance({
  address: Address,
  coin: '0x1::aptos_coin::AptosCoin',
  watch: true
})

Send Transaction

import { UserRejectedRequestError } from '@pancakeswap/awgmi'

const { sendTransactionAsync } = useSendTransaction()

sendTransactionAsync({
  payload: {
    type: 'entry_function_payload',
    function: '<address>::message::set_message',
    arguments: ['are we gonna make it?'],
    type_arguments: [],
  },
}).catch(err => {
  if (err instanceof UserRejectedRequestError) {
    // handle user reject
  }
  // handle transaction error
})