Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

When you call the create NFT function it always fails with an "UNKNOWN" error #80

Closed
jruffer opened this issue Oct 3, 2022 · 8 comments
Labels
bug Something isn't working
Milestone

Comments

@jruffer
Copy link

jruffer commented Oct 3, 2022

Description

contract NFTCreator is HederaTokenService, KeyHelper, ExpiryHelper {
    event LogResponseCode(int responseCode);

    function createNft(
        string memory name,
        string memory symbol,
        string memory memo,
        int64 maxSupply,
        uint32 autoRenewPeriod
    ) external payable returns (address){

        IHederaTokenService.TokenKey[] memory keys = new IHederaTokenService.TokenKey[](1);
        // Set this contract as supply
        keys[0] = getSingleKey(KeyType.SUPPLY, KeyValueType.CONTRACT_ID, address(this));

        IHederaTokenService.HederaToken memory token;
        token.name = name;
        token.symbol = symbol;
        token.memo = memo;
        token.treasury = address(this);
        token.tokenSupplyType = true; // set supply to FINITE
        token.maxSupply = maxSupply;
        token.tokenKeys = keys;
        token.freezeDefault = false;
        token.expiry = createAutoRenewExpiry(address(this), autoRenewPeriod); // Contract automatically renew by himself

        (int responseCode, address createdToken) = createNonFungibleToken(token); // <--- responseCode is UNKNOWN

        if(responseCode != HederaResponseCodes.SUCCESS){
//            revert("Failed to create non-fungible token");
            emit LogResponseCode(responseCode);
        }
        return createdToken;
    }
}

Example deployer:

I will update this code in a few. 

Example of execution:
https://hashscan.io/#/testnet/transaction/0.0.48191765-1664809268-533358275?t=1664809279.658258643

If you look at the bottom of the logs data view, you will see the UNKNOWN error code.
0x0000000000000000000000000000000000000000000000000000000000000015

Steps to reproduce

Deploy contract...
wait a few seconds, and you will see the error...
@bgok

Additional context

No response

Hedera network

testnet

Version

v0.1.0

Operating system

No response

@jruffer jruffer added the bug Something isn't working label Oct 3, 2022
@shemnon
Copy link
Contributor

shemnon commented Oct 3, 2022

I wonder if this is an issue because it's in a ContractCreateTransaction. But per the deployer the function createNft is not being called. Is this the full contract as deployed? Or is there a constructor to the contract?

Rather than using a one-step deployer, could you deploy the contract, and then call the createNft function after the deployment succeds? This "init" pattern is somewhat common for high cost contract deployments.

@jruffer
Copy link
Author

jruffer commented Oct 4, 2022

We fixed the formatting and the deployer is incomplete we will update it. We basically took this sample code provided, ran it and it is not working. Do you happen to have sample code that will allow us to deploy and make calls to it?
Here is where you got the samples https://docs.hedera.com/guides/getting-started/try-examples/create-and-transfer-an-nft-using-a-solidity-contract
If you do steps 1 and 2 you should also see the same error messages we are running into.

@shemnon
Copy link
Contributor

shemnon commented Oct 4, 2022

There should be two steps in the deployer code, because the contract has no constructor. The TX link you gave me couldn't have come from that code snippet alone, there had to be constructor code running a function call after the contract deployment.

@Nana-EC
Copy link
Collaborator

Nana-EC commented Oct 4, 2022

Hi @jruffer thanks for the ticket.
Due to the complexity and configurability of smart contracts and HTS it helps speed things up and avoid misconceptions when issues have detailed and reproduce-able steps to help investigation.

Could you please up date the Description and Steps to reproduce sections with the reproduce-able sequenced steps you took capturing

  • all contract code (deployment and execution)
  • functions called and with which params
  • what tools or clients you're using
  • any produced state details such as account/contract/transaction ids

You had some but if you could complete it then we can take a look and adequately triage it.
Thanks

@cisc0f
Copy link

cisc0f commented Oct 5, 2022

Hey @Nana-EC! I created the example in the docs that @jruffer is talking about. I had some time to review it, and the type of the maxSupply field in the HederaToken struct seems to be the problem. The older precompiled version used to have uint32, but now it's int64. By changing again to uint32 in the IHederaTokenService.sol the example works perfectly.

(btw before changing to uint32 I also tried to work with int64 by changing the type in the js script and also in my contract but I was still getting UNKNOWN)

See line here:

There's the full example in my repo here: https://github.com/cisc0f/hedera/tree/main/src/002_nft_hscs_hts

@bgok
Copy link

bgok commented Oct 5, 2022

@cisc0f Woo! That fixed it. Thank you.

@bgok
Copy link

bgok commented Oct 5, 2022

@cisc0f Do you want to do a pull request to fix the underlying issue in this library?

@jruffer jruffer closed this as completed Oct 5, 2022
@Nana-EC
Copy link
Collaborator

Nana-EC commented Oct 5, 2022

Hi @jruffer and @cisc0f and @bgok just to close this off properly.
@lukelee-sl did a quick investigation and the issue here are the changes are yet to hit the testnet environment.

What seems to have happened is the changes that represented the changes in services went in here before the services version was deployed.
Once 0.30 of services hit testnet the call should work without the manual workaround you've added.

Additionally, we're working on versioning this repo to make it easy to coordinate such changes in the future

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
Archived in project
Development

No branches or pull requests

5 participants