Errors

This guide covers common errors, debugging techniques, and solutions for the Tokenization Precompile.

Critical: uint64 vs uint256

The #1 cause of errors for new developers.

BitBadges uses uint64 internally for timestamps and IDs. Using uint256 max values will cause errors.

// ❌ WRONG - Will cause "range overflow" error
string memory ownershipJson = TokenizationJSONHelpers.uintRangeToJson(1, type(uint256).max);

// βœ… CORRECT - Use the FOREVER constant
string memory ownershipJson = TokenizationJSONHelpers.uintRangeToJson(
    1,
    TokenizationJSONHelpers.FOREVER  // = type(uint64).max = 18446744073709551615
);

Available Constants (in TokenizationJSONHelpers and TokenizationHelpers):

Constant
Value
Use Case

FOREVER

18446744073709551615

Ownership times that never expire

MAX_TIME

18446744073709551615

Maximum valid timestamp

MAX_ID

18446744073709551615

Maximum valid token ID

MIN_ID

1

Minimum valid ID (ranges typically start at 1)

FOREVER_STR

"18446744073709551615"

For direct JSON string use


Error Handling in Solidity

Basic Error Handling

Using TokenizationErrors Library


Common Errors and Solutions

1. Range Value Overflow

Error:

Cause: Using type(uint256).max instead of type(uint64).max.

Solution:


2. Address Cannot Be Empty

Error:

Cause: Wrong field name in JSON, or empty address.

Solution:


3. Failed to Unmarshal JSON

Error:

Causes:

  • Invalid JSON syntax (missing quotes, commas, brackets)

  • Wrong field types (numbers as strings vs raw, booleans as strings)

  • Missing required fields

Solution - Check JSON Format:

Type
Correct
Wrong

Numbers

"123"

123

Booleans

true / false

"true" / "false"

Addresses

"0x742d..."

0x742d...

Ranges

[{"start":"1","end":"100"}]

[{start:1,end:100}]

Correct Example:


4. Collection Not Found

Error:

Cause: The collection ID doesn't exist.

Solution:


5. Insufficient Balance

Error:

Cause: Attempting to transfer more tokens than the user owns.

Solution:


6. Not Authorized / Permission Denied

Error:

Causes:

  • Caller is not the collection manager

  • Missing approval for transfer

  • Permission locked in collection permissions

  • Time window expired for operation

Debugging Steps:

  1. Check who the collection manager is

  2. Verify approvals are set correctly

  3. Check if permissions are locked (permanentlyForbiddenTimes)

  4. Verify current time is within allowed window

Solution:


7. Collection Archived

Error:

Cause: Attempting to modify an archived collection.

Solution:


8. Invalid Range (start > end)

Error:

Cause: Range has start value greater than end value.

Solution:


9. EVM Query Challenge Failed

Error:

Cause: An EVM query challenge in the collection invariants failed.

Debugging:

  1. Check what contract is being called

  2. Verify the calldata is correct

  3. Check the expected result and comparison operator

  4. Ensure the target contract is deployed and working

Solution:


10. Dynamic Store Not Found

Error:

Cause: The dynamic store ID doesn't exist.

Solution:


11. Approval Not Found

Error:

Cause: Trying to delete or reference a non-existent approval.

Solution:


12. Invalid Approval Criteria

Error:

Cause: Approval criteria configuration is incomplete or invalid.

Common Issues:

  • Merkle challenge without merkle root

  • Vote criteria without proposal ID

  • Amount tracker without proper limits


Error Codes Reference

Code
Name
Description

1

InvalidInput

Invalid input parameters

2

JSONUnmarshal

Failed to parse JSON

3

InternalError

Internal precompile error

4

InvalidRange

Range validation failed

5

NotFound

Resource not found (collection, store, etc.)

6

InsufficientBalance

Not enough tokens

7

NotAuthorized

Permission denied

8

Archived

Collection is archived

9

EVMQueryFailed

EVM query challenge failed

10

StoreNotFound

Dynamic store not found

11

ApprovalNotFound

Approval not found

12

InvalidCriteria

Invalid approval criteria


Debugging Tips

1. Log JSON Before Sending

2. Validate JSON Externally

Copy the JSON from logs and validate it:

  • Use online JSON validators

  • Check against proto message definition

  • Ensure field names match exactly

3. Test Individual Components

4. Check Precompile is Responding

5. Use Address Conversion for Debugging


JSON Format Quick Reference

Field Type
JSON Format
Example

uint256

String

"123456789"

uint64

String

"18446744073709551615"

bool

Raw boolean

true or false

address

Hex string

"0x742d35Cc..."

string

Quoted string

"hello world"

UintRange[]

Object array

[{"start":"1","end":"100"}]

string[]

String array

["a","b","c"]

Empty object

{}

{}

Empty array

[]

[]


Getting Help

If you encounter an error not covered here:

  1. Check the API Reference for correct method signatures

  2. Check the precompile implementationarrow-up-right for error definitions

Last updated