创建新帐户失败 INSUFFICIENT_TX_FEE

Creating new account fails with INSUFFICIENT_TX_FEE

我一直在研究 Hedera SDK 及其 Python 的包装器。几个小时前,我有一个工作示例,我能够创建一个具有初始余额的新帐户。

现在,几个小时后,相同的代码失败并出现以下错误 (Testnet):

Exception has occurred: JavaException
JVM exception occurred: Hedera transaction `0.0.29467648@1642981813.928678616` 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)

我一直在努力寻找根本原因并进行修复,但到目前为止运气不佳(官方 docs/github/anywhere)。我在 GitHub 中发现了一些评论,其中提到在使用大于 100_000 tinybars 的值配置客户端时必须指定最大交易费用。我做了但是还是一样的错误

这是我用来配置客户端的辅助函数:

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

这是 class 创建新帐户并引发错误的地方:

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()}"
            )

这就是我 creating/loading 我的帐户:

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")

由于我是 运行 我在测试网中的代码,我的帐户 (root_account) 有足够的 HBAR 来支付创建新帐户 (new_account) 的费用。

常春藤-sdk-py: 2.6.0

回购: https://github.com/ccddan/hbar-hello-world/blob/feature/nfts/src/nft.py

欢迎任何提示,包括 良好 Hedera 文档的链接。谢谢!

事实证明,在撰写本文时,client.setMaxTransactionFee() 的最小金额必须为 1 HBAR。这在文档中没有明确提及,您不能尝试使用较低的值:

https://docs.hedera.com/guides/getting-started/environment-set-up

docs screenshot here

使用 client.setMaxTransactionFee(Hbar(1)) 更新我的客户端配置后,一切正常