sys.aspect
Provides APIs that communicate with Aspect, including id, version, transientStorage, property, state and context.
1. sys.aspect.id
Get aspect id.
sys.aspect.id():string
- Returns
- aspect:string
- Example
const aspectId = sys.aspect.id()
2. sys.aspect.version
Get Aspect version.
sys.aspect.version(): u64
- Returns
- aspect:string
- Example
const version = sys.aspect.version()
3. sys.aspect.readonlyState
Readonly state
sys.aspect.readonlyState.get<T>(key: string):ImmutableStateValue<T>
- Parameter
- key:string state key.
- Returns
- value:T state value. The supported generics type
are:
u8
i8
u16
i16
u32
i32
u64
i64
string
Uint8Array
BigInt
- value:T state value. The supported generics type
are:
- Example
const value = sys.aspect.readonlyState.get<string>("key").unwrap();
4. sys.aspect.mutableState
Get set on aspect state
sys.aspect.mutableState.get<T>(key: string): MutableStateValue<T>
- Parameter
- key:string state key.
- Returns
- value:T state value. The supported generics type
are:
u8
i8
u16
i16
u32
i32
u64
i64
string
Uint8Array
BigInt
- value:T state value. The supported generics type
are:
- Example
// 1. get string value
const value = sys.aspect.mutableState.get<string>("key").unwrap();
// 2. set (key=>value)
sys.aspect.mutableState.get<string>("key").set<string>("value");
// 3. Function Call Mode
const mutableState = sys.aspect.mutableState.get<string>("key");
mutableState.set<string>("value2"); // set (key=>value2)
mutableState.reload(); // reload state
var data = mutableState.unwrap(); // data="value2"
5. sys.aspect.property
Get property by key.
sys.aspect.property.get<T>(key: string): T
- Parameter
- key:string property key.
- Returns
- value:T property value. The supported generics type
are:
u8
i8
u16
i16
u32
i32
u64
i64
string
Uint8Array
BigInt
- value:T property value. The supported generics type
are:
- Example
const value = sys.aspect.rproperty.get<string>("key");
6. sys.aspect.transientStorage
Get、set transientStorage.
sys.aspect.transientStorage.get<T>(key: string, prefix: string = ''): TransientStorageValue<T>
- Parameter
- key:string aspect context key.
- Returns
- result:TransientStorageValue context value. The supported generics type
are:
u8
i8
u16
i16
u32
i32
u64
i64
string
Uint8Array
BigInt
.
- result:TransientStorageValue context value. The supported generics type
are:
- Example
import {
sys
} from "@artela/aspect-libs";
let key="test"
// inline call
sys.aspect.transientStorage.get<string>(key).set<u32>(10000);
// function call
let transientStorage = sys.aspect.transientStorage.get<string>(key);
// set (test=>9999)
transientStorage.set<u32>(9999);
// reload storage, optional
transientStorage.reload();
// get value=9999
var val = transientStorage.unwrap();