Skip to main content

Create your ECDSA Account

Elliptic Curve Digital Signature Algorithm-based accounts with an Alias

info

How to create an ECDSA-based account with an alias on the Hedera network

Creating an ECDSA-Based will allow you to begin interactying with the JSON RPC Relay on Hedera. Currently, the Hedera JSON-RPC Relay only supports Hedera accounts with an alias set (i.e., public address) based on its ECDSA public key.

To build on Hedera using familiar Ethereum tools like Web3JS, Truffle, Ethers, and Hardhat, developers can create an ECDSA-based account and utilize the Hedera JSON RPC Relay. Follow the steps below for a straightforward process.

1. Prepare your environment

import { Client, PrivateKey, AccountInfoQuery, TransferTransaction, Hbar} from "@hashgraph/sdk";const operatorAccountId = `<YOUR_HEDERA_TESTNET_ACCOUNT_ID>`;const operatorPrivateKey = `<YOUR_HEDERA_TESTNET_PRIVATE_KEY>`;const client = Client.forTestnet();client.setOperator(operatorAccountId, operatorPrivateKey);const newPrivateKey = PrivateKey.generateECDSA();console.log(`The raw ECDSA private key (use this for JSON RPC wallet import): ${newPrivateKey.toStringRaw()}`);const newPublicKey = newPrivateKey.publicKey;console.log(`The raw ECDSA public key (use this for JSON RPC wallet import): ${newPublicKey.toStringRaw()}`);const aliasAccountId = newPublicKey.toAccountId(0, 0);console.log(`The alias account id: ${aliasAccountId}`);

2. Create a function to help log your account info

const getAccountInfo = async (accountId) => {    const info = await new AccountInfoQuery()        .setAccountId(accountId)        .execute(client);    console.log(`The normal account ID: ${info.accountId}`);    console.log(`Account Balance: ${info.balance}`);}

3. Create a function to help you see your account info

const getAccountInfo = async (accountId) => {    const info = await new AccountInfoQuery()        .setAccountId(accountId)        .execute(client);    console.log(`The normal account ID: ${info.accountId}`);    console.log(`Account Balance: ${info.balance}`);}

4. Get your Console Output ready

const main = async () => {    await setAliasAccountUsingTx(operatorAccountId, aliasAccountId, 10);    await getAccountInfo(aliasAccountId);}

5. Final Details

To complete the account registration on the Hedera network, it is necessary to deposit $HBAR to the new wallet. The balance of the new account will reflect the deposit amount minus the transaction fee imposed by the network. Verifying the successful registration of your account is a simple and quick process that can be accomplished using the Arkhia Explorer.

6. Code Check

Verify that you have everything you need

import { Client, PrivateKey, AccountInfoQuery, TransferTransaction, Hbar} from "@hashgraph/sdk";const operatorAccountId = `<YOUR_HEDERA_TESTNET_ACCOUNT_ID>`;const operatorPrivateKey = `<YOUR_HEDERA_TESTNET_PRIVATE_KEY>`;const client = Client.forTestnet();client.setOperator(operatorAccountId, operatorPrivateKey);const newPrivateKey = PrivateKey.generateECDSA();console.log(`The raw ECDSA private key (use this for JSON RPC wallet import): ${newPrivateKey.toStringRaw()}`);const newPublicKey = newPrivateKey.publicKey;console.log(`The raw ECDSA public key (use this for JSON RPC wallet import): ${newPublicKey.toStringRaw()}`);const aliasAccountId = newPublicKey.toAccountId(0, 0);console.log(`The alias account id: ${aliasAccountId}`);const setAliasAccountUsingTx = async (senderAccountId, receiverAccountId, amount) => {    const transferToAliasTx = await new TransferTransaction()        .addHbarTransfer(senderAccountId, new Hbar(-amount))        .addHbarTransfer(receiverAccountId, new Hbar(amount))        .execute(client);    await transferToAliasTx.getReceipt(client);}const getAccountInfo = async (accountId) => {    const info = await new AccountInfoQuery()        .setAccountId(accountId)        .execute(client);    console.log(`The normal account ID: ${info.accountId}`);    console.log(`Account Balance: ${info.balance}`);}const main = async () => {    await setAliasAccountUsingTx(operatorAccountId, aliasAccountId, 10);    await getAccountInfo(aliasAccountId);}