@pintswap-v3/awgmi
v1.0.1
Published
## Install
Downloads
5
Readme
@pintswap-v3/awgmi
Install
pnpm i @pintswap-v3/awgmi @tanstack/react-query
Connect to Aptos with similar wagmi React hooks.
Support Aptos Wallet Connectors:
- Petra
- Martian
- Pontem
- Fewcha
- SafePal
- Trust Wallet
- Msafe
import { createClient, AwgmiConfig, useConnect, getDefaultProviders, defaultChains } from '@pintswap-v3/awgmi'
import { QueryClient, QueryClientProvider } from '@tanstack/react-query'
import { PetraConnector } from '@pintswap-v3/awgmi/connectors/petra'
import { MartianConnector } from '@pintswap-v3/awgmi/connectors/martain'
import { SafePalConnector } from '@pintswap-v3/awgmi/connectors/safePal'
import { BloctoConnector } from '@pintswap-v3/awgmi/connectors/blocto'
import { FewchaConnector } from '@pintswap-v3/awgmi/connectors/fewcha'
// import { mainnet, testnet } from '@pintswap-v3/awgmi/core'
const chains = defaultChains // mainnet, testnet, devnet
const queryClient = new QueryClient({
defaultOptions: {
queries: {
gcTime: 1_000 * 60 * 60 * 24, // 24 hours
networkMode: 'offlineFirst',
refetchOnWindowFocus: false,
retry: 0,
},
mutations: {
networkMode: 'offlineFirst',
},
},
})
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}>
<QueryClientProvider client={queryClient}>
<YourApp />
</QueryClientProvider>
</AwgmiConfig>
)
}
Connector
import { useConnect, useDisconnect } from '@pintswap-v3/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 '@pintswap-v3/awgmi'
Balance
const { data } = useAccountBalance({
address: Address,
coin: '0x1::aptos_coin::AptosCoin',
watch: true,
})
Send Transaction
import { UserRejectedRequestError } from '@pintswap-v3/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
})