Namespace: stark
Functions
compressProgram
▸ compressProgram(jsonProgram
): CompressedProgram
Compress compiled Cairo 0 program
Parameters
Name | Type | Description |
---|---|---|
jsonProgram | string | Program | Representing the compiled Cairo 0 program |
Returns
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
decompressProgram
▸ decompressProgram(base64
): any
Decompress compressed compiled Cairo 0 program
Parameters
Name | Type | Description |
---|---|---|
base64 | string | string [] | Compressed 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
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
formatSignature
▸ formatSignature(sig?
): ArraySignatureType
Format Signature to standard type (hex array)
Parameters
Name | Type |
---|---|
sig? | Signature |
Returns
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
signatureToDecimalArray
▸ signatureToDecimalArray(sig?
): ArraySignatureType
Format Signature to decimal string array
Parameters
Name | Type |
---|---|
sig? | Signature |
Returns
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
signatureToHexArray
▸ signatureToHexArray(sig?
): ArraySignatureType
Format Signature to hex string array
Parameters
Name | Type |
---|---|
sig? | Signature |
Returns
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
toOverheadResourceBounds
▸ toOverheadResourceBounds(estimate
, overhead?
): ResourceBoundsBN
Calculates the maximum resource bounds for fee estimation.
Parameters
Name | Type | Description |
---|---|---|
estimate | Object | The estimate for the fee. If a BigInt is provided, the returned bounds will be set to 0n. |
estimate.unit | "WEI" | "FRI" | - |
estimate.l1_gas_price | string | number | - |
estimate.l2_gas_price | string | number | - |
estimate.l1_data_gas_price | string | number | - |
estimate.l1_gas_consumed | string | number | - |
estimate.l2_gas_consumed | string | number | - |
estimate.l1_data_gas_consumed | string | number | - |
estimate.overall_fee | string | number | - |
overhead? | ResourceBoundsOverhead | The percentage overhead added to the max units and max price per unit. |
Returns
The resource bounds with overhead represented as BigInt.
Throws
If the estimate object is undefined or does not have the required properties.
Defined in
resourceBoundsToEstimateFee
▸ resourceBoundsToEstimateFee(resourceBounds
): EstimateFeeResponse
Parameters
Name | Type |
---|---|
resourceBounds | ResourceBoundsBN |
Returns
Defined in
toOverheadOverallFee
▸ toOverheadOverallFee(estimate
, overhead?
): bigint
Calculates the overall fee for a transaction based on resource consumption and prices.
The estimated fee for the transaction (in wei or fri, depending on the tx version), equals to: l1_gas_consumedl1_gas_price + l1_data_gas_consumedl1_data_gas_price + l2_gas_consumed*l2_gas_price
Parameters
Name | Type | Description |
---|---|---|
estimate | Object | The fee estimate containing gas consumption and price data |
estimate.unit | "WEI" | "FRI" | - |
estimate.l1_gas_price | string | number | - |
estimate.l2_gas_price | string | number | - |
estimate.l1_data_gas_price | string | number | - |
estimate.l1_gas_consumed | string | number | - |
estimate.l2_gas_consumed | string | number | - |
estimate.l1_data_gas_consumed | string | number | - |
estimate.overall_fee | string | number | - |
overhead | ResourceBoundsOverhead | The overhead percentage (currently unused in calculation) |
Returns
bigint
The calculated overall fee in wei or fri
Example
const estimate = {
l1_gas_consumed: 1000n,
l1_gas_price: 100n,
l1_data_gas_consumed: 500n,
l1_data_gas_price: 50n,
l2_gas_consumed: 200n,
l2_gas_price: 20n
};
const result = stark.toOverheadOverallFee(estimate, overhead);
// result = 1000n * 100n + 500n * 50n + 200n * 20n = 129000n
Defined in
ZeroFeeEstimate
▸ ZeroFeeEstimate(): FeeEstimate
Mock zero fee response
Returns
Defined in
intDAM
▸ intDAM(dam
): EDAMode
Converts the data availability mode from EDataAvailabilityMode to EDAMode.
Parameters
Name | Type | Description |
---|---|---|
dam | EDataAvailabilityMode | The data availability mode to be converted. |
Returns
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
toTransactionVersion
▸ toTransactionVersion(defaultVersion
, providedVersion?
): ETransactionVersion3
Convert input versions to ETransactionVersion or throw an error. Returns providedVersion if specified, otherwise returns defaultVersion.
Parameters
Name | Type | Description |
---|---|---|
defaultVersion | BigNumberish | The default transaction version to use if providedVersion is not specified |
providedVersion? | BigNumberish | Optional transaction version that takes precedence if provided |
Returns
The transaction version - either providedVersion if specified or defaultVersion
Throws
If either version is not a valid ETransactionVersion
Example
const result = stark.toTransactionVersion("0x100000000000000000000000000000003", stark.toFeeVersion(2));
// result = "0x100000000000000000000000000000002"
Defined in
toFeeVersion
▸ toFeeVersion(providedVersion?
): ETransactionVersion
| undefined
Convert Transaction version to Fee version or throw an error
Parameters
Name | Type | Description |
---|---|---|
providedVersion? | BigNumberish | 0..3 number representing the transaction version |
Returns
ETransactionVersion
| undefined
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
v3Details
▸ v3Details(details
): V3Details
Return provided or default v3 tx details
Parameters
Name | Type | Description |
---|---|---|
details | UniversalDetails | details of the transaction |
Returns
V3Details
an object including the V3 transaction details.
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
getFullPublicKey
▸ getFullPublicKey(privateKey
): string
get the hex string of the full public key related to a Starknet private key.
Parameters
Name | Type | Description |
---|---|---|
privateKey | BigNumberish | a 252 bits private key. |
Returns
string
an hex string of a 520 bit number, representing the full public key related to privateKey
.
Example
const result = ec.getFullPublicKey("0x43b7240d227aa2fb8434350b3321c40ac1b88c7067982549e7609870621b535");
// result = "0x0400b730bd22358612b5a67f8ad52ce80f9e8e893639ade263537e6ef35852e5d3057795f6b090f7c6985ee143f798608a53b3659222c06693c630857a10a92acf"
Defined in
resourceBoundsToHexString
▸ resourceBoundsToHexString(resourceBoundsBN
): ResourceBounds
Converts ResourceBoundsBN (with bigint values) to ResourceBounds (with string values)
Parameters
Name | Type | Description |
---|---|---|
resourceBoundsBN | ResourceBoundsBN | The resource bounds with bigint values |
Returns
The resource bounds with hex string values
Example
const resourceBoundsBN = {
l1_gas: { max_amount: 1000n, max_price_per_unit: 100n },
l2_gas: { max_amount: 2000n, max_price_per_unit: 200n },
l1_data_gas: { max_amount: 500n, max_price_per_unit: 50n }
};
const result = stark.resourceBoundsToHexString(resourceBoundsBN);
// result = {
// l1_gas: { max_amount: '0x3e8', max_price_per_unit: '0x64' },
// l2_gas: { max_amount: '0x7d0', max_price_per_unit: '0xc8' },
// l1_data_gas: { max_amount: '0x1f4', max_price_per_unit: '0x32' }
// }
Defined in
resourceBoundsToBigInt
▸ resourceBoundsToBigInt(resourceBounds
): ResourceBoundsBN
Converts ResourceBounds (with string values) to ResourceBoundsBN (with BigInt values)
Parameters
Name | Type | Description |
---|---|---|
resourceBounds | Object | The resource bounds with string values |
resourceBounds.l1_gas | { max_amount: string; max_price_per_unit: string; } | - |
resourceBounds.l1_data_gas | { max_amount: string; max_price_per_unit: string; } | - |
resourceBounds.l2_gas | { max_amount: string; max_price_per_unit: string; } | - |
Returns
The resource bounds with BigInt values
Example
const resourceBounds = {
l1_gas: { max_amount: '0x3e8', max_price_per_unit: '0x64' },
l2_gas: { max_amount: '0x7d0', max_price_per_unit: '0xc8' },
l1_data_gas: { max_amount: '0x1f4', max_price_per_unit: '0x32' }
};
const result = stark.resourceBoundsToBigInt(resourceBounds);
// result = {
// l1_gas: { max_amount: 1000n, max_price_per_unit: 100n },
// l2_gas: { max_amount: 2000n, max_price_per_unit: 200n },
// l1_data_gas: { max_amount: 500n, max_price_per_unit: 50n }
// }