contracts

package
v0.13.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 27, 2025 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var PREFIX_CONTRACT_ADDRESS = new(felt.Felt).SetBytes([]byte("STARKNET_CONTRACT_ADDRESS"))

Functions

func PrecomputeAddress added in v0.7.1

func PrecomputeAddress(deployerAddress, salt, classHash *felt.Felt, constructorCalldata []*felt.Felt) *felt.Felt

PrecomputeAddress calculates the precomputed address for a contract instance. ref: https://github.com/starkware-libs/cairo-lang/blob/master/src/starkware/starknet/core/os/contract_address/contract_address.py

Parameters:

  • deployerAddress: the deployer address
  • salt: the salt
  • classHash: the class hash
  • constructorCalldata: the constructor calldata

Returns:

  • *felt.Felt: the precomputed address as a *felt.Felt

Types

type ABI added in v0.8.0

type ABI []ABIEntry

type ABIEntry added in v0.8.0

type ABIEntry interface {
	IsType() ABIType
}

type ABIType added in v0.8.0

type ABIType string
const (
	ABITypeConstructor ABIType = "constructor"
	ABITypeFunction    ABIType = "function"
	ABITypeL1Handler   ABIType = "l1_handler"
	ABITypeEvent       ABIType = "event"
	ABITypeStruct      ABIType = "struct"
)

type AllocConstantSize added in v0.8.0

type AllocConstantSize struct {
	Size ResOperand `json:"size"`
	Dst  CellRef    `json:"dst"`
}

type AllocFelt252Dict added in v0.8.0

type AllocFelt252Dict struct {
	SegmentArenaPtr ResOperand `json:"segment_arena_ptr"`
}

type AllocSegment added in v0.8.0

type AllocSegment struct {
	Dst CellRef `json:"dst"`
}

type AssertAllAccessesUsed added in v0.8.0

type AssertAllAccessesUsed struct {
	NotUsedAccesses CellRef `json:"n_used_accesses"`
}

type AssertLeFindSmallArcs added in v0.8.0

type AssertLeFindSmallArcs struct {
	RangeCheckPtr ResOperand `json:"range_check_ptr"`
	A             ResOperand `json:"a"`
	B             ResOperand `json:"b"`
}

type AssertLeIsFirstArcExcluded added in v0.8.0

type AssertLeIsFirstArcExcluded struct {
	SkipExcludeAFlag CellRef `json:"skip_exclude_a_flag"`
}

type AssertLeIsSecondArcExcluded added in v0.8.0

type AssertLeIsSecondArcExcluded struct {
	SkipExcludeBMinusA CellRef `json:"skip_exclude_b_minus_a"`
}

type AssertLtAssertValidInput added in v0.8.0

type AssertLtAssertValidInput struct {
	A ResOperand `json:"a"`
	B ResOperand `json:"b"`
}

type B added in v0.8.0

type B struct {
	Type string
	Data interface{}
}

Can be one of the following values:

  • Deref
  • Immediate

func (B) MarshalJSON added in v0.8.0

func (b B) MarshalJSON() ([]byte, error)

MarshalJSON implements json.Marshaler

func (*B) UnmarshalJSON added in v0.8.0

func (b *B) UnmarshalJSON(data []byte) error

UnmarshalJSON implements json.Unmarshaler

type BinOp added in v0.8.0

type BinOp struct {
	Operation Operation `json:"op"`
	A         CellRef   `json:"a"`
	B         B         `json:"b"`
}

type CasmClass added in v0.4.6

type CasmClass struct {
	EntryPointsByType CasmEntryPointsByType `json:"entry_points_by_type"`
	ByteCode          []*felt.Felt          `json:"bytecode"`
	Prime             NumAsHex              `json:"prime"`
	CompilerVersion   string                `json:"compiler_version"`
	Hints             []Hints               `json:"hints"`
	// a list of sizes of segments in the bytecode, each segment is hashed individually when computing the bytecode hash
	BytecodeSegmentLengths *NestedUints `json:"bytecode_segment_lengths,omitempty"`
}

CasmClass (AKA CASM_COMPILED_CONTRACT_CLASS) is the struct that represents the compiled Cairo contract class.

func UnmarshalCasmClass added in v0.4.6

func UnmarshalCasmClass(filePath string) (*CasmClass, error)

