Skip to main content
Version: 11.x

Function: felt()

felt(it): string

Defined in: src/utils/calldata/cairo.ts:303

Create felt Cairo type (cairo type helper)

Accepted: a whole number, in any of the forms the BigNumberish type covers — a number, a bigint, a hexadecimal string ('0x101') or a decimal string ('257').

Refused: everything else, and text in particular. A felt252 is a field element, not a string type, so a text argument is an error rather than something to encode silently — which also removes a trap: '-123' used to come back as 758198835, the text -123. To carry text in a felt252, encode it explicitly with CairoBytes31.fromText(). Booleans are refused for the same reason, and so are non-integer numbers.

Parameters​

it​

BigNumberish

a whole number, as a number, a bigint, a hex string or a decimal string

Returns​

string

the felt as a decimal string

Example​

const result = felt('0x101');
// result = "257"