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.
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);
}