Skip to content

Commit

Permalink
revert wallet docs
Browse files Browse the repository at this point in the history
  • Loading branch information
alexandratran committed Jul 16, 2024
1 parent 7487161 commit 1cffd62
Show file tree
Hide file tree
Showing 48 changed files with 799 additions and 888 deletions.
8 changes: 4 additions & 4 deletions wallet/concepts/sdk/android.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,10 @@ The [architecture](#architecture) and [connection flow](#connection-flow) of
the Android SDK differs from the other SDK platforms.

:::tip Get started

- Get started by [setting up the SDK in your Android dapp](../../how-to/use-sdk/mobile/android.md).
- See the [example Android dapp](https://github.com/MetaMask/metamask-android-sdk/tree/main/app) in
the Android SDK GitHub repository for advanced use cases.
:::
:::

## Architecture

Expand Down Expand Up @@ -53,7 +52,8 @@ The following diagram outlines the communication flow between the Android client
The flow is as follows:

1. The dapp, with the SDK installed, initiates communication when a user connects to MetaMask.
The dapp deeplinks to MetaMask, and MetaMask sets up the Android Native Module to receive client requests.
The dapp deeplinks to MetaMask, and MetaMask sets up the Android Native Module to receive client requests.
2. The dapp generates an ECIES public/private key pair.
The dapp and MetaMask exchange public keys over IPC.
The dapp and MetaMask exchange public keys over IPC.
3. The dapp and MetaMask perform end-to-end encrypted JSON-RPC calls.

11 changes: 6 additions & 5 deletions wallet/concepts/sdk/connections.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,16 +40,17 @@ The path first depends on whether the dapp is on a desktop or mobile platform:
- If the dapp is on a desktop platform (for example, a desktop web dapp), the dapp shows a modal
asking the user to select if they want to connect to MetaMask using the browser extension or
MetaMask Mobile.

- If the user selects extension:
- If the extension is not installed, the user is taken to the Chrome extension store to
install it.
install it.
- If the extension is installed, the user connects to their MetaMask extension.

- If the user selects MetaMask Mobile:
- If MetaMask Mobile is not installed, the user is taken to the app store to install it.
- If MetaMask Mobile is installed, [an encrypted connection from the dapp to MetaMask
Mobile](#metamask-mobile-connection) is established.

:::note
The choice between the extension and MetaMask Mobile persists until the user or dapp disconnects.
At that point, the dapp displays the modal again.
Expand Down Expand Up @@ -103,11 +104,11 @@ The flow is as follows:
1. The dapp generates a UUID v4 ([Socket.io](https://socket.io/) room ID) and ECIES key pair.
2. The dapp connects to the Socket.io server using the room ID.
3. The dapp sends a deeplink to MetaMask Mobile (either directly, if on mobile, or through a QR
code, if on desktop) containing its ECIES public key and the Socket.io room ID.
code, if on desktop) containing its ECIES public key and the Socket.io room ID.
4. MetaMask Mobile opens the QR code or deeplink and connects to the Socket.io server using the room ID.
5. MetaMask Mobile generates an ECIES key pair.
6. MetaMask Mobile sends its ECIES public key to the dapp using the Socket.io channel, and the two
parties generate a shared secret.
parties generate a shared secret.
7. The dapp and MetaMask Mobile establish an encrypted connection to send JSON-RPC API methods.

:::note
Expand Down
40 changes: 17 additions & 23 deletions wallet/concepts/sdk/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ tags:
- Unity SDK
---

import Tabs from "@theme/Tabs";
import TabItem from "@theme/TabItem";
import Tabs from '@theme/Tabs';
import TabItem from '@theme/TabItem';

# About MetaMask SDK

Expand All @@ -33,15 +33,15 @@ MetaMask using the SDK.
Most of these features are not available if you only integrate your dapp directly using the
[Wallet API](../wallet-api.md).

| Feature | Wallet API only | MetaMask SDK |
| ---------------------------------------------------------------------------------------------------------- | :-------------: | :----------: |
| Connect from a web dapp to the MetaMask extension |||
| Connect from a web dapp to MetaMask Mobile |||
| Connect from desktop, mobile, and gaming dapps to MetaMask Mobile |||
| Use custom RPC methods such as [`connectAndSign`](../../how-to/use-sdk/javascript/connect-and-sign.md) |||
| [Display custom modals](../../how-to/use-sdk/javascript/display-custom-modals.md) in MetaMask |||
| [Make read-only requests](../../how-to/use-sdk/javascript/make-read-only-requests.md) using the Infura API |||
| [Batch multiple RPC requests](../../how-to/use-sdk/javascript/batch-json-rpc-requests.md) |||
| Feature | Wallet API only | MetaMask SDK |
|-----------------------------------------------------------------------------------------------|:---------------:|:------------:|
| Connect from a web dapp to the MetaMask extension | | |
| Connect from a web dapp to MetaMask Mobile | | |
| Connect from desktop, mobile, and gaming dapps to MetaMask Mobile | | |
| Use custom RPC methods such as [`connectAndSign`](../../how-to/use-sdk/javascript/connect-and-sign.md) | | |
| [Display custom modals](../../how-to/use-sdk/javascript/display-custom-modals.md) in MetaMask | | |
| [Make read-only requests](../../how-to/use-sdk/javascript/make-read-only-requests.md) using the Infura API | | |
| [Batch multiple RPC requests](../../how-to/use-sdk/javascript/batch-json-rpc-requests.md) | | |

## User experience

Expand All @@ -61,11 +61,10 @@ to MetaMask Mobile using a QR code.
</p>

:::tip Get started

- Get started by [setting up the SDK in your web dapp](../../how-to/use-sdk/javascript/index.md).
- See the [example JavaScript dapps](https://github.com/MetaMask/metamask-sdk/tree/main/packages/examples)
in the JavaScript SDK GitHub repository for advanced use cases.
:::
:::

</TabItem>
<TabItem value="Mobile browser">
Expand All @@ -82,11 +81,10 @@ This happens for all actions that need user approval.
</p>

:::tip Get started

- Get started by [setting up the SDK in your web dapp](../../how-to/use-sdk/javascript/index.md).
- See the [example JavaScript dapps](https://github.com/MetaMask/metamask-sdk/tree/main/packages/examples)
in the JavaScript SDK GitHub repository for advanced use cases.
:::
:::

</TabItem>
<TabItem value="iOS">
Expand All @@ -103,11 +101,10 @@ This happens for all actions that need user approval.
</p>

:::tip Get started

- Get started by [setting up the SDK in your iOS dapp](../../how-to/use-sdk/mobile/ios.md).
- See the [example iOS dapp](https://github.com/MetaMask/metamask-ios-sdk) in the iOS SDK GitHub
repository for advanced use cases.
:::
:::

</TabItem>
<TabItem value="Android">
Expand All @@ -124,11 +121,10 @@ This happens for all actions that need user approval.
</p>

:::tip Get started

- Get started by [setting up the SDK in your Android dapp](../../how-to/use-sdk/mobile/android.md).
- See the [example Android dapp](https://github.com/MetaMask/metamask-android-sdk/tree/main/app) in
the Android SDK GitHub repository and the [Android SDK architecture](android.md) for more information.
:::
:::

</TabItem>
<TabItem value="Node.js">
Expand All @@ -143,11 +139,10 @@ scan with their MetaMask Mobile app.
</p>

:::tip Get started

- Get started by [setting up the SDK in your Node.js dapp](../../how-to/use-sdk/javascript/nodejs.md).
- See the [example Node.js dapp](https://github.com/MetaMask/metamask-sdk/tree/main/packages/examples/nodejs)
in the Node.js SDK GitHub repository for advanced use cases.
:::
:::

</TabItem>
<TabItem value="Unity">
Expand All @@ -163,11 +158,10 @@ It also supports deeplinking on mobile platforms, as demonstrated in the followi
</p>

:::tip Get started

- Get started by [setting up the SDK in your Unity game](../../how-to/use-sdk/gaming/unity/index.md).
- See the [Unity demo game with the SDK installed](https://assetstore.unity.com/packages/decentralization/demo-game-dragon-crasher-with-metamask-sdk-infura-and-truffle-249789)
for advanced use cases.
:::
:::

</TabItem>
</Tabs>
Expand Down
2 changes: 1 addition & 1 deletion wallet/concepts/smart-contracts.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ the user to add a chain that you suggest, and switch to it using a confirmation
## Contract address

Every account in Ethereum has an address, whether it's an external key-pair account or a smart contract.
For any smart contract library to communicate with your contracts, a smart contract must know the exact address.
For any smart contract library to communicate with your contracts, a smart contract must know the exact address.

Read about
[how to find a token contact address](https://metamask.zendesk.com/hc/en-us/articles/360059683451-How-to-view-or-add-custom-token-contract-address).
Expand Down
10 changes: 5 additions & 5 deletions wallet/concepts/wallet-api.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ The API methods are documented in the following references:

- [Ethereum provider API reference](../reference/provider-api.md)
- [JSON-RPC API reference](/wallet/reference/json-rpc-api)
:::
:::

## Ethereum provider API

Expand Down Expand Up @@ -63,13 +63,13 @@ Make sure to handle errors for every call to

The RPC methods are divided into the following:

- [Restricted methods](#restricted-methods) - Require user consent for actions that impact assets or data (for example, initiating a transaction).
- [Restricted methods](#restricted-methods) - Require user consent for actions that impact assets or data (for example, initiating a transaction).
- [Unrestricted methods](#unrestricted-methods) - Allow dapps to perform basic actions without permission (for example, retrieving a public address).

### Restricted methods

MetaMask implements permissions based on [EIP-2255](https://eips.ethereum.org/EIPS/eip-2255) to enhance security for when users interact with dapps.
This requires that dapps obtain user consent before accessing certain features.
MetaMask implements permissions based on [EIP-2255](https://eips.ethereum.org/EIPS/eip-2255) to enhance security for when users interact with dapps.
This requires that dapps obtain user consent before accessing certain features.
Under the hood, permissions are plain, JSON-compatible objects, with fields that are mostly used
internally by MetaMask.

Expand All @@ -79,7 +79,7 @@ Restricted methods are methods that cannot be called unless you have permission

The following methods are restricted:

- [`eth_accounts`](/wallet/reference/eth_accounts) - Gaining permission requires calling `wallet_requestPermissions`.
- [`eth_accounts`](/wallet/reference/eth_accounts) - Gaining permission requires calling `wallet_requestPermissions`.
Granting permission for `eth_accounts` also grants permissions for the following methods:

- [`eth_sendTransaction`](/wallet/reference/eth_sendTransaction)
Expand Down
16 changes: 8 additions & 8 deletions wallet/concepts/wallet-interoperability.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ mechanism to the [`window.ethereum`](wallet-api.md#ethereum-provider-api) inject
This mechanism is enabled by using the standardized interfaces defined by EIP-6963.

:::info Why EIP-6963?
[EIP-1193](https://eips.ethereum.org/EIPS/eip-1193) standardizes the interface for wallet providers,
[EIP-1193](https://eips.ethereum.org/EIPS/eip-1193) standardizes the interface for wallet providers,
but it results in conflicts when users have multiple wallets installed, due to how the provider
object is injected.
This can cause issues with wallet discovery, user onboarding, and connecting.
The wallet discovery mechanism introduced by EIP-6963 solves these issues.
object is injected.
This can cause issues with wallet discovery, user onboarding, and connecting.
The wallet discovery mechanism introduced by EIP-6963 solves these issues.
:::

The following is a demo of the user experience of detecting multiple wallets, showing the data
Expand Down Expand Up @@ -62,8 +62,8 @@ interface announces an event dispatched by the wallet:

```typescript
interface EIP6963AnnounceProviderEvent extends CustomEvent {
type: "eip6963:announceProvider"
detail: EIP6963ProviderDetail
type: "eip6963:announceProvider";
detail: EIP6963ProviderDetail;
}
```

Expand All @@ -72,7 +72,7 @@ interface requests an event dispatched by a dapp:

```typescript
interface EIP6963RequestProviderEvent extends Event {
type: "eip6963:requestProvider"
type: "eip6963:requestProvider";
}
```

Expand Down Expand Up @@ -112,7 +112,7 @@ MetaMask, resolving potential conflicts that might arise with other wallet exten
more stable and reliable interaction for users.

The SDK is also being integrated into [Wagmi 2+](https://wagmi.sh/), which supports EIP-6963.
The SDK on its own supports connecting _only_ to MetaMask via EIP-6963, so if you intend to support
The SDK on its own supports connecting *only* to MetaMask via EIP-6963, so if you intend to support
discovery of other wallets, we recommend using other methods of adding EIP-6963 support, such as
Wagmi 2+.

Expand Down
44 changes: 22 additions & 22 deletions wallet/how-to/connect/access-accounts.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,30 +42,30 @@ button:
// You should only attempt to request the user's account in response to user interaction, such as
// selecting a button. Otherwise, you pop-up spam the user like it's 1999. If you fail to retrieve
// the user's account, you should encourage the user to initiate the attempt.
const ethereumButton = document.querySelector(".enableEthereumButton")
const showAccount = document.querySelector(".showAccount")
const ethereumButton = document.querySelector(".enableEthereumButton");
const showAccount = document.querySelector(".showAccount");

ethereumButton.addEventListener("click", () => {
getAccount()
})
getAccount();
});

// While awaiting the call to eth_requestAccounts, you should disable any buttons the user can
// select to initiate the request. MetaMask rejects any additional requests while the first is still
// pending.
async function getAccount() {
const accounts = await provider // Or window.ethereum if you don't support EIP-6963.
.request({ method: "eth_requestAccounts" })
.catch((err) => {
if (err.code === 4001) {
// EIP-1193 userRejectedRequest error.
// If this happens, the user rejected the connection request.
console.log("Please connect to MetaMask.")
} else {
console.error(err)
}
})
const account = accounts[0]
showAccount.innerHTML = account
.catch((err) => {
if (err.code === 4001) {
// EIP-1193 userRejectedRequest error.
// If this happens, the user rejected the connection request.
console.log("Please connect to MetaMask.");
} else {
console.error(err);
}
});
const account = accounts[0];
showAccount.innerHTML = account;
}
```

Expand All @@ -87,32 +87,32 @@ be notified when the user changes accounts.
The following code handles user accounts and detects when the user changes accounts:

```javascript title="index.js"
let currentAccount = null
let currentAccount = null;
provider // Or window.ethereum if you don't support EIP-6963.
.request({ method: "eth_accounts" })
.then(handleAccountsChanged)
.catch((err) => {
// Some unexpected error.
// For backwards compatibility reasons, if no accounts are available, eth_accounts returns an
// empty array.
console.error(err)
})
console.error(err);
});

// Note that this event is emitted on page load. If the array of accounts is non-empty, you're
// already connected.
provider // Or window.ethereum if you don't support EIP-6963.
.on("accountsChanged", handleAccountsChanged)
.on("accountsChanged", handleAccountsChanged);

// eth_accounts always returns an array.
function handleAccountsChanged(accounts) {
if (accounts.length === 0) {
// MetaMask is locked or the user has not connected any accounts.
console.log("Please connect to MetaMask.")
console.log("Please connect to MetaMask.");
} else if (accounts[0] !== currentAccount) {
// Reload your interface with accounts[0].
currentAccount = accounts[0]
currentAccount = accounts[0];
// Update the account displayed (see the HTML for the connect button)
showAccount.innerHTML = currentAccount
showAccount.innerHTML = currentAccount;
}
}
```
Expand Down
Loading

0 comments on commit 1cffd62

Please sign in to comment.