Struct std::contract_id::ContractId
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
fn bits(self) -> b256
Returns the underlying raw b256
data of the contract id.
Returns
- [b256] - The raw data of the contract id.
Examples
fn foo() -> {
let my_contract = ContractId:zero();
assert(my_contract.bits() == b256::zero());
}
fn this() -> ContractId
fn this() -> ContractId
Returns the ContractId of the currently executing contract.
Additional Information
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::asset::mint;
fn foo() {
let this_contract = ContractId::this();
mint(b256::zero(), 50);
Address::zero().transfer(AssetId::default(this_contract), 50);
}
fn zero() -> Self
fn zero() -> Self
Returns the zero value for the ContractId
type.
Returns
- [ContractId] -> The zero value for the
ContractId
type.
Examples
fn foo() {
let zero_contract_id = ContractId::zero();
assert(zero_contract_id == ContractId::from(b256::zero()));
}
fn is_zero(self) -> bool
fn is_zero(self) -> bool
Returns whether a ContractId
is set to zero.
Returns
- [bool] -> True if the
ContractId
is zero, otherwise false.
Examples
fn foo() {
let zero_contract_id = ContractId::zero();
assert(zero_contract_id.is_zero());
}
Trait Implementations
impl AbiEncode for ContractId
impl AbiEncode for ContractId
fn abi_encode(self, buffer: Buffer) -> Buffer
impl AbiDecode for ContractId
impl AbiDecode for ContractId
fn abi_decode(refmut buffer: BufferReader) -> Self
impl Eq for ContractId
impl Eq for ContractId
fn eq(self, other: Self) -> bool
fn neq(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, otherwisefalse
.
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);
}