Here’s the article you requested:

Metamask: How to bring locally created addresses to Metamasking

Metamask: How to import locally generated addresses on my Metamask? [closed]

As a developer working with smart contracts, it is important to safely manage the private keys and addresses of users. A popular solution to this is the extension of the Metamask browser, which allows users to interact with their local Ethereum accounts in the browser. However, if you create complex applications, such as merging and fund contracts with Hardhat and Ethers.JS, you must import locally created addresses from a metamo letter from the pocket.

This article goes through a process that provides locally created addresses in your metamask in our local wallet.

Why is it necessary?

If users interact with their contract, they usually give up a clear address (eg 0x1234567890ABCDEF) as the basis for the function. However, if you create a new public key contract for the function, you need to update the address that is stored in the memory of the contract.

To achieve this, you need to import locally created addresses from your Metamast letter bag. This will ensure that you can initiate the contract with the right private key and account information.

Requirements

Before we process the process, make sure you:

  • Local Ethereum node (eg. Metamask, Infura or Geth)

  • Own local metamask letter

  • Your project installed Ethers.js

4 .. Hardhat built with Ethereum network

Step 1: Create a new address from the Metamast letter bag

First, you need to create a new address in Metamask Letter, which is used as a private key to the contract. Such as: how:

  • Start extension of the Metamask browser in the browser.

  • Register for your Metamask registration information (or create a new wallet if necessary).

  • Click "Settings" and go to "wallet".

  • Click "Create a new address" or create a new address with the button.

Name your new address, for example,my_new_address.

Step 2: Set Ethers.js

When you have your private key to your Metamask wallet (public key) ready, you need to set your Hardhat project. Such as: how:

  • Install Ethers.js with NPM or thread:

Bash

NPM Install Ethers.js

  • That “ether” module to the contract code:

`Javascript

Import {.ethers} ‘@nomiclabs/ether’;

`

Phase 3: Base contract with locally created addresses

Create a new function in the agreement that accepts the address and updates the contract with the memory accordingly.

Here is the implementation of a simple connection and a fund agreement:

`Javascript

Const Ethers = Requirements (‘@nomiclabs/ethers’);

Agreement (‘Connectandfund’, () => {

Private key;

Let the address put;

Asynkrum function init () {

// brings locally created addresses from Metamask

Privatexykey = waiting for the ether.wallet.fromaccounts (address);

Address = Private Key.

// Found the agreement with the addresses imported

Wait for the new Ether.Contract (this. Constructor, [… Delivery of the Agreement], die);

}

});

`

Step 4: Update Hardhat project

Update the “Ethersjs” configuration “hardhat.config.js” file containing Metamask Letter Bag:

`Javascript

Module.exports = {

// … Other configurations …

Ethersjs: {

Accounts: {

Mnemonicfile: ‘./metamask.json’,

},

},

};

`

Step 5: Complete the contract

If you want to check if the contract works correctly, complete it with the “Hardhat Run” command with a local Ethereum node:

`Bash

NPX Hardhat Lead Scripts from/Connect-And-Fund.js-Network Mainnet-Accounts -Private-key

Replace the 'and `actual metamask letter bag that you used for the presentation.

It’s!

MNEMONIC PHRASE RISK