UnmarshalCasmClass is a function that unmarshals a CasmClass object from a file. CASM = Cairo instructions

It takes a file path as a parameter and returns a pointer to the unmarshaled CasmClass object and an error.

func (*CasmClass) UnmarshalJSON added in v0.8.0

func (c *CasmClass) UnmarshalJSON(data []byte) error

UnmarshalJSON implements json.Unmarshaler

func (*CasmClass) Validate added in v0.8.0

func (c *CasmClass) Validate() error

Validate ensures all required fields are present and valid

type CasmEntryPoint added in v0.8.0

type CasmEntryPoint struct {
	Selector *felt.Felt `json:"selector"`
	Offset   int        `json:"offset"`
	Builtins []string   `json:"builtins"`
}

type CasmEntryPointsByType added in v0.8.0

type CasmEntryPointsByType struct {
	Constructor []CasmEntryPoint `json:"CONSTRUCTOR"`
	External    []CasmEntryPoint `json:"EXTERNAL"`
	L1Handler   []CasmEntryPoint `json:"L1_HANDLER"`
}

func (*CasmEntryPointsByType) Validate added in v0.8.0

func (e *CasmEntryPointsByType) Validate() error

Validate ensures all required fields are present and valid

type CellRef added in v0.8.0

type CellRef struct {
	Register Register `json:"register"`
	Offset   int      `json:"offset"`
}

type Cheatcode added in v0.8.0

type Cheatcode struct {
	Selector    NumAsHex   `json:"selector"`
	InputStart  ResOperand `json:"input_start"`
	InputEnd    ResOperand `json:"input_end"`
	OutputStart CellRef    `json:"output_start"`
	OutputEnd   CellRef    `json:"output_end"`
}

type ContractClass added in v0.8.0

type ContractClass struct {
	// The list of Sierra instructions of which the program consists
	SierraProgram []*felt.Felt `json:"sierra_program"`

	// The version of the contract class object. Currently, the Starknet OS supports version 0.1.0
	ContractClassVersion string `json:"contract_class_version"`

	EntryPointsByType SierraEntryPointsByType `json:"entry_points_by_type"`

	ABI NestedString `json:"abi,omitempty"`
}

type DebugPrint added in v0.8.0

type DebugPrint struct {
	Start ResOperand `json:"start"`
	End   ResOperand `json:"end"`
}

type DeprecatedCairoEntryPoint added in v0.8.0

type DeprecatedCairoEntryPoint struct {
	// The offset of the entry point in the program
	Offset NumAsHex `json:"offset"`
	// A unique  identifier of the entry point (function) in the program
	Selector *felt.Felt `json:"selector"`
}

type DeprecatedContractClass added in v0.8.0

type DeprecatedContractClass struct {
	// Program A base64 representation of the compressed program code
	Program string `json:"program"`

	DeprecatedEntryPointsByType DeprecatedEntryPointsByType `json:"entry_points_by_type"`

	ABI *ABI `json:"abi,omitempty"`
}

func (*DeprecatedContractClass) UnmarshalJSON added in v0.8.0

func (c *DeprecatedContractClass) UnmarshalJSON(content []byte) error

UnmarshalJSON unmarshals JSON content into the DeprecatedContractClass struct.

type DeprecatedEntryPointsByType added in v0.8.0

type DeprecatedEntryPointsByType struct {
	Constructor []DeprecatedCairoEntryPoint `json:"CONSTRUCTOR"`
	External    []DeprecatedCairoEntryPoint `json:"EXTERNAL"`
	L1Handler   []DeprecatedCairoEntryPoint `json:"L1_HANDLER"`
}

type DeprecatedHintEnum added in v0.8.0

type DeprecatedHintEnum string
const (
	AssertCurrentAccessIndicesIsEmpty DeprecatedHintEnum = "AssertCurrentAccessIndicesIsEmpty"
	AssertAllKeysUsed                 DeprecatedHintEnum = "AssertAllKeysUsed"
	AssertLeAssertThirdArcExcluded    DeprecatedHintEnum = "AssertLeAssertThirdArcExcluded"
)

type Deref added in v0.8.0

type Deref CellRef

type DivMod added in v0.8.0

type DivMod struct {
	Quotient  CellRef `json:"quotient"`
	Remainder CellRef `json:"remainder"`
	// contains filtered or unexported fields
}

type DoubleDeref added in v0.8.0

type DoubleDeref struct {
	CellRef CellRef
	Offset  int
}

A (CellRef, offset) tuple, but adapted to a golang struct

func (DoubleDeref) MarshalJSON added in v0.8.0

func (dd DoubleDeref) MarshalJSON() ([]byte, error)

MarshalJSON implements json.Marshaler

func (*DoubleDeref) Tuple added in v0.8.0

func (dd *DoubleDeref) Tuple() [2]any

func (*DoubleDeref) UnmarshalJSON added in v0.8.0

func (dd *DoubleDeref) UnmarshalJSON(data []byte) error

UnmarshalJSON implements json.Unmarshaler

func (*DoubleDeref) Values added in v0.8.0

func (dd *DoubleDeref) Values() (CellRef, int)

type EvalCircuit added in v0.8.0

type EvalCircuit struct {
	NAddMods      ResOperand `json:"n_add_mods"`
	AddModBuiltin ResOperand `json:"add_mod_builtin"`
	NMulMods      ResOperand `json:"n_mul_mods"`
	MulModBuiltin ResOperand `json:"mul_mod_builtin"`
}

type EventABIEntry added in v0.8.0

type EventABIEntry struct {
	// The event type
	Type ABIType `json:"type"`

	// The event name
	Name string `json:"name"`

	Keys []TypedParameter `json:"keys"`

	Data []TypedParameter `json:"data"`
}

func (*EventABIEntry) IsType added in v0.8.0

func (e *EventABIEntry) IsType() ABIType

IsType returns the ABIType of the EventABIEntry.

type Felt252DictEntryInit added in v0.8.0

type Felt252DictEntryInit felt252Dict

type Felt252DictEntryUpdate added in v0.8.0

type Felt252DictEntryUpdate struct {
	DictPtr ResOperand `json:"dict_ptr"`
	Value   ResOperand `json:"value"`
}

type Felt252DictRead added in v0.8.0

type Felt252DictRead struct {
	ValueDst CellRef `json:"value_dst"`
	// contains filtered or unexported fields
}

type Felt252DictWrite added in v0.8.0

type Felt252DictWrite struct {
	Value ResOperand `json:"value"`
	// contains filtered or unexported fields
}

type FieldSqrt added in v0.8.0

type FieldSqrt struct {
	Val  ResOperand `json:"val"`
	Sqrt CellRef    `json:"sqrt"`
}

type FunctionABIEntry added in v0.8.0

type FunctionABIEntry struct {
	// The function type
	Type ABIType `json:"type"`

	// The function name
	Name string `json:"name"`

	StateMutability FunctionStateMutability `json:"stateMutability,omitempty"`

	Inputs []TypedParameter `json:"inputs"`

	Outputs []TypedParameter `json:"outputs"`
}

func (*FunctionABIEntry) IsType added in v0.8.0

func (f *FunctionABIEntry) IsType() ABIType

IsType returns the ABIType of the FunctionABIEntry.

type FunctionStateMutability added in v0.8.0

type FunctionStateMutability string
const (
	FuncStateMutVIEW FunctionStateMutability = "view"
)

type GetCurrentAccessDelta added in v0.8.0

type GetCurrentAccessDelta struct {
	IndexDeltaMinus1 CellRef `json:"index_delta_minus1"`
}

type GetCurrentAccessIndex added in v0.8.0

type GetCurrentAccessIndex struct {
	RangeCheckPtr ResOperand `json:"range_check_ptr"`
}

type GetNextDictKey added in v0.8.0

type GetNextDictKey struct {
	NextKey CellRef `json:"next_key"`
}

type GetSegmentArenaIndex added in v0.8.0

type GetSegmentArenaIndex struct {
	DictEndPtr ResOperand `json:"dict_end_ptr"`
	DictIndex  CellRef    `json:"dict_index"`
}

type Hint added in v0.8.0

type Hint struct {
	Type string
	Data interface{}
}

Can be one of various hint types described in the spec and in the UnmarshalJSON method Ref: https://github.com/starkware-libs/starknet-specs/blob/d70a2e57c9a66db1bbf86c388f38d6295a6a2a75/api/starknet_executables.json#L276

func (Hint) MarshalJSON added in v0.8.0

func (h Hint) MarshalJSON() ([]byte, error)

MarshalJSON implements json.Marshaler

func (*Hint) UnmarshalJSON added in v0.8.0

func (h *Hint) UnmarshalJSON(data []byte) error

UnmarshalJSON implements json.Unmarshaler

type Hints added in v0.8.0

type Hints struct {
	Int     int
	HintArr []Hint
}

2-tuple of pc value and an array of hints to execute, but adapted to a golang struct

func (Hints) MarshalJSON added in v0.8.0

func (h Hints) MarshalJSON() ([]byte, error)

MarshalJSON implements json.Marshaler interface

func (*Hints) Tuple added in v0.8.0

func (hints *Hints) Tuple() [2]any

func (*Hints) UnmarshalJSON added in v0.8.0

func (h *Hints) UnmarshalJSON(data []byte) error

UnmarshalJSON implements json.Unmarshaler interface

func (*Hints) Values added in v0.8.0

func (hints *Hints) Values() (int, []Hint)

type Immediate added in v0.8.0

type Immediate NumAsHex

type InitSquashData added in v0.8.0

type InitSquashData struct {
	DictAccess ResOperand `json:"dict_accesses"`
	PtrDiff    ResOperand `json:"ptr_diff"`
	NAccesses  ResOperand `json:"n_accesses"`
	BigKeys    CellRef    `json:"big_keys"`
	FirstKey   CellRef    `json:"first_key"`
}

type LinearSplit added in v0.8.0

type LinearSplit struct {
	Value  ResOperand `json:"value"`
	Scalar ResOperand `json:"scalar"`
	MaxX   ResOperand `json:"max_x"`
	X      CellRef    `json:"x"`
	Y      CellRef    `json:"y"`
}

type Member added in v0.8.0

type Member struct {
	TypedParameter
	Offset int64 `json:"offset"`
}

type NestedString added in v0.8.0

type NestedString string

func (*NestedString) UnmarshalJSON added in v0.8.0

func (ns *NestedString) UnmarshalJSON(data []byte) error

type NestedUints added in v0.8.0

type NestedUints struct {
	IsArray bool
	Value   *uint64
	Values  []NestedUints
}

func (NestedUints) MarshalJSON added in v0.8.0

func (ns NestedUints) MarshalJSON() ([]byte, error)

MarshalJSON implements the json.Marshaler interface for NestedUints. It converts the NestedUints structure back into a JSON array format.

func (*NestedUints) UnmarshalJSON added in v0.8.0

func (ns *NestedUints) UnmarshalJSON(data []byte) error

type NumAsHex added in v0.8.0

type NumAsHex string

An integer number in hex format (0x...) TODO: duplicate of rpc.NumAsHex to avoid import cycle. Maybe move to a shared 'types' package?

type Operation added in v0.8.0

type Operation string
const (
	Add Operation = "Add"
	Mul Operation = "Mul"
)

type RandomEcPoint added in v0.8.0

type RandomEcPoint struct {
	X CellRef `json:"x"`
	Y CellRef `json:"y"`
}

type Register added in v0.8.0

type Register string
const (
	AP Register = "AP"
	FP Register = "FP"
)

func (Register) MarshalJSON added in v0.8.0

func (r Register) MarshalJSON() ([]byte, error)

MarshalJSON implements json.Marshaler

func (*Register) UnmarshalJSON added in v0.8.0

func (r *Register) UnmarshalJSON(data []byte) error

UnmarshalJSON implements json.Unmarshaler

type ResOperand added in v0.8.0

type ResOperand struct {
	Type string
	Data interface{}
}

Can be one of the following values:

  • BinOp
  • Deref
  • DoubleDeref
  • Immediate

func (ResOperand) MarshalJSON added in v0.8.0

func (r ResOperand) MarshalJSON() ([]byte, error)

MarshalJSON implements json.Marshaler

func (*ResOperand) UnmarshalJSON added in v0.8.0

func (r *ResOperand) UnmarshalJSON(data []byte) error

UnmarshalJSON implements json.Unmarshaler

type ShouldContinueSquashLoop added in v0.8.0

type ShouldContinueSquashLoop struct {
	ShouldContinue CellRef `json:"should_continue"`
}

type ShouldSkipSquashLoop added in v0.8.0

type ShouldSkipSquashLoop struct {
	ShouldSkipLoop CellRef `json:"should_skip_loop"`
}

type SierraEntryPoint added in v0.8.0

type SierraEntryPoint struct {
	// The index of the function in the program
	FunctionIdx int `json:"function_idx"`
	// A unique  identifier of the entry point (function) in the program
	Selector *felt.Felt `json:"selector"`
}

type SierraEntryPointsByType added in v0.8.0

type SierraEntryPointsByType struct {
	Constructor []SierraEntryPoint `json:"CONSTRUCTOR"`
	External    []SierraEntryPoint `json:"EXTERNAL"`
	L1Handler   []SierraEntryPoint `json:"L1_HANDLER"`
}

type SquareRoot added in v0.8.0

type SquareRoot struct {
	Value ResOperand `json:"value"`
	Dst   CellRef    `json:"dst"`
}

type StructABIEntry added in v0.8.0

type StructABIEntry struct {
	// The event type
	Type ABIType `json:"type"`

	// The event name
	Name string `json:"name"`

	// todo(minimum size should be 1)
	Size uint64 `json:"size"`

	Members []Member `json:"members"`
}

func (*StructABIEntry) IsType added in v0.8.0

func (s *StructABIEntry) IsType() ABIType

IsType returns the ABIType of the StructABIEntry.

type SystemCall added in v0.8.0

type SystemCall struct {
	System ResOperand `json:"system"`
}

type TestLessThan added in v0.8.0

type TestLessThan struct {
	Dst CellRef `json:"dst"`
	// contains filtered or unexported fields
}

type TestLessThanOrEqual added in v0.8.0

type TestLessThanOrEqual TestLessThan

type TestLessThanOrEqualAddress added in v0.8.0

type TestLessThanOrEqualAddress TestLessThan

type TypedParameter added in v0.8.0

type TypedParameter struct {
	// The parameter's name
	Name string `json:"name"`

	// The parameter's type
	Type string `json:"type"`
}

type U256InvModN added in v0.8.0

type U256InvModN struct {
	B0        ResOperand `json:"b0"`
	B1        ResOperand `json:"b1"`
	N0        ResOperand `json:"n0"`
	N1        ResOperand `json:"n1"`
	G0OrNoInv CellRef    `json:"g0_or_no_inv"`
	G1Option  CellRef    `json:"g1_option"`
	SOrR0     CellRef    `json:"s_or_r0"`
	SOrR1     CellRef    `json:"s_or_r1"`
	TOrK0     CellRef    `json:"t_or_k0"`
	TOrK1     CellRef    `json:"t_or_k1"`
}

type Uint256DivMod added in v0.8.0

type Uint256DivMod struct {
	Dividend0  ResOperand `json:"dividend0"`
	Dividend1  ResOperand `json:"dividend1"`
	Divisor0   ResOperand `json:"divisor0"`
	Divisor1   ResOperand `json:"divisor1"`
	Quotient0  CellRef    `json:"quotient0"`
	Quotient1  CellRef    `json:"quotient1"`
	Remainder0 CellRef    `json:"remainder0"`
	Remainder1 CellRef    `json:"remainder1"`
}

type Uint256SquareRoot added in v0.8.0

type Uint256SquareRoot struct {
	ValueLow                     ResOperand `json:"value_low"`
	ValueHigh                    ResOperand `json:"value_high"`
	Sqrt0                        CellRef    `json:"sqrt0"`
	Sqrt1                        CellRef    `json:"sqrt1"`
	RemainderLow                 CellRef    `json:"remainder_low"`
	RemainderHigh                CellRef    `json:"remainder_high"`
	SqrtMul2MinusRemainderGeU128 CellRef    `json:"sqrt_mul_2_minus_remainder_ge_u128"`
}

type Uint512DivModByUint256 added in v0.8.0

type Uint512DivModByUint256 struct {
	Uint256DivMod
	Dividend2 ResOperand `json:"dividend2"`
	Dividend3 ResOperand `json:"dividend3"`
	Quotient2 CellRef    `json:"quotient2"`
	Quotient3 CellRef    `json:"quotient3"`
}

type WideMul128 added in v0.8.0

type WideMul128 struct {
	High CellRef `json:"high"`
	Low  CellRef `json:"low"`
	// contains filtered or unexported fields
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL