INVALID_FULL_PREFIX_SIGNATURE_FOR_PRECOMPILE error when trying to create a token on Hedera via a smart contract

huangapple go评论65阅读模式
英文:

INVALID_FULL_PREFIX_SIGNATURE_FOR_PRECOMPILE error when trying to create a token on Hedera via a smart contract

问题

我遇到了一个错误信息 INVALID_FULL_PREFIX_SIGNATURE_FOR_PRECOMPILE,尝试通过智能合约创建 Hedera 代币时。

涉及的函数旨在调用 HederaTokenService 预编译并创建新代币。目标是将调用者的账户指定为代币管理员和财政账户。

尽管该函数简单,但我无法创建代币,而是收到上述错误信息。

请指导我如何解决这个问题。谢谢。

英文:

I am encountering an error message INVALID_FULL_PREFIX_SIGNATURE_FOR_PRECOMPILE while attempting to create a Hedera Token through a smart contract.

The function in question is designed to call the HederaTokenService precompile and create a new token. The objective is to assign the caller's account as the token admin and the treasury account.

Despite the simplicity of the function, I am unable to create the token and instead receive the aforementioned error message.

function myCreateToken() public payable {
        IHederaTokenService.TokenKey[]
            memory keys = new IHederaTokenService.TokenKey[](0);

        IHederaTokenService.Expiry memory expiry = IHederaTokenService.Expiry(
            0,
            msg.sender,
            8000000
        );

        IHederaTokenService.HederaToken memory token = IHederaTokenService
            .HederaToken(
                "MyToken",
                "MTT",
                msg.sender,
                "",
                true,
                10000000,
                false,
                keys,
                expiry
            );

        (int responseCode, ) = HederaTokenService.createFungibleToken(
            token,
            10000000,
            NUM_DECIMALS
        );

        require(responseCode == HederaResponseCodes.SUCCESS);
    }

Please advise on how I can resolve this issue. Thank you.

答案1

得分: 0

在版本0.35.2中的安全模型更改后,智能合约不再能创建代币并将外部账户(EOA)指定为管理员或财政账户。这是因为需要用户账户的签名和用户明确授权以将其分配给特定角色。

要创建代币并将自己指定为管理员或财政账户,用户现在必须切换到使用 Hedera SDK 来创建代币。然而,智能合约仍然可以通过调用预编译函数来创建 Hedera 代币,前提是智能合约分配给了财政账户或管理员账户的角色。您可以通过将 msg.sender 更改为 address(this) 来实现这一点。

function myCreateToken() public payable {
    IHederaTokenService.TokenKey[] memory keys = new IHederaTokenService.TokenKey[](0);

    IHederaTokenService.Expiry memory expiry = IHederaTokenService.Expiry(
        0,
        address(this),
        8000000
    );

    IHederaTokenService.HederaToken memory token = IHederaTokenService.HederaToken(
        "MyToken",
        "MTT",
        address(this),
        "",
        true,
        10000000,
        false,
        keys,
        expiry
    );

    (int responseCode, ) = HederaTokenService.createFungibleToken(
        token,
        10000000,
        NUM_DECIMALS
    );

    require(responseCode == HederaResponseCodes.SUCCESS);
}
英文:

Following the security model change in version 0.35.2, it is no longer possible for smart contracts to create a token and assign an externally owned account (EOA) as the admin or treasury account. This is due to the requirement for signatures from the user account and explicit authorization from the user to assign them to a specific role.

To create a token and assign oneself as the admin or treasury account, users must now switch to using Hedera SDK to create tokens instead. However, smart contracts can still create a Hedera Token through precompile calls, provided that the smart contract is assigned to the role of the treasury account or admin account. You can do this by changing from msg.sender to address(this)

function myCreateToken() public payable {
        IHederaTokenService.TokenKey[]
            memory keys = new IHederaTokenService.TokenKey[](0);

        IHederaTokenService.Expiry memory expiry = IHederaTokenService.Expiry(
            0,
            address(this),
            8000000
        );

        IHederaTokenService.HederaToken memory token = IHederaTokenService
            .HederaToken(
                "MyToken",
                "MTT",
                address(this),
                "",
                true,
                10000000,
                false,
                keys,
                expiry
            );

        (int responseCode, ) = HederaTokenService.createFungibleToken(
            token,
            10000000,
            NUM_DECIMALS
        );

        require(responseCode == HederaResponseCodes.SUCCESS);
    }

答案2

得分: 0

I created a token using Hedera SDK, but not able to mint a token via smart contracts, throwing error INVALID_FULL_PREFIX_SIGNATURE_FOR_PRECOMPILE

我使用Hedera SDK创建了一个代币,但无法通过智能合约铸造代币,抛出错误INVALID_FULL_PREFIX_SIGNATURE_FOR_PRECOMPILE

function mintIt(bytes[] memory _metadata, address _nftOwner) external onlyOwner returns(bool, int64, address) {
int64 _amount = 0;
(int response, int64 newTotalSupply, int64[] memory serialNumbers) = HederaTokenService.mintToken(tokenId, _amount, _metadata);

if (response != HederaResponseCodes.SUCCESS && newTotalSupply == 0) {
    return(false, 0, _nftOwner);
} else {
    transferNft(tokenId, _nftOwner, serialNumbers[0]);
    NftToSeller[serialNumbers[0]] = _nftOwner;
    return(true, serialNumbers[0], _nftOwner);
}

}

英文:

I created a token using Hedera SDK , but not able to mint a token via smart contracts , throwing error INVALID_FULL_PREFIX_SIGNATURE_FOR_PRECOMPILE

function mintIt(bytes[] memory _metadata,address _nftOwner) external onlyOwner returns(bool,int64,address) {
int64 _amount=0;
(int response, int64 newTotalSupply, int64[] memory serialNumbers) = HederaTokenService.mintToken(tokenId, _amount, _metadata);

    if (response != HederaResponseCodes.SUCCESS && newTotalSupply==0) {
        return(false,0,_nftOwner);
    }
    else{
        
        transferNft(tokenId,_nftOwner,serialNumbers[0]);
        NftToSeller[serialNumbers[0]]=_nftOwner;
        return(true,serialNumbers[0],_nftOwner);
    }
}

huangapple
  • 本文由 发表于 2023年4月17日 16:47:49
  • 转载请务必保留本文链接:https://go.coder-hub.com/76033277.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定