Skip to main content
@tevm/voltaire
@tevm/voltaire / primitives/ContractCode

primitives/ContractCode

Type Aliases

ContractCodeType

ContractCodeType = Uint8Array & object
Defined in: src/primitives/ContractCode/ContractCodeType.ts:7 Branded ContractCode type Full deployed contract bytecode including metadata

Type Declaration

[brand]
readonly [brand]: "ContractCode"

Functions

_equals()

_equals(a, b): boolean
Defined in: src/primitives/ContractCode/equals.js:15 Check if two ContractCode instances are equal

Parameters

a
ContractCodeType First ContractCode
b
ContractCodeType Second ContractCode

Returns

boolean true if equal

Example

import * as ContractCode from './primitives/ContractCode/index.js';
const code1 = ContractCode.from("0x6001");
const code2 = ContractCode.from("0x6001");
ContractCode._equals(code1, code2); // true

_extractRuntime()

_extractRuntime(code): RuntimeCodeType
Defined in: src/primitives/ContractCode/extractRuntime.js:18 Extract runtime code from contract code Strips metadata to return pure runtime bytecode. Alias for stripMetadata for semantic clarity.

Parameters

code
ContractCodeType ContractCode

Returns

RuntimeCodeType RuntimeCode

Example

import * as ContractCode from './primitives/ContractCode/index.js';
const contract = ContractCode.from("0x6001600155a264...0033");
const runtime = ContractCode._extractRuntime(contract);

_hasMetadata()

_hasMetadata(code): boolean
Defined in: src/primitives/ContractCode/hasMetadata.js:16 Check if contract code contains CBOR metadata Solidity compiler includes CBOR-encoded metadata at the end of deployed bytecode. The metadata section starts with 0xa2 (CBOR map) and ends with 0x00 0x33 (length).

Parameters

code
ContractCodeType ContractCode to check

Returns

boolean true if metadata is present

Example

import * as ContractCode from './primitives/ContractCode/index.js';
const code = ContractCode.from("0x6001600155a264...0033");
ContractCode._hasMetadata(code); // true

_stripMetadata()

_stripMetadata(code): RuntimeCodeType
Defined in: src/primitives/ContractCode/stripMetadata.js:17 Strip CBOR metadata from contract code Returns runtime code without the Solidity compiler metadata.

Parameters

code
ContractCodeType ContractCode with metadata

Returns

RuntimeCodeType RuntimeCode without metadata

Example

import * as ContractCode from './primitives/ContractCode/index.js';
const withMeta = ContractCode.from("0x6001600155a264...0033");
const runtime = ContractCode._stripMetadata(withMeta);

_toHex()

_toHex(data): HexType
Defined in: src/primitives/ContractCode/toHex.js:15 Convert ContractCode to hex string

Parameters

data
ContractCodeType ContractCode

Returns

HexType Hex string

Example

import * as ContractCode from './primitives/ContractCode/index.js';
const code = ContractCode.from("0x6001600155");
const hex = ContractCode._toHex(code); // "0x6001600155"

equals()

equals(a, b): boolean
Defined in: src/primitives/ContractCode/index.ts:19

Parameters

a
string | Uint8Array<ArrayBufferLike> | ContractCodeType
b
string | Uint8Array<ArrayBufferLike> | ContractCodeType

Returns

boolean

extractRuntime()

extractRuntime(value): RuntimeCodeType
Defined in: src/primitives/ContractCode/index.ts:44

Parameters

value
string | Uint8Array<ArrayBufferLike> | ContractCodeType

Returns

RuntimeCodeType

from()

from(value): ContractCodeType
Defined in: src/primitives/ContractCode/from.js:18 Create ContractCode from various input types

Parameters

value
Hex string or Uint8Array string | Uint8Array<ArrayBufferLike>

Returns

ContractCodeType ContractCode

See

https://voltaire.tevm.sh/primitives/contract-code for ContractCode documentation

Since

0.0.0

Throws

Example

import * as ContractCode from './primitives/ContractCode/index.js';
const code1 = ContractCode.from("0x6001600155");
const code2 = ContractCode.from(new Uint8Array([0x60, 0x01, 0x60, 0x01, 0x55]));

fromHex()

fromHex(hex): ContractCodeType
Defined in: src/primitives/ContractCode/fromHex.js:15 Create ContractCode from hex string

Parameters

hex
string Hex string

Returns

ContractCodeType ContractCode

Throws

If hex string is invalid

Example

import * as ContractCode from './primitives/ContractCode/index.js';
const code = ContractCode.fromHex("0x6001600155");

hasMetadata()

hasMetadata(value): boolean
Defined in: src/primitives/ContractCode/index.ts:32

Parameters

value
string | Uint8Array<ArrayBufferLike> | ContractCodeType

Returns

boolean

stripMetadata()

stripMetadata(value): RuntimeCodeType
Defined in: src/primitives/ContractCode/index.ts:38

Parameters

value
string | Uint8Array<ArrayBufferLike> | ContractCodeType

Returns

RuntimeCodeType

toHex()

toHex(value): HexType
Defined in: src/primitives/ContractCode/index.ts:26

Parameters

value
string | Uint8Array<ArrayBufferLike> | ContractCodeType

Returns

HexType