Skip to main content
Version: Next

Namespace: stark

Functions​

compressProgram​

â–¸ compressProgram(jsonProgram): CompressedProgram

Compress compiled Cairo 0 program

Reference

Parameters​

NameTypeDescription
jsonProgramstring | ProgramRepresenting the compiled Cairo 0 program

Returns​

CompressedProgram

Compressed Cairo 0 program

Example

const contractCairo0 = json.parse(fs.readFileSync("./cairo0contract.json").toString("ascii"));
const result = stark.compressProgram(contractCairo0);
// result = "H4sIAAAAAAAAA+1dC4/bOJL+K4aBu01me7r5EEUyixzQk/TuB..."

Defined in​

src/utils/stark.ts:41


decompressProgram​

â–¸ decompressProgram(base64): any

Decompress compressed compiled Cairo 0 program

Parameters​

NameTypeDescription
base64stringCompressed Cairo 0 program

Returns​

any

Parsed decompressed compiled Cairo 0 program

Example

const contractCairo0 = json.parse(fs.readFileSync("./cairo0contract.json").toString("ascii"));
const compressedCairo0 = stark.compressProgram(contractCairo0);
const result = stark.decompressProgram(compressedCairo0);
// result = {
// abi: [
// {
// inputs: [Array],
// name: 'increase_balance',
// outputs: [],
// type: 'function'
// }
// ],
// entry_points_by_type: { CONSTRUCTOR: [], EXTERNAL: [ [Object], [Object] ], L1_HANDLER: [] },
// program: {
// attributes: [],
// builtins: [ 'pedersen', 'range_check' ],
// compiler_version: '0.10.2',
// data: [
// '0x480680017fff8000',
// ...

Defined in​

src/utils/stark.ts:75


randomAddress​

â–¸ randomAddress(): string

Random Address based on random keyPair

Returns​

string

an hex string of a random Starknet address

Example

const result = stark.randomAddress();
// result = "0x51fc8126a13cd5ddb29a71ca399cb1e814f086f5af1b502d7151c14929554f"

Defined in​

src/utils/stark.ts:90


makeAddress​

â–¸ makeAddress(input): string

Lowercase and hex prefix string

Parameters​

NameType
inputstring

Returns​

string

Deprecated

Not used internally, naming is confusing based on functionality

Defined in​

src/utils/stark.ts:100


formatSignature​

â–¸ formatSignature(sig?): ArraySignatureType

Format Signature to standard type (hex array)

Parameters​

NameType
sig?Signature

Returns​

ArraySignatureType

Custom hex string array

Throws

if sig not defined, or wrong format

Example

const signature = ec.starkCurve.sign("0x12de34", "0x3487123eac");
const result = stark.formatSignature(signature);
// result = ['0xba8eecee2d69c417e8c6a20cf331c821f716b58ba9e47166c7476afdb38997',
// '0x69ef7438c94104839a6e2aa2385482a77399d2f46e894ae4f50ab6d69239d1c']

Defined in​

src/utils/stark.ts:117


signatureToDecimalArray​

â–¸ signatureToDecimalArray(sig?): ArraySignatureType

Format Signature to decimal string array

Parameters​

NameType
sig?Signature

Returns​

ArraySignatureType

Custom hex string array

Throws

if sig not defined, or wrong format

Example

const signature = ec.starkCurve.sign("0x12de34", "0x3487123eac");
const result = stark.signatureToDecimalArray(signature);
// result = ['329619989660444495690615805546674399714973829707166906185976654753023887767',
// '2994745480203297689255012826403147585778741462125743754529207781488706428188']

Defined in​

src/utils/stark.ts:143


signatureToHexArray​

â–¸ signatureToHexArray(sig?): ArraySignatureType

Format Signature to hex string array

Parameters​

NameType
sig?Signature

Returns​

ArraySignatureType

Custom hex string array

Throws

if sig not defined, or wrong format

Example

const signature = ec.starkCurve.sign("0x12de34", "0x3487123eac");
const result = stark.signatureToHexArray(signature);
// result = ['0xba8eecee2d69c417e8c6a20cf331c821f716b58ba9e47166c7476afdb38997',
// '0x69ef7438c94104839a6e2aa2385482a77399d2f46e894ae4f50ab6d69239d1c']

Defined in​

src/utils/stark.ts:160


estimatedFeeToMaxFee​

â–¸ estimatedFeeToMaxFee(estimatedFee, overhead?): bigint

Convert estimated fee to max fee including a margin

Parameters​

NameTypeDefault valueDescription
estimatedFeeBigNumberishundefinedThe estimated fee
overhead?numberFeeMarginPercentage.MAX_FEEThe overhead added to the gas

Returns​

bigint

The maximum fee with the margin

Example

const result = stark.estimatedFeeToMaxFee("8982300000000", 50);
// result = "13473450000000n"

Defined in​

src/utils/stark.ts:175


estimateFeeToBounds​

â–¸ estimateFeeToBounds(estimate, amountOverhead?, priceOverhead?): ResourceBounds

