⌘K

Contract Id

Icon LinkContractId

Bytes32 类似,ContractId 是对 [u8; 32] 的包装器,具有类似的方法并实现相同的特性(参见 fuel-types 文档 Icon Link)。

以下是创建 ContractId 的主要方法:

use std::str::FromStr;
 
use fuels::types::ContractId;
 
// Zeroed Bytes32
let contract_id = ContractId::zeroed();
 
// Grab the inner `[u8; 32]` from
// `Bytes32` by dereferencing (i.e. `*`) it.
assert_eq!([0u8; 32], *contract_id);
 
// From a `[u8; 32]`.
let my_slice = [1u8; 32];
let contract_id = ContractId::new(my_slice);
assert_eq!([1u8; 32], *contract_id);
 
// From a string.
let hex_str = "0x0000000000000000000000000000000000000000000000000000000000000000";
let contract_id = ContractId::from_str(hex_str)?;
assert_eq!([0u8; 32], *contract_id);