Nishu Sank
Nishu Sank

Reputation: 1

How this uint accept Address value in this smart contract?

Can anyone Explain me how uint variable accept address in this smart contract

// SPDX-License-Identifier: Apache-2.0. pragma solidity ^0.6.12;

library CairoConstants { uint256 public constant FIELD_PRIME = 0x800000000000011000000000000000000000000000000000000000000000001; }

As per my Knowledge Uint Only accept unsigned integer values so why on Compilation it not throws an Error Message

Please Clear my Doubt

Thank You

Hello Everyone,

Can anyone Explain me how uint variable accept address in this smart contract

// SPDX-License-Identifier: Apache-2.0. pragma solidity ^0.6.12;

library CairoConstants { uint256 public constant FIELD_PRIME = 0x800000000000011000000000000000000000000000000000000000000000001; }

As per my Knowledge Uint Only accept unsigned integer values so why on Compilation it not throws an Error Message

Please Clear my Doubt

Thank You

Upvotes: 0

Views: 113

Answers (2)

Steven
Steven

Reputation: 141

In solidity, there are 2 ways to represent uint values.

  • Decimal, 123
  • Hexadecimal, 0x006B

And the number FIELD_PRIME = 0x800000000000011000000000000000000000000000000000000000000000001 is a valid uint256 value in hexadecimal format. Its not an address as @Satoshi mentioned. Its a positive integer value, which is what uint256 requires.

Thx

Upvotes: 0

Satoshi Naoki
Satoshi Naoki

Reputation: 393

If the size of a given hex value is 20bytes, the compiler thinks it's an address, otherwise, it thinks it's a number. So if you use 0x8000000000000110000000000000000000000000, it might throw an error since it's an address, but in your code, the given value is not an address. In addition, if the length of the value is 39 or 41 hex digits, it also throws an error since the compiler thinks it looks like an address but there's a typo.

Upvotes: 0

Related Questions