# Aptos-AIP-62
The 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. The AIP-62 also upgrades the data interfaces for interaction between DApps and wallets, such as the encapsulated RawTransaction
, etc.
Note:
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 SafePal 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>;
2
3
4
5
# 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: 'SafePal Wallet', icon: '...'}]
2
3
# Connect to SafePal Wallet
Pass the wallet name to the connect method to connect to a specified wallet:
Note:
After the user has approved the connection for the first time, the web app's domain will be remembered for the future sessions.
See the example code below:
import { useWallet } from "@aptos-labs/wallet-adapter-react";
const { connect } = useWallet(); // [{name: 'SafePal Wallet', icon: '...'}]
await connect("SafePal Wallet");
2
3
4
5
# Get Wallet Address
import { useWallet } from "@aptos-labs/wallet-adapter-react";
const { account } = useWallet(); // {address: '...', publicKey: '...'}
2
3
# Get Network
import { useWallet } from "@aptos-labs/wallet-adapter-react";
const { network } = useWallet();
2
3
# Sign Message
import { useWallet } from "@aptos-labs/wallet-adapter-react";
const { signMessage } = useWallet();
const res = await signMessage({
message: "XXXXXX",
nonce: "1111",
});
2
3
4
5
6
7
8
# Send 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"
}
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
# Sign and submit Transaction
import { useWallet } from "@aptos-labs/wallet-adapter-react";
const { signAndSubmitTransaction } = useWallet();
try {
const pendingTransaction = await signAndSubmitTransaction({
data: transaction,
});
} catch (error) {
// see "Errors"
}
2
3
4
5
6
7
8
9
10
11