Ethcode provides developers with all the required features of Ethereum account. Inside Ethcode developers can create, import, and Export an Ethereum account to do operations on EVM-compatible systems. below is the explanation of each feature associated with the account.
Create Ethereum Account
An Ethereum account is 42 characters long hexadecimal address. Developers can use an inbuilt Ethereum account to do any deployment and contract call process in Ethcode.
Ctrl + shift + P - shows command palate of VScode.
Ethcode: Activate Extension - this command activates the Ethcode extension.
3. Create ethereum account- command is for creating an Ethereum account in Ethcode.
4. Set the desired password for the new Ethereum account.
You should remember the password of your newly created Ethereum account to do any interaction with smart contracts.
After successful account creation now it's time to fund your Ethereum account with faucet tokens.
If anyone wants to use accounts created outside Ethcode like Metamask. Ethcode provides the feature of importing the Ethereum account stored in Keystore format.
Import ethereum account- command for importing Ethereum account stored in Keystore format.
2. Select keystore file where it is saved in your local machine.
Export Ethereum Account
Developers love uniformity that's why Ethcode contains one more exciting feature called Export account. you can export the Ethereum account that you use in Ethcode in Keystore format and use that account on others wallets too.
Ethcode: Export Account- command to export account from Ethcode in Keystore format.
2. Select account from the Quick menu.
3. Select the directory where you want to save the Keystore file.
Use with hardhat wallets
While using with hardhat, one might select hardhat accounts and be able to use that account for readonly calls without any further modifications. But if user requires to sign transactions with a hardhat account using ethcode here are the steps.
Export a hardhat wallet
create account.ts file
// account.ts
import { config } from'hardhat';import { ethers } from'ethers';import { createFromPrivateKey } from'./keyeth';import { HardhatNetworkHDAccountsConfig } from'hardhat/types';import keyethereum from'keythereum';constaccounts:HardhatNetworkHDAccountsConfig=config.networks.hardhat.accounts asHardhatNetworkHDAccountsConfig;constindex=0; // index of hardhat account that you want to exportconstwallet=ethers.Wallet.fromMnemonic(accounts.mnemonic,accounts.path +`/${index}`);constparams= { keyBytes:32, ivBytes:16, privateKey:wallet.privateKey };try {constbareKey=createFromPrivateKey(params);constoptions= { kdf:'scrypt', cipher:'aes-128-ctr' };if (bareKey) {constkeyObject=keyethereum.dump(Buffer.from('','utf-8'),bareKey.privateKey,bareKey.salt,bareKey.iv );console.log(keyObject);// path to export your key. Default current directory.keyethereum.exportToFile(keyObject,`./`); }} catch (error) {console.error(error);}
require('hardhat')constkeythereum=require('keythereum')constkeyeth=require('./keyeth')constaccounts=config.networks.hardhat.accountsconstindex=0// index of hardhat account that you want to exportconstwallet=ethers.Wallet.fromMnemonic(accounts.mnemonic,accounts.path +`/${index}`)constparams= { keyBytes:32, ivBytes:16, privateKey:wallet.privateKey }constbareKey=keyeth.createFromPrivateKey(params)constoptions= { kdf:'scrypt', cipher:'aes-128-ctr'}constkeyObject=keythereum.dump(Buffer.from('','utf-8'),bareKey.privateKey,bareKey.salt,bareKey.iv, options)console.log(keyObject)// path to export your key. Default current directory.keythereum.exportToFile(keyObject,`./`)