Skip to content

Commit 367519a

Browse files
0xmaayanclay-aptos
andauthored
[DOC] add aptos wallet adapter docs (#5812)
* [DOC] add aptos wallet adapter docs * [DOC] add aptos wallet adapter docs * [DOC] add aptos wallet adapter docs * import image and baseUrl components * add missing link * rename image files * add words to dict file * Make direct edits to Wallet Adapter concept * Make direct edits to Wallet Adapter for Dapps doc * Edit Wallet Adapter for Wallets directly * Fix order of new dictionary entries * address feedback * add context on the adapter * Make small edits directly Co-authored-by: Clay Murphy <[email protected]>
1 parent 0377a5f commit 367519a

7 files changed

+266
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
---
2+
title: "Aptos Wallet Adapter"
3+
id: "wallet-adapter-concept"
4+
---
5+
6+
import ThemedImage from '@theme/ThemedImage';
7+
import useBaseUrl from '@docusaurus/useBaseUrl';
8+
9+
# Aptos Wallet Adapter
10+
11+
Building a dapp requiers to provide a wallet for the user to interact with the Aptos chain, and for a good user experience, it requires to provide multiple wallets so users can chose the one they want to use.
12+
13+
Implementing wallet integration can be difficult for dapps in:
14+
15+
1. Support and test all edge cases
16+
2. Implement and maintain different wallet APIs
17+
3. Provide users with needed functionality the wallet itself doesnt support
18+
4. Keep track on all the different wallets in our ecosystem
19+
20+
In addition, creating and implementing a wallet is also not an easy task,
21+
22+
1. Provide a wallet that follows a known standard so it is easy to integrate with
23+
2. Getting visibility and exposure in the ecosystem among all the other wallets
24+
3. Dapp projects need to dedicate time and resource to integrate the wallet within their app
25+
26+
When we started building a wallet adapter, we wanted to provide an adapter that can be easy enough for wallets to integrate with and for dapps to use and implement.
27+
28+
For that, we provide an [Aptos Wallet Adapter](https://github.com/aptos-labs/aptos-wallet-adapter) monorepo for wallet and dapps creators to ease development and ensure a smooth process in building projects on the Aptos network.
29+
The Aptos Wallet Adapter acts as a service between dapps and wallets and exposes APIs for dapps to interact with the wallets by following our [Wallet Standard](../guides/wallet-standard). This in turns allows dapps to support many wallets with minimal integration efforts, and for wallets to follow a known standard and gain visibility.
30+
31+
## Adapter structure
32+
33+
The adapter has three different components, the:
34+
35+
1. Adapter Core package
36+
2. Adapter React provider (for dapps)
37+
3. Adapter Template plugin (for wallets)
38+
39+
This structure offers the following benefits:
40+
41+
- Modularity (separation of concerns) - separating the adapter into three components can help having more freedom in design, implementation, deployment and usage.
42+
- Wallets create and own their plugin implementation (instead of having all in the same monorepo):
43+
- Reduces the packages bundle size used by dapps.
44+
- Lets them be self-service and support themselves without too much friction.
45+
- Prevents build failures in case of any bugs/bad implementation/wrong config files/etc.
46+
- Simplicity - keeps the Provider package very light and small as the major logic is implemented in the core package.
47+
- Flexibility - for wallets in creating and implementing custom functions.
48+
49+
### Adapter Core package
50+
51+
The [Adapter Core package](https://github.com/aptos-labs/aptos-wallet-adapter/tree/main/packages/wallet-adapter-core) handles the interaction between the dapp and the wallet. It:
52+
53+
- Exposes the standard API (and some different functions supported by different wallets)
54+
- Holds the current wallet state and the installed wallets
55+
- Emits events on different actions and much more
56+
57+
Dapps should not _know_ this package as dapps interact with the provider, which in turn interacts with the core package; some Types are exposed from the core package for the dapp to use.
58+
59+
Wallets should implement their own plugin class that extends the basic plugin class (properties + events) interface that lives in the core package.
60+
61+
:::tip
62+
If a wallet supports functions that are not part of the basic plugin interface, a pull request should be made to the core package to include this function so it can support it. You can take a look at the `signTransaction` on the wallet core package for guidance.
63+
:::
64+
65+
### Adapter React provider
66+
67+
The light [Adapter React package](https://github.com/aptos-labs/aptos-wallet-adapter/tree/main/packages/wallet-adapter-react) is for dapps to import and use. The package contains a `Provider` and a `Context` to implement and use within your app.
68+
69+
Follow the [Wallet Adapter For Dapp Builders](../guides/wallet-adapter-for-dapp.md) guide on how to use the provider package on your dapp.
70+
71+
### Adapter Template plugin
72+
73+
Wallets looking to integrate with the adapter should implement their own wallet plugin, to ease the process we provide you with a pre-made class that implements the basic functionality needed (according to the wallet standard).
74+
75+
The [Wallet Adapter Plugin Template repo](https://github.com/aptos-labs/wallet-adapter-plugin-template) holds a pre-made class, a test file, and some config files to help you build and publish the plugin as an NPM package.
76+
77+
Follow the [Wallet Adapter For Wallet Builders](../guides/wallet-adapter-for-wallets.md) on how to use the template to implement and publish your wallet plugin.
78+
79+
<center>
80+
<ThemedImage
81+
alt="Wallet Adapter Concept"
82+
sources={{
83+
light: useBaseUrl('/img/docs/wallet-adapter-chart-light.svg'),
84+
dark: useBaseUrl('/img/docs/wallet-adapter-chart-dark.svg'),
85+
}}
86+
/>
87+
</center>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
---
2+
title: "For Dapps"
3+
id: "wallet-adapter-for-dapp"
4+
---
5+
6+
# Wallet Adapter For Dapp builders
7+
8+
Imagine you have a great idea for a dapp and you want to start building it. Eventually, you will need to integrate a wallet or multiple wallets so your users can interact with the Aptos blockchain.
9+
Implementing wallet integration can be difficult in supporting all edge cases, new features, unsupported functionality. And it can be even harder to support multiple wallets.
10+
11+
In addition, different wallets have different APIs, and not all wallets share the same naming convention. For example, maybe all wallets have a `connect` method, but not all wallets call that method `connect`; that can be tricky to support.
12+
13+
Luckily, Aptos built a wallet adapter, created and maintained by the Aptos team, to help you ramp up development and standardize where possible.
14+
15+
The Aptos Wallet Adapter provides:
16+
17+
- Easy wallet implementation - no need to implement and support code for multiple wallets.
18+
- Support for different wallet APIs.
19+
- Support for features not implemented on the wallet level.
20+
- Detection for uninstalled wallets (so you can show users that a wallet is not installed).
21+
- Auto-connect functionality and remembers the current wallet state.
22+
- Listens to wallet events, such as account and network changes.
23+
- A well-developed and maintained reference implementation by the Aptos ecosystem team.
24+
25+
## Install
26+
27+
Currently, the adapter supports a _React provider_ for you to include in your app.
28+
29+
Install wallet dependencies you want to include in your app. You can find a list of the wallets in the Aptos Wallet Adapter [README](https://github.com/aptos-labs/aptos-wallet-adapter#supported-wallet-packages).
30+
31+
Install the React provider:
32+
33+
```bash
34+
npm install @aptos-labs/wallet-adapter-react
35+
```
36+
37+
## Import dependencies
38+
39+
In the `App.jsx` file:
40+
41+
Import the installed wallets:
42+
43+
```js
44+
import { PetraWallet } from "petra-plugin-wallet-adapter";
45+
```
46+
47+
Import the `AptosWalletAdapterProvider`:
48+
49+
```js
50+
import { AptosWalletAdapterProvider } from "@aptos-labs/wallet-adapter-react";
51+
```
52+
53+
Wrap your app with the Provider, pass it the plugins (wallets) you want to have on your app as an array, and include an autoConnect option (set to false by default):
54+
55+
```js
56+
const wallets = [new PetraWallet()];
57+
<AptosWalletAdapterProvider plugins={wallets} autoConnect={true}>
58+
<App />
59+
</AptosWalletAdapterProvider>;
60+
```
61+
62+
### Use
63+
64+
On any page you want to use the wallet properties, import `useWallet` from `@aptos-labs/wallet-adapter-react`:
65+
66+
```js
67+
import { useWallet } from "@aptos-labs/wallet-adapter-react";
68+
```
69+
70+
You can then use the exported properties:
71+
72+
```js
73+
const {
74+
connect,
75+
account,
76+
network,
77+
connected,
78+
disconnect,
79+
wallet,
80+
wallets,
81+
signAndSubmitTransaction,
82+
signTransaction,
83+
signMessage,
84+
} = useWallet();
85+
```
86+
87+
Finally, use the [examples](https://github.com/aptos-labs/aptos-wallet-adapter/tree/main/packages/wallet-adapter-react#examples) on the package README file to build more functionality into your dapps.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
---
2+
title: "For Wallets"
3+
id: "wallet-adapter-for-wallets"
4+
---
5+
6+
# Wallet Adapter For Wallet Builders
7+
8+
To gain from dapps in the Aptos Ecosystem and provide your users the functionality they are looking for in a wallet, your wallet plugin should follow the [Aptos Wallet Standard](./wallet-standard.md) and be built from the Aptos Wallet Adapter.
9+
10+
The [wallet-adapter-plugin-template](https://github.com/aptos-labs/wallet-adapter-plugin-template) repository gives wallet builders a pre-made class with all required wallet functionality following the Aptos Wallet Standard for easy and fast development.
11+
12+
## Configuration
13+
14+
1. `git clone [email protected]:aptos-labs/wallet-adapter-plugin-template.git`
15+
1. Open `src/index.ts` for editing.
16+
1. Replace all `AptosWindow` references with: `<Your-Wallet-Name>Window`
17+
1. Replace `AptosWalletName` with: `<Your-Wallet-Name>WalletName`
18+
1. Replace `url` with your website URL.
19+
1. Change `icon` to your wallet icon (pay attention to the required format).
20+
1. Replace `window.aptos` with: `window.<your-wallet-name>`
21+
- Make sure the `Window Interface` has `<your-wallet-name>` as a key (instead of `aptos`).
22+
1. Open `__tests/index.test.tsx` and change `AptosWallet` to: `<Your-Wallet-Name>Wallet`
23+
1. Run tests with `pnpm test` - all tests should pass.
24+
25+
At this point, you have a ready wallet class with all required properties and functions to integrate with the Aptos Wallet Adapter.
26+
27+
### Publish as a package
28+
29+
The next step is to publish your wallet as an NPM package so dapps can install it as a dependency. Use one of the options below:
30+
31+
[Creating and publishing scoped public packages](https://docs.npmjs.com/creating-and-publishing-scoped-public-packages)
32+
33+
[Creating and publishing unscoped public packages](https://docs.npmjs.com/creating-and-publishing-unscoped-public-packages)
34+
35+
:::tip
36+
If your wallet provides functionality that is not included, you should open a pull request against `aptos-wallet-adapter` in the core package to have it support this functionality. See the `signTransaction` on the [wallet core package](https://github.com/aptos-labs/aptos-wallet-adapter/blob/main/packages/wallet-adapter-core/src/WalletCore.ts) for guidance.
37+
:::
38+
39+
### Add your name to the wallets list
40+
41+
Once the package is published, create a pull request against the [aptos-wallet-adapter](https://github.com/aptos-labs/aptos-wallet-adapter) package and add your wallet name to the [supported wallet list](https://github.com/aptos-labs/aptos-wallet-adapter#supported-wallet-packages) on the README file as a URL to your NPM package.

developer-docs-site/scripts/additional_dict.txt

+12
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ AptosBFT
1717
AptosCoin
1818
AptosLabs
1919
AptosNet
20+
AptosWalletAdapterProvider
21+
autoConnect
2022
BCS
2123
BFT
2224
BIP
@@ -36,8 +38,11 @@ CoinType
3638
Ctrl
3739
DAO
3840
DApps
41+
Dapps
42+
dapps
3943
DDoS
4044
DECL
45+
doesnt
4146
DM
4247
DNS
4348
Dev
@@ -120,6 +125,8 @@ Mainnnet
120125
ManagedCoin
121126
Merkle
122127
MiB
128+
Modularity
129+
monorepo
123130
Monterey
124131
MoonCoin
125132
MoveVM
@@ -132,6 +139,7 @@ NFTs
132139
NHC
133140
NetworkAddress
134141
NoAvailablePeers
142+
NPM
135143
ORM
136144
Octa
137145
Octas
@@ -278,6 +286,7 @@ io
278286
ip
279287
ips
280288
isConnected
289+
jsx
281290
kickstart
282291
korean
283292
leaderboard
@@ -331,6 +340,7 @@ quickstart
331340
quickstarts
332341
repo
333342
repos
343+
requiers
334344
ruleset
335345
runtime
336346
scalability
@@ -369,6 +379,7 @@ uint
369379
unexportable
370380
unixtime
371381
unmount
382+
unscoped
372383
untracked
373384
upgradeability
374385
upgradeable
@@ -377,6 +388,7 @@ upvote
377388
url
378389
useBaseUrl
379390
usecase
391+
useWallet
380392
utc
381393
validator
382394
validator's

developer-docs-site/sidebars.js

+7
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,13 @@ const sidebars = {
137137
"guides/move-guides/upgrading-move-code",
138138
],
139139
},
140+
{
141+
type: "category",
142+
label: "Aptos Wallet Adapter",
143+
collapsible: true,
144+
collapsed: true,
145+
items: ["concepts/wallet-adapter-concept", "guides/wallet-adapter-for-dapp", "guides/wallet-adapter-for-wallets"],
146+
},
140147
{
141148
type: "html",
142149
value: "Run Nodes",

0 commit comments

Comments
 (0)