Skip to main content

Try it Live

Run Uint examples in the interactive playground

    Usage Patterns

    Arithmetic Operations

    const a = Uint(100n)
    const b = Uint(50n)
    
    // Use BigInt for operations not supported by Uint
    const bigIntA = Uint.toBigInt(a)
    const bigIntB = Uint.toBigInt(b)
    
    // Custom operation
    const result = bigIntA ** 2n + bigIntB
    const resultUint = Uint(result)
    

    Comparison with BigInt

    const value = Uint(1000n)
    const bigint = Uint.toBigInt(value)
    
    if (bigint > 500n) {
      console.log("Greater than 500")
    }
    

    JSON Serialization

    const value = Uint(12345n)
    
    // BigInt not supported in JSON.stringify
    const json = JSON.stringify({
      balance: Uint.toBigInt(value).toString()  // Convert to string
    })
    

    See Also