Account
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.
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.
- 1.
Ctrl + shift + P
- shows command palate of VScode. - 2.
Ethcode: Activate Extension
- this command activates the Ethcode extension.

Activate ETHcode
3.
Create ethereum account
- command is for creating an Ethereum account in Ethcode.
Create Ethereum account
4. Set the desired password for the new Ethereum account.

new account passord
You should remember the password of your newly created Ethereum account to do any interaction with smart contracts.

account created
After successful account creation now it's time to fund your Ethereum account with faucet tokens.
you can get free tokens from mentioned faucets:
If anyone wants to use accounts created outside Ethcode like Metamask. Ethcode provides the feature of importing the Ethereum account stored in Keystore format.
- 1.
Import ethereum account
- command for importing Ethereum account stored in Keystore format.

import account command
2. Select keystore file where it is saved in your local machine.

keystore file

account imported
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.
- 1.
Ethcode: Export Account
- command to export account from Ethcode in Keystore format.

export account command
2. Select account from the Quick menu.

account quickpick menu
3. Select the directory where you want to save the Keystore file.

account exported
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.
- 1.Export a hardhat wallet
TypeScript
JavaScript
- 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';
const accounts: HardhatNetworkHDAccountsConfig = config.networks.hardhat.accounts as HardhatNetworkHDAccountsConfig;
const index = 0; // index of hardhat account that you want to export
const wallet = ethers.Wallet.fromMnemonic(accounts.mnemonic, accounts.path + `/${index}`);
const params = { keyBytes: 32, ivBytes: 16, privateKey: wallet.privateKey };
try {
const bareKey = createFromPrivateKey(params);
const options = {
kdf: 'scrypt',
cipher: 'aes-128-ctr'
};
if (bareKey) {
const keyObject = 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);
}
- create
keyeth.ts
file
// keyeth.ts
import { getRandomBytesSync, getRandomBytes } from "ethereum-cryptography/random";
import { privateKeyVerify } from "ethereum-cryptography/secp256k1-compat";
import keythereum from "keythereum";
function isFunction(f: any): f is Function {
return typeof f === "function";
}
interface KeyParams {
keyBytes?: number;
ivBytes?: number;
privateKey: string;
}
interface PrivateKeyObject {
privateKey: Buffer;
iv: Buffer;
salt: Buffer;
}
function createFromPrivateKey(
params: KeyParams, cb?: any
): PrivateKeyObject | void {
const keyBytes = params.keyBytes || 32;
const ivBytes = params.ivBytes || 16;
const privateKey = Buffer.from(params.privateKey.slice(2), 'hex');
function checkBoundsAndCreateObject(randomBytes: Uint8Array): any {
randomBytes = Buffer.from(randomBytes);
if (!privateKeyVerify(privateKey)) {
return keythereum.create({ keyBytes, ivBytes }, cb);
}
return {
privateKey,
iv: randomBytes.slice(keyBytes, keyBytes + ivBytes),
salt: randomBytes.slice(keyBytes + ivBytes)
};
}
// synchronous key generation if callback not provided
if (!isFunction(cb)) {
return checkBoundsAndCreateObject(getRandomBytesSync(keyBytes + ivBytes + keyBytes));
}
// asynchronous key generation
getRandomBytes(keyBytes + ivBytes + keyBytes).then(
function (randomBytes: Uint8Array) {
cb(checkBoundsAndCreateObject(randomBytes));
}, function (err: any) {
cb(err);
}
);
}
export { createFromPrivateKey };
- create
account.js
file
// account.js
require('hardhat')
const keythereum = require('keythereum')
const keyeth = require('./keyeth')
const accounts = config.networks.hardhat.accounts
const index = 0 // index of hardhat account that you want to export
const wallet = ethers.Wallet.fromMnemonic(accounts.mnemonic, accounts.path + `/${index}`)
const params = { keyBytes: 32, ivBytes: 16, privateKey: wallet.privateKey }
const bareKey = keyeth.createFromPrivateKey(params)
const options = {
kdf: 'scrypt',
cipher: 'aes-128-ctr'
}
const keyObject = 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, `./`)
- create
keyeth.js
file
// keyeth.js
var random = require("ethereum-cryptography/random");
var secp256k1 = require("ethereum-cryptography/secp256k1-compat");
function isFunction(f) {
return typeof f === "function";
}
function createFromPrivateKey(params, cb) {
var keyBytes, ivBytes, self = this;
params = params || {};
keyBytes = params.keyBytes || this.constants.keyBytes;
ivBytes = params.ivBytes || this.constants.ivBytes;
var privateKey = Buffer.from(params.privateKey.slice(2), 'hex');
function checkBoundsAndCreateObject(randomBytes) {
randomBytes = Buffer.from(randomBytes);
if (!secp256k1.privateKeyVerify(privateKey)) return keythereum.create({ keyBytes, ivBytes }, cb);
return {
privateKey: privateKey,
iv: randomBytes.slice(keyBytes, keyBytes + ivBytes),
salt: randomBytes.slice(keyBytes + ivBytes)
};
}
// synchronous key generation if callback not provided
if (!isFunction(cb)) {
return checkBoundsAndCreateObject(random.getRandomBytesSync(keyBytes + ivBytes + keyBytes));
}
// asynchronous key generation
random.getRandomBytes(keyBytes + ivBytes + keyBytes).then(function (randomBytes) {
cb(checkBoundsAndCreateObject(randomBytes));
}, function (err) {
cb(err);
});
}
exports.createFromPrivateKey = createFromPrivateKey;
- 2.Import the hardhat wallet into ethcode

Import wallet
- 3.Now you should be able to sign your transaction using the hardhat wallet you imported. When asked for password use nothing and hit enter.