Skip to content

I have some bug to create funded account on my priveate hedera solo network. #2370

@topdevStar1126

Description

@topdevStar1126

Describe the bug

/**
 * Account Creation with AFLAO Funding
 * Based on official Hedera SDK documentation and best practices
 */

const { 
  Client, 
  PrivateKey, 
  AccountId, 
  AccountCreateTransaction,
  TransferTransaction, 
  Hbar,
  Status,
  TransactionId
} = require("@hashgraph/sdk");

// Helper function to save account data
function saveAccountData(evmAddress, privateKey, publicKey, balance, accountId = null, transactionId = null) {
  const fs = require('fs');
  const accountData = {
    created: new Date().toISOString(),
    evmAddress: evmAddress,
    privateKey: privateKey.toString(),
    privateKeyRaw: `0x${privateKey.toStringRaw()}`,
    publicKey: publicKey.toString(),
    accountId: accountId,
    transactionId: transactionId,
    initialBalance: balance,
    network: {
      chainId: 298,
      rpcUrl: "http://51.75.53.241:17546",
      mirrorNode: "http://51.75.53.241:15551",
      consensusNodes: [
        "51.75.53.241:50311",
        "51.75.53.241:50321", 
        "51.75.53.241:50331"
      ]
    }
  };
  
  const filename = `aflao-account-${Date.now()}.json`;
  fs.writeFileSync(filename, JSON.stringify(accountData, null, 2));
  console.log(`\n Account saved to: ${filename}`);
  
  return accountData;
}

