Skip to content
This repository has been archived by the owner on Apr 18, 2023. It is now read-only.

Update wallet documentation #59

Merged
merged 7 commits into from
Mar 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
/snaps/ @alexandratran @bgravenorst @ziad-saab
/wallet/ @alexandratran @bgravenorst @GuiBibeau
/snaps/ @MetaMask/tech-writers @MetaMask/snaps
/wallet/ @MetaMask/tech-writers @MetaMask/dev-ex @ziad-saab
9 changes: 2 additions & 7 deletions wallet-sidebar.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,18 +55,13 @@ const sidebar = {
items: [
"concepts/sdk-connections",
"concepts/signing-methods",
"concepts/onboarding-library",
"concepts/convenience-libraries",
],
},
{
type: "category",
type: "doc",
id: "tutorials/index",
label: "Tutorials",
link: { type: "generated-index" },
items: [
"tutorials/create-simple-dapp",
"tutorials/create-simple-dapp-with-sdk",
],
},
{
type: "category",
Expand Down
4 changes: 4 additions & 0 deletions wallet/concepts/convenience-libraries.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
---
description: Learn about convenience libraries.
---

# Convenience libraries

Various convenience libraries exist for dapp developers.
Expand Down
21 changes: 0 additions & 21 deletions wallet/concepts/onboarding-library.md

This file was deleted.

4 changes: 4 additions & 0 deletions wallet/concepts/sdk-connections.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
---
description: Learn about MetaMask SDK connections.
---

# MetaMask SDK connections

You can [use MetaMask SDK](../how-to/use-sdk/index.md) to enable users to easily connect from your
Expand Down
2 changes: 1 addition & 1 deletion wallet/get-started/detect-network.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ Consult [chainid.network](https://chainid.network) for more.

| Hex | Decimal | Network |
|----------|----------|---------------------------------------------------------------------------|
| 0x1 | 1 | Ethereum main network (mainnet) |
| 0x1 | 1 | Ethereum main network (Mainnet) |
| 0x5 | 5 | Goerli test network |
| 0xaa36a7 | 11155111 | Sepolia test network |
| 0x539 | 1337 | Localhost test networks (including [Ganache](run-development-network.md)) |
43 changes: 19 additions & 24 deletions wallet/how-to/access-provider.md
Original file line number Diff line number Diff line change
@@ -1,23 +1,28 @@
---
description: Access a user's MetaMask provider using metamask-extension-provider.
---

# Access a user's MetaMask provider

You the [`metamask-extension-provider`](https://www.npmjs.com/package/metamask-extension-provider)
package to access a user's MetaMask provider from other web extensions.
Use the [`metamask-extension-provider`](https://github.com/MetaMask/extension-provider) module to
access a user's MetaMask provider from other web extensions.

The account provided by this provider is the user's MetaMask account.

When sending signing requests to this provider, MetaMask prompts the user to sign with their accounts.

This module works in Chrome and Firefox.

## Installation
Install `metamask-extension-provider` using the following command:

```bash
npm install metamask-extension-provider -s
```

## Usage

:::tip
You can use a bundler such as [Browserify](https://browserify.org/) with `metamask-extension-provider`.
:::

To use the module, add something like the following to your project script:

```javascript
const createMetaMaskProvider = require('metamask-extension-provider');
Expand All @@ -27,13 +32,11 @@ const provider = createMetaMaskProvider();
provider.on('error', (error) => {
// Failed to connect to MetaMask, fallback logic.
});

// Enjoy!
```

## Add additional browser support

Add MetaMask's extension ID for that browser's store to the configuration file:
To add support for an additional browser, add MetaMask's extension ID for that browser's store to
the configuration file.
For example:

```javascript
{
Expand All @@ -44,23 +47,15 @@ Add MetaMask's extension ID for that browser's store to the configuration file:

## Run the example

Use the `./sample-extension` folder as a web extension.
The
[`sample-extension`](https://github.com/MetaMask/extension-provider/tree/master/sample-extension)
directory contains an example web extension implementation.
You can easily add it to Chrome or Firefox Developer Edition.

## Edit the example

You must have Browserify installed (`npm i -g browserify`) to edit the example.

You can edit the sample file `sample-extension/index.js` and rebuild the file with `npm run buildSample`.

## Use with a local development copy of MetaMask
You can edit the sample file `sample-extension/index.js` and rebuild the file using
`npm run buildSample`.

You must edit the method `getMetaMaskId()` to return your local development MetaMask instance's ID.
You can get that from your MetaMask console using `chrome.runtime.id`.

## Current limitations

In order to identify problems (such as MetaMask not connecting), proper error handling must be added
to [metamask-inpage-provider](https://github.com/MetaMask/metamask-inpage-provider) that exposes the
errors to the consumer of the provider.
Maybe making it an event-emitter, so it can emit its errors, instead of just logging them.
54 changes: 30 additions & 24 deletions wallet/how-to/interact-with-smart-contracts.md
Original file line number Diff line number Diff line change
@@ -1,34 +1,41 @@
---
description: Enable your dapp to interact with smart contracts.
---

# Interact with smart contracts

Once you have your [development environment set up](../get-started/set-up-dev-environment.md), you
can start interacting with some smart contracts.
There are some basic things you'll need, regardless of what convenience library you're using, when
communicating with a smart contract.
To interact with a smart contract, your dapp needs the contract's:

- [Network](#contract-network).
- [Address](#contract-address).
- [ABI](#contract-abi).
- [Bytecode](#contract-bytecode).
- [Source code](#contract-source-code).

## The contract network
## Contract network

If you're not connected to the right network, you can't send transactions to your contract.
Many dapp developers deploy their contract to a testnet first, in order to avoid potentially
disastrous fees if something goes wrong during development and testing on mainnet.
disastrous fees if something goes wrong during development and testing on Mainnet.

Regardless of which network you deploy your final dapp on, your users must be able to access it.
Use the [`wallet_switchEthereumChain`](../reference/rpc-api.md#wallet_switchethereumchain) and
[`wallet_addEthereumChain`](../reference/rpc-api.md#wallet_addethereumchain) RPC API methods to
prompt the user to add a chain that you suggest, and switch to it using a confirmation dialogue.
Use the [`wallet_switchEthereumChain`](../reference/rpc-api.md#walletswitchethereumchain) and
[`wallet_addEthereumChain`](../reference/rpc-api.md#walletaddethereumchain) RPC methods to prompt
the user to add a chain that you suggest, and switch to it using a confirmation dialogue.

## The contract address
## Contract address

Every account in Ethereum has an address, whether it's an external key-pair account or a smart contract.
In order for any smart contract library to communicate with your contracts, it 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).

## The contract ABI
## Contract ABI

In Ethereum, the [ABI specification](https://solidity.readthedocs.io/en/develop/abi-spec.html) is a
way to encode the interface of a smart contract that is comprehensible to your user interface.
It is an array of method-describing objects, and when you feed this and the address into a
way to encode the interface of a smart contract that's comprehensible to your user interface.
The ABI is an array of method-describing objects, and when you feed this and the address into a
contract-abstraction library, the ABI tells those libraries about what methods to provide, and
how to compose transactions to call those methods.

Expand All @@ -40,19 +47,18 @@ Example libraries include:
- [ethjs](https://www.npmjs.com/package/ethjs).
- [Truffle](https://www.trufflesuite.com/).

## The contract bytecode
## Contract bytecode

If your dapp publishes a new pre-compiled smart contract, it may need to include some bytecode.
You don't know the contract address in advance, but instead must publish,
watch for the transaction to be processed, and then extract the final contract's address from the
completed transaction.
If your dapp publishes a new pre-compiled smart contract, it might need to include some bytecode.
You don't know the contract address in advance; you must publish the contract, watch for the
transaction to be processed, and then extract the final contract's address from the completed transaction.

If publishing a contract from bytecode, you still need an ABI to interact with it.
If you publish a contract from bytecode, you still need an [ABI](#contract-abi) to interact with it.
The bytecode doesn't describe how to interact with the final contract.

## The contract source code
## Contract source code

If your dapp allows users to edit smart contract source code and compile it, similar to
[Remix](http://remix.ethereum.org/), you may import a whole compiler.
You derive your bytecode and ABI from that source code, and eventually you derive the contract's
address from the completed transaction, where that bytecode is published.
[Remix](http://remix.ethereum.org/), you can import a whole compiler.
You derive your bytecode and ABI from that source code, and eventually derive the contract's address
from the completed transaction, where that bytecode is published.
19 changes: 12 additions & 7 deletions wallet/how-to/migrate-api.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
# Migrate to the current provider API

:::caution Important
If you're a MetaMask user attempting to use a legacy Ethereum website that hasn't migrated to the
new API, please see the [MetaMask legacy Web3 extension](#using-the-metamask-legacy-web3-extension).
---
title: Migrate the provider API
description: Migrate to the current provider API.
---

Except for such legacy websites, no action is required for MetaMask users.
:::
# Migrate to the current provider API

In January 2021, MetaMask made a number of breaking changes to the
[provider API](../reference/provider-api.md), and removed the injected `window.web3`.
Expand All @@ -18,6 +16,13 @@ This guide describes how to migrate to the new provider API, and how to replace
To understand why MetaMask made these changes, please see
[this blog post](https://medium.com/metamask/breaking-changes-to-the-metamask-provider-are-here-7b11c9388be9).

:::note
If you're a MetaMask user attempting to use a legacy Ethereum website that hasn't migrated to the
new API, please see the [MetaMask legacy Web3 extension](#use-the-metamask-legacy-web3-extension).

Except for such legacy websites, no action is required for MetaMask users.
:::

## Summary of breaking changes

### `window.web3` removal
Expand Down
67 changes: 12 additions & 55 deletions wallet/how-to/register-method-names.md
Original file line number Diff line number Diff line change
@@ -1,58 +1,15 @@
# Register a contract's methods names
---
description: Register a contract's method names on the Ethereum Signature Database.
---

MetaMask uses the Parity on-chain registry of function signatures to display method names on the
confirm screen.
For many common method names, such as token methods, this allows MetaMask to successfully look up
the method names by their [method signature](https://solidity.readthedocs.io/en/v0.4.21/abi-spec.html).
However, sometimes you're using a method that isn't in that on-chain registry, and MetaMask simply
displays **Contract Interaction** to the user.

To add your contract's function names to this registry so it shows in the MetaMask interface, follow
these steps:

1. Go to the
[Mainnet Parity signature registration contract on Etherscan](https://etherscan.io/address/0x44691b39d1a75dc4e0a0346cbb15e310e6ed1e86#writeContract).
1. Connect MetaMask.
1. Use Etherscan's write contract feature to input the string value (without quotes or spaces) to
the register function.
For example:

`getOwners()`

`execTransaction(address,uint256,bytes,uint8,uint256,uint256,uint256,address,address,bytes)`

1. Select **write**.
1. Approve the transaction in MetaMask (you only pay gas).

## Verify

`ethers.utils.keccak256('getOwners()') => 0xa0e67e2bdc0a6d8a09ccd6c353c9df590807ad66ff5e6630c4f31a86dfa84821`
# Register a contract's method names

Input the first 10 characters, `0xa0e67e2b`, into
[this demo app](https://jennypollack.github.io/function_signature_registry/) that checks the
on-chain registry (Mainnet or Rinkeby only).

### Use Remix

1. Paste the contract code from
[bokky's blog post](https://www.bokconsulting.com.au/blog/a-quick-look-at-paritys-signature-registry-contract/)
into [Remix](https://remix.ethereum.org).
1. Set the correct compiler version based on the contract.
1. Use Remix's write functionality to add to the registry.
1. You can look at the `FUNCTIONHASHES` section on Remix by loading the signature registry contract,
and selecting **details** on the compile tab.

### Use `eth-method-registry`

You can also use the
[signature registry](https://rinkeby.etherscan.io/address/0x0c0831fb1ec7442485fb41a033ba188389a990b4)
deployed on Rinkeby.

[`eth-method-registry`](https://github.com/MetaMask/eth-method-registry) is used to lookup methods
in MetaMask.

:::note
MetaMask reads from the mainnet `eth-method-registry` endpoint, regardless of the user's network.
:::
MetaMask uses the [Ethereum Signature Database](https://www.4byte.directory/) to display
method names on the confirmation screen.
For many common method names, such as token methods, this allows MetaMask to look up the method
names by their [method signature](https://solidity.readthedocs.io/en/v0.4.21/abi-spec.html).
However, sometimes you're using a method that isn't in that database, and MetaMask simply
displays **Contract Interaction** to the user.

For more details, see [this StackExchange answer](https://ethereum.stackexchange.com/questions/59678/metamask-shows-unknown-function-when-calling-method-send-function).
To register your contract's method names so they show in the MetaMask interface,
[submit each method's signature to the Ethereum Signature Database](https://www.4byte.directory/submit/).
Loading