Aptos-AIP-62
AIP-62 standard is a new standard officially introduced by Aptos. It is a set of chain-agnostic interfaces and conventions designed to improve the interaction between applications and injected wallets. It uses the Wallet Standard method to detect installed wallets and automatically display a list of connectable wallets. AIP-62 also upgrades the data interfaces for interaction between DApps and wallets, such as the encapsulated RawTransaction, etc.
In the near future, as wallets adopt the new standard, wallet adapters will deprecate the old standard and only retain support for the AIP-62 wallet standard.
When running a DApp in the Bitget Wallet App or in the Chrome browser with the Chrome Extension installed, the app can achieve wallet injection by wrapping AptosWalletAdapterProvider.
import { AptosWalletAdapterProvider } from "@aptos-labs/wallet-adapter-react";
<AptosWalletAdapterProvider autoConnect>
<App />
</AptosWalletAdapterProvider>;Wallet Basic Method
Get wallet list
DApps can directly use hooks to get the list of wallets registered via registerWallet:
import { useWallet } from "@aptos-labs/wallet-adapter-react";
const { wallets } = useWallet(); // [{name: 'Bitget Wallet', icon: '...'}]Connect Wallet
Pass the wallet name to the connect method to connect to a specified wallet:
Parameters
name- string:wallet name
import { useWallet } from "@aptos-labs/wallet-adapter-react";
const { connect } = useWallet(); // [{name: 'Bitget Wallet', icon: '...'}]
await connect("Bitget Wallet");Get Wallet Address
import { useWallet } from "@aptos-labs/wallet-adapter-react";
const { account } = useWallet(); // {address: '...', publicKey: '...'}Get Network
import { useWallet } from "@aptos-labs/wallet-adapter-react";
const { network } = useWallet();Message
Sign Message
Parameters
optionsmessage- stringnonce- string
import { useWallet } from "@aptos-labs/wallet-adapter-react";
const { signMessage } = useWallet();
const res = await signMessage({
message: "The message to be signed and displayed to the user",
nonce: "1",
});Verify Message
Signing information is intended to verify ownership of private resources.
import nacl from 'tweetnacl';
import { useWallet } from "@aptos-labs/wallet-adapter-react";
const { signMessage, account } = useWallet();
const message = "hello";
const nonce = "random_string"
try {
const response = await signMessage({
message,
nonce,
});
// Remove the 0x prefix
const key = account.publicKey!.slice(2, 66);
const verified = nacl.sign.detached.verify(Buffer.from(response.fullMessage),
Buffer.from(response.signature, 'hex'),
Buffer.from(key, 'hex'));
console.log(verified);
} catch (error) {
console.error(error);
}Transaction
Sign Transaction
import { useWallet } from "@aptos-labs/wallet-adapter-react";
const { signTransaction } = useWallet();
const transaction = {
arguments: ["100000", "330679"],
function:
"0xc7efb4076dbe143cbcd98cfaaa929ecfc8f299203dfff63b95ccb6bfe19850fa::router::swap_exact_input",
type: "entry_function_payload",
type_arguments: [
"0x1::aptos_coin::AptosCoin",
"0x159df6b7689437016108a019fd5bef736bac692b6d4a1f10c941f6fbb9a74ca6::oft::CakeOFT",
],
};
try {
const res = await signTransaction(transaction);
} catch (error) {
// see "Errors"
}Sign and Send Transaction
import { useWallet } from "@aptos-labs/wallet-adapter-react";
const { signAndSubmitTransaction } = useWallet();
try {
const pendingTransaction = await signAndSubmitTransaction({
data: transaction,
});
} catch (error) {
// see "Errors"
}