async function createFundedAccount() {
  console.log(' CREATING FUNDED ACCOUNT - HEDERA SDK');
  console.log('━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\n');

  // Generate new ED25519 key pair (recommended by Hedera docs)
  const newPrivateKey = PrivateKey.generateED25519();
  const newPublicKey = newPrivateKey.publicKey;
  
  // Get EVM address from private key
  const { privateKeyToAccount } = require('viem/accounts');
  const evmAccount = privateKeyToAccount(`0x${newPrivateKey.toStringRaw()}`);
  
  console.log(' NEW ACCOUNT GENERATED:');
  console.log('━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━');
  console.log('Private Key (DER format):');
  console.log(`${newPrivateKey.toString()}\n`);
  console.log('Private Key Raw (32 bytes):');
  console.log(`0x${newPrivateKey.toStringRaw()}\n`);
  console.log('Public Key:');
  console.log(`${newPublicKey.toString()}\n`);
  console.log('EVM Address (derived):');
  console.log(`${evmAccount.address}`);
  console.log('━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\n');

  // Setup client with all nodes
  const nodes = {
    "51.75.53.241:50311": new AccountId(3),
    "51.75.53.241:50321": new AccountId(4),
    "51.75.53.241:50331": new AccountId(5)
  };
  
  const client = Client.forNetwork(nodes);
  
  // Set mirror node network
  client.setMirrorNetwork(["51.75.53.241:15551"]);
  
  // Set operator account (from local network setup docs)
  const operatorAccountId = AccountId.fromString("0.0.2");
  const operatorKey = PrivateKey.fromString("302e020100300506032b65700422042091132178e72057a1d7528025956fe39b0b847f200ab59b2fdd367017f3087137");
  client.setOperator(operatorAccountId, operatorKey);
  
  // Configure client settings (from client configuration docs)
  client.setDefaultMaxTransactionFee(new Hbar(100)); // Set reasonable max fee
  client.setDefaultMaxQueryPayment(new Hbar(50));    // Set query payment limit
  client.setRequestTimeout(120000);                   // 2 minute timeout
  
  console.log(' Client configured for AFLAO Solo testnet');
  console.log(`   Operator: ${operatorAccountId.toString()}`);
  console.log(`   Network: Solo testnet (3 nodes)`);
  console.log(`   Mirror node: 51.75.53.241:15551\n`);

  try {
    // First check if platform accepts AccountCreateTransaction
    console.log(' Testing network capabilities...\n');
    
    // Try a simple transfer first to see if network works
    console.log('離 Testing with self-transfer...');
    try {
      const testTx = await new TransferTransaction()
        .addHbarTransfer(operatorAccountId, new Hbar(-1))
        .addHbarTransfer(operatorAccountId, new Hbar(1))
        .setMaxTransactionFee(new Hbar(2))
        .execute(client);
      
      const testReceipt = await testTx.getReceipt(client);
      console.log(`✅ Network is active! Transfer status: ${testReceipt.status}\n`);
    } catch (testError) {
      console.log(`⚠️  Network test failed: ${testError.message}\n`);
    }
    
    // Try hollow account creation via transfer instead of AccountCreateTransaction
    console.log(' Creating account via transfer (hollow account method)...\n');
    
    const transferTx = new TransferTransaction()
      .addHbarTransfer(operatorAccountId, new Hbar(-1000))
      .addHbarTransfer(evmAccount.address, new Hbar(1000))
      .setMaxTransactionFee(new Hbar(20))
      .setTransactionMemo("AFLAO hollow account");
    
    console.log('⏳ Submitting transfer to EVM address...');
    console.log(`   From: ${operatorAccountId}`);
    console.log(`   To: ${evmAccount.address}`);
    console.log(`   Amount: 1000 HBAR\n`);
    
    const txResponse = await transferTx.execute(client);
    
    console.log(`✅ Transfer submitted!`);
    console.log(`   Transaction ID: ${txResponse.transactionId.toString()}`);
    console.log(`   Node ID: ${txResponse.nodeId.toString()}`);
    console.log(`   Transaction Hash: ${Buffer.from(txResponse.transactionHash).toString('hex')}\n`);
    
    // Get the receipt
    console.log('⏳ Waiting for consensus...');
    const receipt = await txResponse.getReceipt(client);
    
    if (receipt.status === Status.Success) {
      console.log(`\n✅ HOLLOW ACCOUNT CREATED SUCCESSFULLY!`);
      console.log(`━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━`);
      if (receipt.accountId) {
        console.log(`   Account ID: ${receipt.accountId.toString()}`);
      }
      console.log(`   Initial Balance: 1000 AFLAO`);
      console.log(`   EVM Address: ${evmAccount.address}`);
      console.log(`━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━`);
      
      const accountData = saveAccountData(
        evmAccount.address,
        newPrivateKey,
        newPublicKey,
        "1000 AFLAO",
        receipt.accountId?.toString() || null,
        txResponse.transactionId.toString()
      );
      
      console.log('\n Account is ready to use!');
      console.log('Import the private key into your wallet to access the account.');
      
      client.close();
      return accountData;
    } else {
      console.log(`\n❌ Transfer failed with status: ${receipt.status.toString()}`);
      throw new Error(`Transfer failed: ${receipt.status.toString()}`);
    }
    
  } catch (error) {
    console.log(`\n⚠️  Account creation failed: ${error.message}`);
    
    // Log detailed error information
    console.log('\n DETAILED ERROR INFORMATION:');
    console.log('━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━');
    
    // Basic error info
    console.log('Error Type:', error.constructor.name);
    console.log('Error Name:', error.name);
    console.log('Error Message:', error.message);
    
    // Hedera specific error details
    if (error.status) {
      console.log('\n Hedera Status Information:');
      console.log('   Status:', error.status.toString());
      console.log('   Status Code:', error.status._code);
      console.log('   Status Name:', error.status._name);
    }
    
    if (error.transactionId) {
      console.log('\n Transaction Information:');
      console.log('   Transaction ID:', error.transactionId.toString());
      console.log('   Account ID:', error.transactionId.accountId?.toString());
      console.log('   Valid Start:', error.transactionId.validStart?.toString());
    }
    
    if (error.nodeAccountId) {
      console.log('\n️  Node Information:');
      console.log('   Node Account ID:', error.nodeAccountId.toString());
      console.log('   Shard:', error.nodeAccountId.shard);
      console.log('   Realm:', error.nodeAccountId.realm);
      console.log('   Num:', error.nodeAccountId.num);
    }
    
    // Network/GRPC errors
    if (error.grpc) {
      console.log('\n GRPC Error Details:');
      console.log('   GRPC Status:', error.grpc);
      console.log('   GRPC Code:', error.grpc.code);
      console.log('   GRPC Details:', error.grpc.details);
      console.log('   GRPC Metadata:', error.grpc.metadata);
    }
    
    // Timeout or network errors
    if (error.code) {
      console.log('\n⚡ Network Error Details:');
      console.log('   Error Code:', error.code);
      console.log('   System Error:', error.syscall);
      console.log('   Error Number:', error.errno);
      console.log('   Address:', error.address);
      console.log('   Port:', error.port);
    }
    
    // Receipt information if available
    if (error.receipt) {
      console.log('\n Receipt Information:');
      console.log('   Receipt Status:', error.receipt.status?.toString());
      console.log('   Exchange Rate:', error.receipt.exchangeRate?.toString());
      console.log('   Topic Running Hash:', error.receipt.topicRunningHash);
    }
    
    // Stack trace
    console.log('\n Stack Trace:');
    console.log(error.stack);
    
    // All properties
    console.log('\n All Error Properties:');
    const allProps = {};
    for (let prop in error) {
      allProps[prop] = error[prop];
    }
    console.log(JSON.stringify(allProps, null, 2));
    
    // Full error object with all hidden properties
    console.log('\n Complete Error Object (including non-enumerable):');
    const errorDetails = JSON.stringify(error, Object.getOwnPropertyNames(error), 2);
    console.log(errorDetails);
    
    // Check if it's a specific known error type
    if (error.message.includes('PLATFORM_NOT_ACTIVE')) {
      console.log('\n⚠️  PLATFORM_NOT_ACTIVE: The Hedera network is not accepting this type of transaction.');
      console.log('   This usually means the network is in maintenance or restricted mode.');
    }
    
    if (error.message.includes('UNKNOWN')) {
      console.log('\n⚠️  UNKNOWN STATUS: The transaction was submitted but the network returned an unknown status.');
      console.log('   This could indicate:');
      console.log('   - Network consensus issues');
      console.log('   - Node synchronization problems');
      console.log('   - Platform restrictions on account creation');
    }
    
    if (error.message.includes('timeout') || error.message.includes('TIMEOUT')) {
      console.log('\n⏱️  TIMEOUT: The request exceeded the time limit.');
      console.log('   This could indicate:');
      console.log('   - Network connectivity issues');
      console.log('   - Nodes are overloaded or unresponsive');
      console.log('   - Firewall blocking the connection');
    }
    
    console.log('━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\n');
    
    // Save account credentials anyway
    console.log(' Your account credentials are still valid!');
    console.log('   You can import the private key and receive funds later.\n');
    
    const accountData = saveAccountData(
      evmAccount.address,
      newPrivateKey,
      newPublicKey,
      "0 AFLAO (unfunded)",
      null,
      null
    );
    
    console.log('\n Next steps:');
    console.log('1. Import the private key into your wallet');
    console.log('2. Share your EVM address to receive funds:');
    console.log(`   ${evmAccount.address}`);
    
    client.close();
    return accountData;
  }
}

