pub struct AssetId {
bits: b256,
}
Expand description
An AssetId is used for interacting with an asset on the network.
Additional Information
It is calculated by taking the sha256 hash of the originating ContractId and a SubId.
i.e. sha256((contract_id, sub_id)).
An exception is the Base Asset.
The SubId is used to differentiate between different assets that are created by the same contract.
Fields
bits: b256
Implementations
fn new(contract_id: ContractId, sub_id: SubId) -> Self
fn new(contract_id: ContractId, sub_id: SubId) -> Self
Creates a new AssetId from a ContractId and SubId.
Arguments
contract_id
: [ContractId] - The ContractId of the contract that created the asset.sub_id
: [SubId] - The SubId of the asset.
Returns
- [AssetId] - The AssetId of the asset. Computed by hashing the ContractId and SubId.
Examples
use std::{callframes::contract_id, constants::ZERO_B256};
fn foo() {
let contract_id = contract_id();
let sub_id = ZERO_B256;
let asset_id = AssetId::new(contract_id, sub_id);
}
fn default() -> Self
fn default() -> Self
Creates a new AssetId with the default SubId for the current contract.
Returns
- [AssetId] - The AssetId of the asset. Computed by hashing the ContractId and the default SubId.
Examples
use std::{callframes::contract_id, constants::DEFAULT_SUB_ID};
fn foo() {
let asset_id = AssetId::default();
assert(asset_id == AssetId::new(contract_id(), DEFAULT_SUB_ID));
}
fn base() -> Self
fn base() -> Self
The base asset of a chain.
Additional Information
On the Fuel network, the base asset is Ether.
Returns
- [AssetId] - The AssetId of the base asset.
Examples
use std::{constants::ZERO_B256, asset::transfer};
fn foo() {
let asset_id = AssetId::base();
let amount = 100;
let recipient = Identity::ContractId(ContractId::from(ZERO_B256));
transfer(recipient, asset_id, amount);
fn bits(self) -> b256
fn bits(self) -> b256
Returns the underlying raw b256
data of the asset id.
Returns
- [b256] - The raw data of the asset id.
Examples
use std::constants::ZERO_B256;
fn foo() -> {
let my_asset = AssetId::from(ZERO_B256);
assert(my_asset.bits() == ZERO_B256);
}
Trait Implementations
impl Eq for AssetId
impl Eq for AssetId
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);
}