首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用INSUFFICIENT_TX_FEE创建新帐户失败

使用INSUFFICIENT_TX_FEE创建新帐户失败
EN

Stack Overflow用户
提问于 2022-01-24 01:23:21
回答 1查看 343关注 0票数 0

我一直在使用Hedera和它的Python包装器。几个小时前,我有一个工作的例子,我能够创建一个新的帐户与初始余额。

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

代码语言:javascript
复制
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)

我一直试图找出根本原因并修复,但到目前为止(官方文档/github/anywhere)没有任何运气。我在GitHub中发现了一些注释,其中提到,当配置客户端的值大于100_000 tinybar时,必须指定最大事务费。我做到了,但还是犯了同样的错误。

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

代码语言:javascript
复制
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

这是创建新帐户和抛出错误的类:

代码语言:javascript
复制
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()}"
            )

我就是这样创建/加载我的帐户的:

代码语言:javascript
复制
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)的费用。

hedera-sdk-py:2.6.0

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

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

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2022-01-27 03:31:12

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

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

医生截图

使用client.setMaxTransactionFee(Hbar(1))更新我的客户端配置后,一切都按预期工作。

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/70828049

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档