Calculates the maximum resource bounds for fee estimation.

Parameters​

NameTypeDefault valueDescription
estimate0n | { unit: "WEI" | "FRI" ; gas_consumed: string ; gas_price: string ; overall_fee: string ; data_gas_consumed: undefined | string ; data_gas_price: undefined | string }undefinedThe estimate for the fee. If a BigInt is provided, the returned bounds will be set to '0x0'.
amountOverhead?numberFeeMarginPercentage.L1_BOUND_MAX_AMOUNTThe percentage overhead added to the gas consumed or overall fee amount.
priceOverhead?numberFeeMarginPercentage.L1_BOUND_MAX_PRICE_PER_UNITThe percentage overhead added to the gas price per unit.

Returns​

ResourceBounds

The maximum resource bounds for fee estimation.

Throws

If the estimate object is undefined or does not have the required properties.

Example

const feeEstimated: FeeEstimate = {
gas_consumed: "0x3456a",
gas_price: "0xa45567567567ae4",
overall_fee: "0x2198F463A77A899A5668",
unit: "WEI"
};
const result = stark.estimateFeeToBounds(feeEstimated, 70, 50);
// result = {
// l2_gas: { max_amount: '0x0', max_price_per_unit: '0x0' },
// l1_gas: { max_amount: '0x58f9a', max_price_per_unit: '0xf6801b01b01b856' }
// }

Defined in​

src/utils/stark.ts:205


intDAM​

â–¸ intDAM(dam): EDAMode

Converts the data availability mode from EDataAvailabilityMode to EDAMode.

Parameters​

NameTypeDescription
damEDataAvailabilityModeThe data availability mode to be converted.

Returns​

EDAMode

The converted data availability mode.

Throws

If the data availability mode is not a valid value.

Example

const result = stark.intDAM(RPC.EDataAvailabilityMode.L1);
// result = 0

Defined in​

src/utils/stark.ts:244


toTransactionVersion​

â–¸ toTransactionVersion(defaultVersion, providedVersion?): ETransactionVersion

Convert to ETransactionVersion or throw an error. Return providedVersion is specified else return defaultVersion

Parameters​

NameTypeDescription
defaultVersionBigNumberishdefault estimate transaction version
providedVersion?BigNumberishestimate transaction version

Returns​

ETransactionVersion

if providedVersion is not provided, returns the default estimate version, else return the provided version

Throws

if estimate transaction version or default estimate transaction version is unknown

Example

const result = stark.toTransactionVersion("0x100000000000000000000000000000003", stark.toFeeVersion(2));
// result = "0x100000000000000000000000000000002"

Defined in​

src/utils/stark.ts:263


toFeeVersion​

â–¸ toFeeVersion(providedVersion?): undefined | "0x100000000000000000000000000000000" | "0x100000000000000000000000000000001" | "0x100000000000000000000000000000002" | "0x100000000000000000000000000000003"

Convert Transaction version to Fee version or throw an error

Parameters​

NameTypeDescription
providedVersion?BigNumberish0..3 number representing the transaction version

Returns​

undefined | "0x100000000000000000000000000000000" | "0x100000000000000000000000000000001" | "0x100000000000000000000000000000002" | "0x100000000000000000000000000000003"

the fee estimation version corresponding to the transaction version provided

Throws

if the transaction version is unknown

Example

const result = stark.toFeeVersion(2);
// result = "0x100000000000000000000000000000002"

Defined in​

src/utils/stark.ts:291


v3Details​

â–¸ v3Details(details): Object

Return provided or default v3 tx details

Parameters​

NameTypeDescription
detailsUniversalDetailsdetails of the transaction

Returns​

Object

an object including the V3 transaction details.

NameType
tipBigNumberish
paymasterDataBigNumberish[]
accountDeploymentDataBigNumberish[]
nonceDataAvailabilityModeEDataAvailabilityMode
feeDataAvailabilityModeEDataAvailabilityMode
resourceBoundsRESOURCE_BOUNDS_MAPPING

Example

const detail: UniversalDetails = { tip: 3456n };
const result = stark.v3Details(detail);
// result = {
// tip: 3456n,
// paymasterData: [],
// accountDeploymentData: [],
// nonceDataAvailabilityMode: 'L1',
// feeDataAvailabilityMode: 'L1',
// resourceBounds: {
// l2_gas: { max_amount: '0x0', max_price_per_unit: '0x0' },
// l1_gas: { max_amount: '0x0', max_price_per_unit: '0x0' }
// }
// }

Defined in​

src/utils/stark.ts:324


reduceV2​

â–¸ reduceV2(providedVersion): ETransactionVersion

It will reduce V2 to V1, else (V3) stay the same F2 -> F1 V2 -> V1 F3 -> F3 V3 -> V3

Parameters​

NameType
providedVersionETransactionVersion

Returns​

ETransactionVersion

if v2 then returns v1. if v3 then return v3

Example

const result = stark.reduceV2(constants.TRANSACTION_VERSION.V2);
// result = "0x1"

Defined in​

src/utils/stark.ts:349