@casperlabs/contract
v0.5.1
Published
Library for developing CasperLabs smart contracts.
Downloads
10
Readme
@casperlabs/contract
This package allows a distributed app developer to create smart contracts for the open source CasperLabs project using AssemblyScript.
Installation
For each smart contract you create, make a project directory and initialize it.
mkdir project
cd project
npm init
npm init will prompt you for various details about your project;
answer as you see fit but you may safely default everything except name
which should follow the convention of
your-contract-name
.
Then install assembly script and this package in the project directory.
npm install --save-dev [email protected]
npm install --save @casperlabs/contract
Usage
Add script entries for assembly script to your project's package.json
; note that your contract name is used
for the name of the wasm file.
{
"name": "your-contract-name",
...
"scripts": {
"asbuild:optimized": "asc assembly/index.ts -b dist/your-contract-name.wasm --validate --optimize --use abort=",
"asbuild": "npm run asbuild:optimized",
...
},
...
}
In your project root, create an index.js
file with the following contents:
const fs = require("fs");
const compiled = new WebAssembly.Module(fs.readFileSync(__dirname + "/dist/your-contract-name.wasm"));
const imports = {
env: {
abort(_msg, _file, line, column) {
console.error("abort called at index.ts:" + line + ":" + column);
}
}
};
Object.defineProperty(module, "exports", {
get: () => new WebAssembly.Instance(compiled, imports).exports
});
Create an assembly/tsconfig.json
file in the following way:
{
"extends": "../node_modules/assemblyscript/std/assembly.json",
"include": [
"./**/*.ts"
]
}
Sample smart contract
Create a assembly/index.ts
file. This is where the code for your contract will go.
You can use the following sample snippet which demonstrates a very simple smart contract that immediately returns an error, which will write a message to a block if executed on the CasperLabs platform.
//@ts-nocheck
import {Error, ErrorCode} from "@casperlabs/contract/error";
// simplest possible feedback loop
export function call(): void {
Error.fromErrorCode(ErrorCode.None).revert(); // ErrorCode: 1
}
If you prefer a more complicated first contract, you can look at client contracts on the CasperLabs github repository for inspiration.
Compile to wasm
To compile your contract to wasm, use npm to run the asbuild script from your project root.
npm run asbuild
If the build is successful, you should see a dist
folder in your root folder and in it
should be your-contract-name.wasm
@casperlabs/contract
Index
Modules
- "account"
- "bignum"
- "bytesrepr"
- "clvalue"
- "constants"
- "contracts"
- "error"
- "externals"
- "index"
- "key"
- "local"
- "option"
- "pair"
- "purse"
- "runtime_args"
- "unit"
- "uref"
- "utils"
Classes
Class: U512
An implementation of 512-bit unsigned integers.
Hierarchy
- U512
Index
Constructors
Accessors
Methods
- add
- bits
- clone
- cmp
- div
- divMod
- eq
- gt
- gte
- isZero
- lt
- lte
- mul
- neg
- neq
- postfixDec
- postfixInc
- prefixDec
- prefixInc
- rem
- setBytesLE
- setHex
- setU64
- setValues
- shl
- shr
- sub
- toBytes
- toBytesLE
- toString
- fromBytes
- fromHex
- fromU64
Constructors
constructor
+ new U512(): U512
Defined in bignum.ts:31
Constructs a new instance of U512.
Returns: U512
Accessors
width
• get width(): i32
Defined in bignum.ts:79
Gets the width of the number in bytes.
Returns: i32
Static
MAX_VALUE
• get MAX_VALUE(): U512
Defined in bignum.ts:43
Returns: U512
The maximum possible value of a U512.
Static
MIN_VALUE
• get MIN_VALUE(): U512
Defined in bignum.ts:52
Returns: U512
The minimum possible value of a U512 (which is 0).
Methods
add
Defined in bignum.ts:146
The addition operator - adds two U512 numbers together.
Parameters:
Name | Type |
------ | ------ |
other
| U512 |
Returns: U512
bits
▸ bits(): u32
Defined in bignum.ts:282
Returns length of the integer in bits (not counting the leading zero bits).
Returns: u32
clone
▸ clone(): U512
Defined in bignum.ts:273
Clones the U512.
Returns: U512
cmp
▸ cmp(other
: U512): i32
Defined in bignum.ts:406
Compares this
and other
.
Parameters:
Name | Type | Description |
------ | ------ | ------ |
other
| U512 | The number to compare this
to. |
Returns: i32
-1 if this
is less than other
, 1 if this
is greater than other
, 0 if this
and other
are equal.
div
Defined in bignum.ts:339
The division operator - divides the arguments.
Parameters:
Name | Type |
------ | ------ |
other
| U512 |
Returns: U512
divMod
▸ divMod(other
: U512): Pair‹U512, U512› | null
Defined in bignum.ts:298
Performs the integer division of this/other
.
Parameters:
Name | Type | Description |
------ | ------ | ------ |
other
| U512 | The divisor. |
Returns: Pair‹U512, U512› | null
A pair consisting of the quotient and the remainder, or null if the divisor was 0.
eq
▸ eq(other
: U512): bool
Defined in bignum.ts:425
The equality operator.
Parameters:
Name | Type |
------ | ------ |
other
| U512 |
Returns: bool
True if this
and other
are equal, false otherwise.
gt
▸ gt(other
: U512): bool
Defined in bignum.ts:445
The greater-than operator.
Parameters:
Name | Type |
------ | ------ |
other
| U512 |
Returns: bool
True if this
is greater than other
, false otherwise.
gte
▸ gte(other
: U512): bool
Defined in bignum.ts:465
The greater-than-or-equal operator.
Parameters:
Name | Type |
------ | ------ |
other
| U512 |
Returns: bool
True if this
is greater than or equal to other
, false otherwise.
isZero
▸ isZero(): bool
Defined in bignum.ts:133
Checks whether this U512 is equal to 0.
Returns: bool
True if this U512 is 0, false otherwise.
lt
▸ lt(other
: U512): bool
Defined in bignum.ts:455
The less-than operator.
Parameters:
Name | Type |
------ | ------ |
other
| U512 |
Returns: bool
True if this
is less than other
, false otherwise.
lte
▸ lte(other
: U512): bool
Defined in bignum.ts:475
The less-than-or-equal operator.
Parameters:
Name | Type |
------ | ------ |
other
| U512 |
Returns: bool
True if this
is less than or equal to other
, false otherwise.
mul
Defined in bignum.ts:185
The multiplication operator - calculates the product of the two arguments.
Parameters:
Name | Type |
------ | ------ |
other
| U512 |
Returns: U512
neg
▸ neg(): U512
Defined in bignum.ts:164
The negation operator - returns the two's complement of the argument.
Returns: U512
neq
▸ neq(other
: U512): bool
Defined in bignum.ts:435
The not-equal operator.
Parameters:
Name | Type |
------ | ------ |
other
| U512 |
Returns: bool
False if this
and other
are equal, true otherwise.
postfixDec
▸ postfixDec(): U512
Defined in bignum.ts:253
Postfix operator --
- decrements this U512.
Returns: U512
postfixInc
▸ postfixInc(): U512
Defined in bignum.ts:243
Postfix operator ++
- increments this U512.
Returns: U512
prefixDec
▸ prefixDec(): U512
Defined in bignum.ts:234
Prefix operator --
- decrements this U512.
Returns: U512
prefixInc
▸ prefixInc(): U512
Defined in bignum.ts:225
Prefix operator ++
- increments this U512.
Returns: U512
rem
Defined in bignum.ts:349
The 'modulo' operator - calculates the remainder from the division of the arguments.
Parameters:
Name | Type |
------ | ------ |
other
| U512 |
Returns: U512
setBytesLE
▸ setBytesLE(bytes
: Uint8Array): void
Defined in bignum.ts:496
Sets the value of this U512 to the value represented by bytes
when treated as a
little-endian representation of a number.
Parameters:
Name | Type |
------ | ------ |
bytes
| Uint8Array |
Returns: void
setHex
▸ setHex(value
: String): void
Defined in bignum.ts:100
Sets the value of this U512 to a value represented by the given string of hex digits.
Parameters:
Name | Type | Description |
------ | ------ | ------ |
value
| String | The string of hex digits representing the desired value. |
Returns: void
setU64
▸ setU64(value
: u64): void
Defined in bignum.ts:88
Sets the value of this U512 to a given 64-bit value.
Parameters:
Name | Type | Description |
------ | ------ | ------ |
value
| u64 | The desired new value of this U512. |
Returns: void
setValues
▸ setValues(pn
: Uint32Array): void
Defined in bignum.ts:264
Sets the values of the internally kept 32-bit "digits" (or "limbs") of the U512.
Parameters:
Name | Type | Description |
------ | ------ | ------ |
pn
| Uint32Array | The array of unsigned 32-bit integers to be used as the "digits"/"limbs". |
Returns: void
shl
▸ shl(shift
: u32): U512
Defined in bignum.ts:359
The bitwise left-shift operator.
Parameters:
Name | Type |
------ | ------ |
shift
| u32 |
Returns: U512
shr
▸ shr(shift
: u32): U512
Defined in bignum.ts:381
The bitwise right-shift operator.
Parameters:
Name | Type |
------ | ------ |
shift
| u32 |
Returns: U512
sub
Defined in bignum.ts:177
The subtraction operator - subtracts the two U512s.
Parameters:
Name | Type |
------ | ------ |
other
| U512 |
Returns: U512
toBytes
▸ toBytes(): Array‹u8›
Defined in bignum.ts:578
Serializes the U512 into an array of bytes that represents it in the CasperLabs serialization format.
Returns: Array‹u8›
toBytesLE
▸ toBytesLE(): Uint8Array
Defined in bignum.ts:483
Returns a little-endian byte-array representation of this U512 (i.e. result[0]
is the least
significant byte.
Returns: Uint8Array
toString
▸ toString(): String
Defined in bignum.ts:539
An alias for [[toHex]].
Returns: String
Static
fromBytes
▸ fromBytes(bytes
: Uint8Array): Result‹U512›
Defined in bignum.ts:550
Deserializes a U512 from an array of bytes. The array should represent a correct U512 in the CasperLabs serialization format.
Parameters:
Name | Type |
------ | ------ |
bytes
| Uint8Array |
A Result that contains the deserialized U512 if the deserialization was successful, or an error otherwise.
Static
fromHex
▸ fromHex(hex
: String): U512
Defined in bignum.ts:59
Constructs a new U512 from a string of hex digits.
Parameters:
Name | Type |
------ | ------ |
hex
| String |
Returns: U512
Static
fromU64
▸ fromU64(value
: u64): U512
Defined in bignum.ts:70
Converts a 64-bit unsigned integer into a U512.
Parameters:
Name | Type | Description |
------ | ------ | ------ |
value
| u64 | The value to be converted. |
Returns: U512
Class: Ref <T>
Boxes a value which could then be nullable in any context.
Type parameters
▪ T
Hierarchy
- Ref
Index
Constructors
Properties
Constructors
constructor
+ new Ref(value
: T): Ref
Defined in bytesrepr.ts:8
Parameters:
Name | Type |
------ | ------ |
value
| T |
Returns: Ref
Properties
value
• value: T
Defined in bytesrepr.ts:9
Class: Result <T>
Class representing a result of an operation that might have failed. Can contain either a value
resulting from a successful completion of a calculation, or an error. Similar to Result
in Rust
or Either
in Haskell.
Type parameters
▪ T
Hierarchy
- Result
Index
Constructors
Properties
Accessors
Methods
Constructors
constructor
+ new Result(ref
: Ref‹T› | null, error
: Error, position
: u32): Result
Defined in bytesrepr.ts:53
Creates new Result with wrapped value
Parameters:
Name | Type | Description |
------ | ------ | ------ |
ref
| Ref‹T› | null | - |
error
| Error | Error value |
position
| u32 | Position of input stream |
Returns: Result
Properties
error
• error: Error
Defined in bytesrepr.ts:60
Error value
position
• position: u32
Defined in bytesrepr.ts:60
Position of input stream
ref
• ref: Ref‹T› | null
Defined in bytesrepr.ts:60
Accessors
value
• get value(): T
Defined in bytesrepr.ts:65
Assumes that reference wrapper contains a value and then returns it
Returns: T
Methods
hasError
▸ hasError(): bool
Defined in bytesrepr.ts:83
Checks if error value is set.
Truth also implies !hasValue(), false value implies hasValue()
Returns: bool
hasValue
▸ hasValue(): bool
Defined in bytesrepr.ts:74
Checks if given Result contains a value
Returns: bool
ok
▸ ok(): T | null
Defined in bytesrepr.ts:90
For nullable types, this returns the value itself, or a null.
Returns: T | null
unwrap
▸ unwrap(): T
Defined in bytesrepr.ts:97
Returns success value, or reverts error value.
Returns: T
Class: CLType
Hierarchy
- CLType
Index
Constructors
Properties
Methods
Constructors
constructor
+ new CLType(tag
: CLTypeTag, extra
: Array‹u8› | null): CLType
Defined in clvalue.ts:63
Parameters:
Name | Type | Default |
------ | ------ | ------ |
tag
| CLTypeTag | - |
extra
| Array‹u8› | null | null |
Returns: CLType
Properties
bytes
• bytes: Array‹u8›
Defined in clvalue.ts:63
tag
• tag: CLTypeTag
Defined in clvalue.ts:62
Methods
toBytes
▸ toBytes(): u8[]
Defined in clvalue.ts:90
Returns: u8[]
Static
fixedList
▸ fixedList(typeTag
: CLType, size
: u32): CLType
Defined in clvalue.ts:73
Parameters:
Name | Type |
------ | ------ |
typeTag
| CLType |
size
| u32 |
Returns: CLType
Static
list
▸ list(typeTag
: CLType): CLType
Defined in clvalue.ts:82
Parameters:
Name | Type |
------ | ------ |
typeTag
| CLType |
Returns: CLType
Static
option
▸ option(typeTag
: CLType): CLType
Defined in clvalue.ts:86
Parameters:
Name | Type |
------ | ------ |
typeTag
| CLType |
Returns: CLType
Class: CLValue
A CasperLabs value, i.e. a value which can be stored and manipulated by smart contracts.
It holds the underlying data as a type-erased, serialized array of bytes and also holds the CLType of the underlying data as a separate member.
Hierarchy
- CLValue
Index
Constructors
Properties
Methods
Constructors
constructor
+ new CLValue(bytes
: u8[], clType
: CLType): CLValue
Defined in clvalue.ts:103
Constructs a new CLValue
with given underlying data and type.
Parameters:
Name | Type |
------ | ------ |
bytes
| u8[] |
clType
| CLType |
Returns: CLValue
Properties
bytes
• bytes: u8[]
Defined in clvalue.ts:102
clType
• clType: CLType
Defined in clvalue.ts:103
Methods
toBytes
▸ toBytes(): u8[]
Defined in clvalue.ts:172
Serializes a CLValue
into an array of bytes.
Returns: u8[]
Static
fromI32
▸ fromI32(value
: i32): CLValue
Defined in clvalue.ts:130
Creates a CLValue
holding a signed 32-bit integer.
Parameters:
Name | Type |
------ | ------ |
value
| i32 |
Returns: CLValue
Static
fromKey
Defined in clvalue.ts:144
Creates a CLValue
holding a Key.
Parameters:
Name | Type |
------ | ------ |
key
| Key |
Returns: CLValue
Static
fromOption
▸ fromOption(value
: Option, nestedT
: CLType): CLValue
Defined in clvalue.ts:165
Creates a CLValue
holding an Option.
Parameters:
Name | Type |
------ | ------ |
value
| Option |
nestedT
| CLType |
Returns: CLValue
Static
fromString
▸ fromString(s
: String): CLValue
Defined in clvalue.ts:116
Creates a CLValue
holding a string.
Parameters:
Name | Type |
------ | ------ |
s
| String |
Returns: CLValue
Static
fromStringList
▸ fromStringList(values
: String[]): CLValue
Defined in clvalue.ts:158
Creates a CLValue
holding a list of strings.
Parameters:
Name | Type |
------ | ------ |
values
| String[] |
Returns: CLValue
Static
fromU512
▸ fromU512(value
: U512): CLValue
Defined in clvalue.ts:123
Creates a CLValue
holding an unsigned 512-bit integer.
Parameters:
Name | Type |
------ | ------ |
value
| U512 |
Returns: CLValue
Static
fromU64
▸ fromU64(value
: u64): CLValue
Defined in clvalue.ts:137
Creates a CLValue
holding an unsigned 64-bit integer.
Parameters:
Name | Type |
------ | ------ |
value
| u64 |
Returns: CLValue
Static
fromURef
▸ fromURef(uref
: URef): CLValue
Defined in clvalue.ts:151
Creates a CLValue
holding a URef.
Parameters:
Name | Type |
------ | ------ |
uref
| URef |
Returns: CLValue
Class: Error
This class represents error condition and is constructed by passing an error value.
The variants are split into numeric ranges as follows:
| Inclusive range | Variant(s) |
| ----------------| ---------------------------------------------|
| [1, 65023] | all except Mint
, ProofOfStake
and User
. Can be created with Error.fromErrorCode |
| [65024, 65279] | Mint
- instantiation currently unsupported |
| [65280, 65535] | ProofOfStake
errors |
| [65536, 131071] | User error codes created with Error.fromUserError |
Example usage
// Creating using user error which adds 65536 to the error value.
Error.fromUserError(1234).revert();
// Creating using standard error variant.
Error.fromErrorCode(ErrorCode.InvalidArguent).revert();
Hierarchy
- Error
Index
Constructors
Methods
Constructors
constructor
+ new Error(value
: u32): Error
Defined in error.ts:115
Creates an error object with given error value.
Recommended way to use this class is through its static members:
- [[Error.fromUserCode]]
- Error.fromErrorCode
Parameters:
Name | Type | Description |
------ | ------ | ------ |
value
| u32 | Error value |
Returns: Error
Methods
isSystemContractError
▸ isSystemContractError(): bool
Defined in error.ts:183
Checks if error value is contained within system contract error range.
Returns: bool
isUserError
▸ isUserError(): bool
Defined in error.ts:176
Checks if error value is contained within user error range.
Returns: bool
revert
▸ revert(): void
Defined in error.ts:190
Reverts execution of current contract with an error value contained within this error instance.
Returns: void
value
▸ value(): u32
Defined in error.ts:169
Returns an error value.
Returns: u32
Static
fromErrorCode
▸ fromErrorCode(errorCode
: ErrorCode): Error
Defined in error.ts:162
Creates new error object from an ErrorCode value.
Parameters:
Name | Type | Description |
------ | ------ | ------ |
errorCode
| ErrorCode | Variant of a standarized error. |
Returns: Error
Static
fromResult
▸ fromResult(result
: u32): Error | null
Defined in error.ts:139
Creates an error object from a result value.
Results in host interface contains 0 for a successful operation, or a non-zero standardized error otherwise.
Parameters:
Name | Type | Description |
------ | ------ | ------ |
result
| u32 | A result value obtained from host interface functions. |
Returns: Error | null
Error object with an error ErrorCode variant.
Static
fromUserError
▸ fromUserError(userErrorCodeValue
: u16): Error
Defined in error.ts:153
Creates new error from user value.
Actual value held by returned Error object will be 65536 with added passed value.
Parameters:
Name | Type | Description |
------ | ------ | ------ |
userErrorCodeValue
| u16 | |
Returns: Error
Class: AddContractVersionResult
Hierarchy
- AddContractVersionResult
Index
Constructors
Properties
Constructors
constructor
+ new AddContractVersionResult(contractHash
: Uint8Array, contractVersion
: u32): AddContractVersionResult
Defined in index.ts:501
Parameters:
Name | Type |
------ | ------ |
contractHash
| Uint8Array |
contractVersion
| u32 |
Returns: AddContractVersionResult
Properties
contractHash
• contractHash: Uint8Array
Defined in index.ts:502
contractVersion
• contractVersion: u32
Defined in index.ts:502
Class: CreateContractPackageResult
A two-value structure that holds the result of createContractPackageAtHash.
Hierarchy
- CreateContractPackageResult
Index
Constructors
Properties
Constructors
constructor
+ new CreateContractPackageResult(packageHash
: Uint8Array, accessURef
: URef): CreateContractPackageResult
Defined in index.ts:436
Parameters:
Name | Type |
------ | ------ |
packageHash
| Uint8Array |
accessURef
| URef |
Returns: CreateContractPackageResult
Properties
accessURef
• accessURef: URef
Defined in index.ts:437
packageHash
• packageHash: Uint8Array
Defined in index.ts:437
Class: EntryPoint
Hierarchy
- EntryPoint
Index
Constructors
Properties
Methods
Constructors
constructor
+ new EntryPoint(name
: String, args
: Array‹Pair‹String, CLType››, ret
: CLType, access
: EntryPointAccess, entry_point_type
: EntryPointType): EntryPoint
Defined in index.ts:404
Parameters:
Name | Type |
------ | ------ |
name
| String |
args
| Array‹Pair‹String, CLType›› |
ret
| CLType |
access
| EntryPointAccess |
entry_point_type
| EntryPointType |
Returns: EntryPoint
Properties
access
• access: EntryPointAccess
Defined in index.ts:408
args
• args: Array‹Pair‹String, CLType››
Defined in index.ts:406
entry_point_type
• entry_point_type: EntryPointType
Defined in index.ts:409
name
• name: String
Defined in index.ts:405
ret
• ret: CLType
Defined in index.ts:407
Methods
toBytes
▸ toBytes(): Array‹u8›
Defined in index.ts:411
Returns: Array‹u8›
Class: EntryPointAccess
Hierarchy
EntryPointAccess
Index
Constructors
Properties
Methods
Constructors
constructor
+ new EntryPointAccess(cachedBytes
: Array‹u8›): EntryPointAccess
Defined in index.ts:377
Parameters:
Name | Type |
------ | ------ |
cachedBytes
| Array‹u8› |
Returns: EntryPointAccess
Properties
cachedBytes
• cachedBytes: Array‹u8›
Defined in index.ts:378
Methods
toBytes
▸ toBytes(): Array‹u8›
Defined in index.ts:379
Returns: Array‹u8›
Class: EntryPoints
Hierarchy
- EntryPoints
Index
Properties
Methods
Properties
entryPoints
• entryPoints: Array‹Pair‹String, EntryPoint›› = new Array<Pair<String, EntryPoint>>()
Defined in index.ts:423
Methods
addEntryPoint
▸ addEntryPoint(entryPoint
: EntryPoint): void
Defined in index.ts:424
Parameters:
Name | Type |
------ | ------ |
entryPoint
| EntryPoint |
Returns: void
toBytes
▸ toBytes(): Array‹u8›
Defined in index.ts:427
Returns: Array‹u8›
Class: GroupAccess
Hierarchy
↳ GroupAccess
Index
Constructors
Properties
Methods
Constructors
constructor
+ new GroupAccess(groups
: String[]): GroupAccess
Overrides EntryPointAccess.constructor
Defined in index.ts:390
Parameters:
Name | Type |
------ | ------ |
groups
| String[] |
Returns: GroupAccess
Properties
cachedBytes
• cachedBytes: Array‹u8›
Inherited from EntryPointAccess.cachedBytes
Defined in index.ts:378
Methods
toBytes
▸ toBytes(): Array‹u8›
Inherited from EntryPointAccess.toBytes
Defined in index.ts:379
Returns: Array‹u8›
Class: PublicAccess
Hierarchy
↳ PublicAccess
Index
Constructors
Properties
Methods
Constructors
constructor
+ new PublicAccess(): PublicAccess
Overrides EntryPointAccess.constructor
Defined in index.ts:384
Returns: PublicAccess
Properties
cachedBytes
• cachedBytes: Array‹u8›
Inherited from EntryPointAccess.cachedBytes
Defined in index.ts:378
Methods
toBytes
▸ toBytes(): Array‹u8›
Inherited from EntryPointAccess.toBytes
Defined in index.ts:379
Returns: Array‹u8›
Class: AccountHash
A cryptographic public key.
Hierarchy
- AccountHash
Index
Constructors
Properties
Methods
Constructors
constructor
+ new AccountHash(bytes
: Uint8Array): AccountHash
Defined in key.ts:23
Constructs a new AccountHash
.
Parameters:
Name | Type | Description |
------ | ------ | ------ |
bytes
| Uint8Array | The bytes constituting the public key. |
Returns: AccountHash
Properties
bytes
• bytes: Uint8Array
Defined in key.ts:29
The bytes constituting the public key.
Methods
equalsTo
▸ equalsTo(other
: AccountHash): bool
Defined in key.ts:33
Checks whether two AccountHash
s are equal.
Parameters:
Name | Type |
------ | ------ |
other
| AccountHash |
Returns: bool
notEqualsTo
▸ notEqualsTo(other
: AccountHash): bool
Defined in key.ts:39
Checks whether two AccountHash
s are not equal.
Parameters:
Name | Type |
------ | ------ |
other
| AccountHash |
Returns: bool
toBytes
▸ toBytes(): Array‹u8›
Defined in key.ts:56
Serializes a AccountHash
into an array of bytes.
Returns: Array‹u8›
Static
fromBytes
▸ fromBytes(bytes
: Uint8Array): Result‹AccountHash›
Defined in key.ts:44
Deserializes a AccountHash
from an array of bytes.
Parameters:
Name | Type |
------ | ------ |
bytes
| Uint8Array |
Returns: Result‹AccountHash›
Class: Key
The type under which data (e.g. CLValues, smart contracts, user accounts) are indexed on the network.
Hierarchy
- Key
Index
Properties
Methods
Properties
account
• account: AccountHash | null
Defined in key.ts:69
hash
• hash: Uint8Array | null
Defined in key.ts:67
uref
• uref: URef | null
Defined in key.ts:68
variant
• variant: KeyVariant
Defined in key.ts:66
Methods
add
▸ add(value
: CLValue): void
Defined in key.ts:225
Adds the given CLValue
to a value already stored under this Key
.
Parameters:
Name | Type |
------ | ------ |
value
| CLValue |
Returns: void
equalsTo
▸ equalsTo(other
: Key): bool
Defined in key.ts:239
Checks whether two Key
s are equal.
Parameters:
Name | Type |
------ | ------ |
other
| Key |
Returns: bool
isURef
▸ isURef(): bool
Defined in key.ts:186
Checks whether the Key
is of KeyVariant.UREF_ID.
Returns: bool
notEqualsTo
▸ notEqualsTo(other
: Key): bool
Defined in key.ts:272
Checks whether two keys are not equal.
Parameters:
Name | Type |
------ | ------ |
other
| Key |
Returns: bool
read
▸ read(): Uint8Array | null
Defined in key.ts:196
Reads the data stored under this Key
.
Returns: Uint8Array | null
toBytes
▸ toBytes(): Array‹u8›
Defined in key.ts:158
Serializes a Key
into an array of bytes.
Returns: Array‹u8›
toURef
▸ toURef(): URef
Defined in key.ts:191
Converts the Key
into URef
.
Returns: URef
write
▸ write(value
: CLValue): void
Defined in key.ts:213
Stores a CLValue under this Key
.
Parameters:
Name | Type |
------ | ------ |
value
| CLValue |
Returns: void
Static
create
▸ create(value
: CLValue): Key | null
Defined in key.ts:100
Attempts to write value
under a new Key::URef
If a key is returned it is always of KeyVariant.UREF_ID
Parameters:
Name | Type |
------ | ------ |
value
| CLValue |
Returns: Key | null
Static
fromAccount
▸ fromAccount(account
: AccountHash): Key
Defined in key.ts:88
Creates a Key
from a [[]] representing an account.
Parameters:
Name | Type |
------ | ------ |
account
| AccountHash |
Returns: Key
Static
fromBytes
▸ fromBytes(bytes
: Uint8Array): Result‹Key›
Defined in key.ts:116
Deserializes a Key
from an array of bytes.
Parameters:
Name | Type |
------ | ------ |
bytes
| Uint8Array |
Static
fromHash
▸ fromHash(hash
: Uint8Array): Key
Defined in key.ts:80
Creates a Key
from a given hash.
Parameters:
Name | Type |
------ | ------ |
hash
| Uint8Array |
Returns: Key
Static
fromURef
Defined in key.ts:72
Creates a Key
from a given URef.
Parameters:
Name | Type |
------ | ------ |
uref
| URef |
Returns: Key
Class: Option
A class representing an optional value, i.e. it might contain either a value of some type or
no value at all. Similar to Rust's Option
or Haskell's Maybe
.
Hierarchy
- Option
Index
Constructors
Methods
Constructors
constructor
+ new Option(bytes
: Uint8Array | null): Option
Defined in option.ts:10
Constructs a new option containing the value of bytes
. bytes
can be null
, which
indicates no value.
Parameters:
Name | Type |
------ | ------ |
bytes
| Uint8Array | null |
Returns: Option
Methods
isNone
▸ isNone(): bool
Defined in option.ts:25
Checks whether the Option
contains no value.
Returns: bool
True if the Option
has no value.
isSome
▸ isSome(): bool
Defined in option.ts:34
Checks whether the Option
contains a value.
Returns: bool
True if the Option
has some value.
toBytes
▸ toBytes(): Array‹u8›
Defined in option.ts:50
Serializes the Option
into an array of bytes.
Returns: Array‹u8›
unwrap
▸ unwrap(): Uint8Array | null
Defined in option.ts:43
Unwraps the Option
, returning the inner value (or null
if there was none).
Returns: Uint8Array | null
The inner value, or null
if there was none.
Static
fromBytes
▸ fromBytes(bytes
: Uint8Array): Option
Defined in option.ts:70
Deserializes an array of bytes into an Option
.
Parameters:
Name | Type |
------ | ------ |
bytes
| Uint8Array |
Returns: Option
Class: Pair <T1, T2>
A pair of values.
Type parameters
▪ T1
The type of the first value.
▪ T2
The type of the second value.
Hierarchy
- Pair
Index
Constructors
Properties
Methods
Constructors
constructor
+ new Pair(first
: T1, second
: T2): Pair
Defined in pair.ts:15
Constructs the pair out of the two given values.
Parameters:
Name | Type |
------ | ------ |
first
| T1 |
second
| T2 |
Returns: Pair
Properties
first
• first: T1
Defined in pair.ts:11
The first value in the pair.
second
• second: T2
Defined in pair.ts:15
The second value in the pair.
Methods
equalsTo
▸ equalsTo(other
: Pair‹T1, T2›): bool
Defined in pair.ts:30
Checks whether two pairs are equal. The pairs are considered equal when both their first and second values are equal.
Parameters:
Name | Type |
------ | ------ |
other
| Pair‹T1, T2› |
Returns: bool
notEqualsTo
▸ notEqualsTo(other
: Pair‹T1, T2›): bool
Defined in pair.ts:38
Checks whether two pairs are not equal (the opposite of equalsTo).
Parameters:
Name | Type |
------ | ------ |
other
| Pair‹T1, T2› |
Returns: bool
Class: RuntimeArgs
Implements a collection of runtime arguments.
Hierarchy
- RuntimeArgs
Index
Constructors
Properties
Methods
Constructors
constructor
+ new RuntimeArgs(arguments
: Pair‹String, CLValue›[]): RuntimeArgs
Defined in runtime_args.ts:8
Parameters:
Name | Type | Default |
------ | ------ | ------ |
arguments
| Pair‹String, CLValue›[] | [] |
Returns: RuntimeArgs
Properties
arguments
• arguments: Pair‹String, CLValue›[]
Defined in runtime_args.ts:9
Methods
toBytes
▸ toBytes(): Array‹u8›
Defined in runtime_args.ts:15
Returns: Array‹u8›
Static
fromArray
▸ fromArray(pairs
: Pair‹String, CLValue›[]): RuntimeArgs
Defined in runtime_args.ts:11
Parameters:
Name | Type |
------ | ------ |
pairs
| Pair‹String, CLValue›[] |
Returns: RuntimeArgs
Class: Unit
A class representing the unit type, i.e. a type that has no values (equivalent to eg. void
in
C or ()
in Rust).
Hierarchy
- Unit
Index
Methods
Methods
toBytes
▸ toBytes(): Array‹u8›
Defined in unit.ts:9
Serializes a Unit - returns an empty array.
Returns: Array‹u8›
Static
fromBytes
▸ fromBytes(bytes
: Uint8Array): Unit
Defined in unit.ts:16
Deserializes a Unit - returns a new Unit.
Parameters:
Name | Type |
------ | ------ |
bytes
| Uint8Array |
Returns: Unit
Class: URef
Represents an unforgeable reference, containing an address in the network's global storage and the AccessRights of the reference.
A URef can be used to index entities such as CLValues, or smart contracts.
Hierarchy
- URef
Index
Constructors
Methods
Constructors
constructor
+ new URef(bytes
: Uint8Array, accessRights
: AccessRights): URef
Defined in uref.ts:55
Constructs new instance of URef.
Parameters:
Name | Type | Description |
------ | ------ | ------ |
bytes
| Uint8Array | Bytes representing address of the URef. |
accessRights
| AccessRights | Access rights flag. Use AccessRights.NONE to indicate no permissions. |
Returns: URef
Methods
equalsTo
▸ equalsTo(other
: URef): bool
Defined in uref.ts:129
The equality operator.
Parameters:
Name | Type |
------ | ------ |
other
| URef |
Returns: bool
True if this
and other
are equal, false otherwise.
getAccessRights
▸ getAccessRights(): AccessRights
Defined in uref.ts:79
Returns the access rights of this URef.
Returns: AccessRights
getBytes
▸ getBytes(): Uint8Array
*Defined in