// Run the account creation
createFundedAccount()
  .then(() => {
    console.log('\n✅ Process completed successfully!');
    process.exit(0);
  })
  .catch(error => {
    console.error('\n❌ Unexpected error:', error);
    process.exit(1);
  });

Above is code for creating funded hedera account.

The name "Aflao" is my private network's name.

The bug is like this:

 CREATING FUNDED ACCOUNT - HEDERA SDK
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

 NEW ACCOUNT GENERATED:
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
Private Key (DER format):
302e020100300506032b6570042204207d9749be73eeb483f6bb3dd8fe87ac9d0d282fd5eb7fc23d6db29310c6dcd6f2

Private Key Raw (32 bytes):
0x7d9749be73eeb483f6bb3dd8fe87ac9d0d282fd5eb7fc23d6db29310c6dcd6f2

Public Key:
302a300506032b657003210035150aa251f5ef47750078df45e7b342ce9b25059d3f3d58df64eb078418b79f

EVM Address (derived):
0x89BE1065afE12884a1ae761E8003d66E87DD27C5
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

 Client configured for AFLAO Solo testnet
   Operator: 0.0.2
   Network: Solo testnet (3 nodes)
   Mirror node: 51.75.53.241:15551

 Testing network capabilities...

離 Testing with self-transfer...
⚠️  Network test failed: max attempts of 10 was reached for request with last error being: UNKNOWN

 Creating account via transfer (hollow account method)...

⏳ Submitting transfer to EVM address...
   From: 0.0.2
   To: 0x89BE1065afE12884a1ae761E8003d66E87DD27C5
   Amount: 1000 HBAR

✅ Transfer submitted!
   Transaction ID: 0.0.2@1753780575.024770592
   Node ID: 0.0.5
   Transaction Hash: 285a727ad90c791285631dea9dde307cc964a38732e6bd4e18a3dedf5486c62c5fd7324e3104e5b10a55517dd356ed01

⏳ Waiting for consensus...

⚠️  Account creation failed: max attempts of 10 was reached for request with last error being: UNKNOWN

 DETAILED ERROR INFORMATION:
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
Error Type: MaxAttemptsOrTimeoutError
Error Name: Error
Error Message: max attempts of 10 was reached for request with last error being: UNKNOWN

️  Node Information:
   Node Account ID: 0.0.5
   Shard: undefined
   Realm: undefined
   Num: undefined

 Stack Trace:
Error: max attempts of 10 was reached for request with last error being: UNKNOWN
    at TransactionReceiptQuery.execute (/home/ubuntu/AflaoWallet/node_modules/@hashgraph/sdk/lib/Executable.cjs:692:11)
    at async TransactionResponse.getReceipt (/home/ubuntu/AflaoWallet/node_modules/@hashgraph/sdk/lib/transaction/TransactionResponse.cjs:85:17)
    at async createFundedAccount (/home/ubuntu/AflaoWallet/create-account-simple.js:141:21)

 All Error Properties:
{
  "nodeAccountId": "0.0.5"
}

 Complete Error Object (including non-enumerable):
{
  "message": "max attempts of 10 was reached for request with last error being: UNKNOWN",
  "nodeAccountId": "0.0.5"
}

⚠️  UNKNOWN STATUS: The transaction was submitted but the network returned an unknown status.
   This could indicate:
   - Network consensus issues
   - Node synchronization problems
   - Platform restrictions on account creation
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

 Your account credentials are still valid!
   You can import the private key and receive funds later.


 Account saved to: aflao-account-1753780637598.json

 Next steps:
1. Import the private key into your wallet
2. Share your EVM address to receive funds:
   0x89BE1065afE12884a1ae761E8003d66E87DD27C5

✅ Process completed successfully!

I can not sure what the issue is. I need your help urgently, Can you please check this issue?

Describe the expected behavior

Can you please check above issue and give me correct approach to create funded account?

To Reproduce

Can you please check above issue and give me correct approach to create funded account?

Additional Context

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugA error that causes the feature to behave differently than what was expected based on design docsPending TriageNew issue that needs to be triaged by the team

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions