pub struct ContractId {
    /// The underlying raw `b256` data of the contract id.
    bits: b256,
}
Expand description

The ContractId type, a struct wrapper around the inner b256 value.

Fields

bits: b256

The underlying raw b256 data of the contract id.

Implementations

fn bits(self) -> b256

Returns the underlying raw b256 data of the contract id.

Returns

  • [b256] - The raw data of the contract id.

Examples

use std::constants::ZERO_B256;

fn foo() -> {
    let my_contract = ContractId::from(ZERO_B256);
    assert(my_contract.bits() == ZERO_B256);
}

fn this() -> ContractId

Returns the ContractId of the currently executing contract.

Additional Information

This is equivalent to std::callframes::contract_id().

Note: If called in an external context, this will not return a ContractId.
If called externally, will actually return a pointer to the Transaction Id (Wrapped in the ContractId struct).

Returns

  • [ContractId] - The contract id of this contract.

Examples

use std::{constants::ZERO_B256, asset::mint};

fn foo() {
    let this_contract = ContractId::this();
    mint(ZERO_B256, 50);
    Address::from(ZERO_B256).transfer(AssetId::default(this_contract), 50);
}

Trait Implementations

fn eq(self, other: Self) -> bool

fn neq(self, other: Self) -> bool

Evaluates if two values of the same type are not equal.

Additional Information

This function is inherited when eq() is implemented.

Arguments

  • other: [Self] - The value of the same type.

Returns

  • [bool] - true if the two values are not equal, otherwise false.

Examples

struct MyStruct {
    val: u64,
}

impl Eq for MyStruct {
    fn eq(self, other: Self) -> bool {
         self.val == other.val
    }
}

fn foo() {
    let struct1 = MyStruct { val: 10 };
    let struct2 = MyStruct { val: 2 };
    let result = struct1 != struct2;
    assert(result);
}

fn from(bits: b256) -> Self

Casts raw b256 data to a ContractId.

Arguments

  • bits: [b256] - The raw b256 data to be casted.

Returns

  • [ContractId] - The newly created ContractId from the raw b256.

Examples

use std::constants::ZERO_B256;

fn foo() {
   let contract_id = ContractId::from(ZERO_B256);
}

fn hash(
self,
refmut state: Hasher,
)