Reputation: 21
I've been playing around with the Hedera SDK and with it's wrapper for Python. A couple of hours ago I had a working example were I was able to create a new account with an initial balance.
Now, a couple of hours later, the same code is failling with the following error (Testnet):
Exception has occurred: JavaException
JVM exception occurred: Hedera transaction `[email protected]` failed pre-check with the status `INSUFFICIENT_TX_FEE` com.hedera.hashgraph.sdk.PrecheckStatusException
File "/home/.../src/utils/hedera.py", line 101, in __init__
AccountCreateTransaction()
File "/home/.../src/main.py", line 21, in <module>
new_account: HederaAccount = HederaAccount(client, initial_balance=100_000)
I've been trying to find the root cause and fix but no luck so far (oficial docs/github/anywhere). I found some comments in GitHub where it was mentioned that you must specify the max transaction fee when configuring the client with a value greater than 100_000 tinybars. I did it but still the same error.
This is the helper function I'm using to configure the client:
def get_client(
account_id: Optional[AccountId] = None, private_key: Optional[PrivateKey] = None
) -> Client:
logger.debug(f"Hedera::get_client - create account_id")
_account_id: AccountId = (
account_id if account_id else Hedera.load_account_from_id()
)
logger.debug(f"Hedera::get_client - create account_id")
private_key: PrivateKey = (
private_key
if private_key
else Hedera.load_private_key(config["account"]["private_key"])
)
logger.debug(f"Hedera::get_client - create client")
client: Client = (
Client.forTestnet()
if config["env"] == DeploymentEnv.Development.value
else Client.forMainnet()
)
logger.debug(f"Hedera::get_client - set operator")
client.setOperator(_account_id, private_key)
# I just added this line (not required a couple of hours ago), still same error
client.setMaxTransactionFee(Hbar.fromTinybars(200_000))
logger.debug(f"Hedera::get_client - client: {client.toString()}")
return client
And this is the class where the new account is created and where the error is thrown:
class HederaAccount:
def __init__(
self,
client,
account_id: Optional[AccountId] = None,
private_key: Optional[PrivateKey] = None,
initial_balance: Optional[int] = 1_000_000,
) -> None:
self.client: Client = client
if account_id:
logger.debug(
f"HederaAccount::init - existent account id: {account_id.toString()}"
)
if not private_key:
raise Exception(
"When loading an existing account, 'private_key' is required"
)
self.account_id = account_id
self.private_key = private_key
self.public_key = self.private_key.getPublicKey()
self.node_id: Optional[AccountId] = None
else:
self.private_key: PrivateKey = PrivateKey.generate()
self.public_key: PublicKey = self.private_key.getPublicKey()
tx_resp: TransactionResponse = (
AccountCreateTransaction()
.setKey(self.public_key)
.setInitialBalance(Hbar.fromTinybars(initial_balance))
.execute(client)
)
self.node_id: AccountId = tx_resp.nodeId
tx_receipt: TransactionReceipt = tx_resp.getReceipt(self.client)
self.account_id: AccountId = tx_receipt.accountId
logger.debug(
f"HederaAccount::init - new account id: {self.account_id.toString()}"
)
And this is how I'm creating/loading my accounts:
root_account_id = Hedera.load_account_id()
root_private_key = Hedera.load_private_key()
client = Hedera.get_client(account_id=root_account_id, private_key=root_private_key)
# Load root account (no problems here)
root_account: HederaAccount = HederaAccount(
client, account_id=root_account_id, private_key=root_private_key
)
logger.info(f"Root account: {root_account}")
logger.info("\n\n")
# Create a new account (Failing here)
new_account: HederaAccount = HederaAccount(client, initial_balance=100_000)
logger.info(f"New account: {new_account}")
logger.info("\n\n")
Since I'm running my code in the Testnet, my account (root_account) has enough HBARs to pay the fees to create the new account (new_account).
hedera-sdk-py: 2.6.0
Repo: https://github.com/ccddan/hbar-hello-world/blob/feature/nfts/src/nft.py
Any hint is welcome, including links to good Hedera documentation. Thanks!
Upvotes: 0
Views: 787
Reputation: 21
It turns out that, at the time of this writing, the minimum amount for client.setMaxTransactionFee()
must be 1 HBAR. This is not explicitly mentioned in the documentation and you cannot try with lower values:
https://docs.hedera.com/guides/getting-started/environment-set-up
After updating my client configuration with client.setMaxTransactionFee(Hbar(1))
everything works as expected
Upvotes: 2