Skip to main content
Version: Next

Function: encodeValue()

encodeValue(types, type, data, ctx?, revision?): [string, string]

Defined in: src/utils/typedData.ts:335

Encodes a single value to an ABI serialisable string, number or Buffer. Returns the data as a tuple, which consists of an array of ABI compatible types, and an array of corresponding values.

Parameters

types

Record<string, StarknetType[]>

The types object containing all defined types.

type

string

The name of the type to encode.

data

unknown

The data to encode.

ctx?

Context = {}

The context of the encoding process.

revision?

TypedDataRevision = Revision.LEGACY

The revision of the TypedData.

Returns

[string, string]

The ABI compatible type and corresponding value.

Example

import { getSelectorFromName } from '../../src/utils/hash';

const selector = 'transfer';
const selectorHash = getSelectorFromName(selector);
const result1 = encodeValue({}, 'felt', selectorHash);

// result1 = ['felt', '0x83afd3f4caedc6eebf44246fe54e38c95e3179a5ec9ea81740eca5b482d12e']