{"size": 1223, "ext": "js", "max_stars_repo_path": "src/service/accountCreate.js", "max_stars_repo_name": "pixelscript-io/hedera-hts-demo", "max_stars_repo_stars_event_min_datetime": "2020-10-29T16:39:45.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-17T21:13:17.000Z", "max_issues_repo_path": "src/service/accountCreate.js", "max_issues_repo_name": "pixelscript-io/hedera-hts-demo", "max_issues_repo_issues_event_min_datetime": "2020-11-06T20:39:12.000Z", "max_issues_repo_issues_event_max_datetime": "2022-02-27T10:34:22.000Z", "max_forks_repo_path": "src/service/accountCreate.js", "max_forks_repo_name": "pixelscript-io/hedera-hts-demo", "max_forks_repo_forks_event_min_datetime": "2020-12-08T12:01:01.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-29T19:36:23.000Z"}
{"max_stars_count": 59, "max_issues_count": 6, "max_forks_count": 42, "avg_line_length": 25.4791666667, "max_line_length": 71, "alphanum_fraction": 0.6696647588}
import { hederaClient } from "./client";
import { EventBus } from "@/eventBus";
import {notifyError} from "@/utils";

const {
  PrivateKey,
  AccountCreateTransaction,
  Hbar
} = require("@hashgraph/sdk");

export async function accountCreate(wallet) {
  const client = hederaClient();

  try {

    const privateKey = await PrivateKey.generate();

    const response = await new AccountCreateTransaction()
      .setKey(privateKey.publicKey)
      .setInitialBalance(new Hbar(process.env.VUE_APP_INITIAL_BALANCE))
      .execute(client);

    const transactionReceipt = await response.getReceipt(client);
    const newAccountId = transactionReceipt.accountId;

    const transaction = {
      id: response.transactionId.toString(),
      type: "cryptoCreate",
      inputs: "initialBalance=" + process.env.VUE_APP_INITIAL_BALANCE,
      outputs: "accountId=" + newAccountId.toString()
    };
    EventBus.$emit("addTransaction", transaction);

    return {
      accountId: newAccountId.toString(),
      account: {
        wallet: wallet,
        privateKey: privateKey.toString(),
        tokenRelationships: {}
      }
    };
  } catch (err) {
    notifyError(err.message);
    console.error(err);
    return {};
  }
}
