casper-contract
v1.4.15-alt
Published
Library for developing Casper smart contracts.
Downloads
30
Readme
casper-contract
This package allows a distributed app developer to create smart contracts for the open source Casper 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 casper-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 --optimizeLevel 3 --converge --noAssert --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 Casper platform.
//@ts-nocheck
import {Error, ErrorCode} from "casper-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 casper-node 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
casper-contract
Index
Modules
- "account"
- "bignum"
- "bytesrepr"
- "clvalue"
- "constants"
- "dictionary"
- "error"
- "externals"
- "index"
- "key"
- "option"
- "pair"
- "public_key"
- "purse"
- "ref"
- "runtime"
- "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:32
Constructs a new instance of U512.
Returns: U512
Accessors
width
• get width(): i32
Defined in bignum.ts:80
Gets the width of the number in bytes.
Returns: i32
Static
MAX_VALUE
• get MAX_VALUE(): U512
Defined in bignum.ts:44
Returns: U512
The maximum possible value of a U512.
Static
MIN_VALUE
• get MIN_VALUE(): U512
Defined in bignum.ts:53
Returns: U512
The minimum possible value of a U512 (which is 0).
Methods
add
Defined in bignum.ts:147
The addition operator - adds two U512 numbers together.
Parameters:
Name | Type |
------ | ------ |
other
| U512 |
Returns: U512
bits
▸ bits(): u32
Defined in bignum.ts:283
Returns length of the integer in bits (not counting the leading zero bits).
Returns: u32
clone
▸ clone(): U512
Defined in bignum.ts:274
Clones the U512.
Returns: U512
cmp
▸ cmp(other
: U512): i32
Defined in bignum.ts:407
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:340
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:299
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:426
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:446
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:466
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:134
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:456
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:476
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:186
The multiplication operator - calculates the product of the two arguments.
Parameters:
Name | Type |
------ | ------ |
other
| U512 |
Returns: U512
neg
▸ neg(): U512
Defined in bignum.ts:165
The negation operator - returns the two's complement of the argument.
Returns: U512
neq
▸ neq(other
: U512): bool
Defined in bignum.ts:436
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:254
Postfix operator --
- decrements this U512.
Returns: U512
postfixInc
▸ postfixInc(): U512
Defined in bignum.ts:244
Postfix operator ++
- increments this U512.
Returns: U512
prefixDec
▸ prefixDec(): U512
Defined in bignum.ts:235
Prefix operator --
- decrements this U512.
Returns: U512
prefixInc
▸ prefixInc(): U512
Defined in bignum.ts:226
Prefix operator ++
- increments this U512.
Returns: U512
rem
Defined in bignum.ts:350
The 'modulo' operator - calculates the remainder from the division of the arguments.
Parameters:
Name | Type |
------ | ------ |
other
| U512 |
Returns: U512
setBytesLE
▸ setBytesLE(bytes
: StaticArray‹u8›): void
Defined in bignum.ts:497
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
| StaticArray‹u8› |
Returns: void
setHex
▸ setHex(value
: String): void
Defined in bignum.ts:101
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:89
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:265
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:360
The bitwise left-shift operator.
Parameters:
Name | Type |
------ | ------ |
shift
| u32 |
Returns: U512
shr
▸ shr(shift
: u32): U512
Defined in bignum.ts:382
The bitwise right-shift operator.
Parameters:
Name | Type |
------ | ------ |
shift
| u32 |
Returns: U512
sub
Defined in bignum.ts:178
The subtraction operator - subtracts the two U512s.
Parameters:
Name | Type |
------ | ------ |
other
| U512 |
Returns: U512
toBytes
▸ toBytes(): Array‹u8›
Defined in bignum.ts:580
Serializes the U512 into an array of bytes that represents it in the Casper serialization format.
Returns: Array‹u8›
toBytesLE
▸ toBytesLE(): Uint8Array
Defined in bignum.ts:484
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:541
An alias for [[toHex]].
Returns: String
Static
fromBytes
▸ fromBytes(bytes
: StaticArray‹u8›): Result‹U512›
Defined in bignum.ts:552
Deserializes a U512 from an array of bytes. The array should represent a correct U512 in the Casper serialization format.
Parameters:
Name | Type |
------ | ------ |
bytes
| StaticArray‹u8› |
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:60
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:71
Converts a 64-bit unsigned integer into a U512.
Parameters:
Name | Type | Description |
------ | ------ | ------ |
value
| u64 | The value to be converted. |
Returns: U512
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:46
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:53
Error value
position
• position: u32
Defined in bytesrepr.ts:53
Position of input stream
ref
• ref: Ref‹T› | null
Defined in bytesrepr.ts:53
Accessors
value
• get value(): T
Defined in bytesrepr.ts:58
Assumes that reference wrapper contains a value and then returns it
Returns: T
Methods
hasError
▸ hasError(): bool
Defined in bytesrepr.ts:76
Checks if error value is set.
Truth also implies !hasValue(), false value implies hasValue()
Returns: bool
hasValue
▸ hasValue(): bool
Defined in bytesrepr.ts:67
Checks if given Result contains a value
Returns: bool
ok
▸ ok(): T | null
Defined in bytesrepr.ts:83
For nullable types, this returns the value itself, or a null.
Returns: T | null
unwrap
▸ unwrap(): T
Defined in bytesrepr.ts:90
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:66
Parameters:
Name | Type | Default |
------ | ------ | ------ |
tag
| CLTypeTag | - |
extra
| Array‹u8› | null | null |
Returns: CLType
Properties
bytes
• bytes: Array‹u8›
Defined in clvalue.ts:66
tag
• tag: CLTypeTag
Defined in clvalue.ts:65
Methods
toBytes
▸ toBytes(): u8[]
Defined in clvalue.ts:92
Returns: u8[]
Static
byteArray
▸ byteArray(size
: u32): CLType
Defined in clvalue.ts:76
Parameters:
Name | Type |
------ | ------ |
size
| u32 |
Returns: CLType
Static
list
▸ list(typeTag
: CLType): CLType
Defined in clvalue.ts:84
Parameters:
Name | Type |
------ | ------ |
typeTag
| CLType |
Returns: CLType
Static
option
▸ option(typeTag
: CLType): CLType
Defined in clvalue.ts:88
Parameters:
Name | Type |
------ | ------ |
typeTag
| CLType |
Returns: CLType
Class: CLValue
A Casper 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:105
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:104
clType
• clType: CLType
Defined in clvalue.ts:105
Methods
toBytes
▸ toBytes(): u8[]
Defined in clvalue.ts:188
Serializes a CLValue
into an array of bytes.
Returns: u8[]
Static
fromI32
▸ fromI32(value
: i32): CLValue
Defined in clvalue.ts:139
Creates a CLValue
holding a signed 32-bit integer.
Parameters:
Name | Type |
------ | ------ |
value
| i32 |
Returns: CLValue
Static
fromKey
Defined in clvalue.ts:153
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:181
Creates a CLValue
holding an Option.
Parameters:
Name | Type |
------ | ------ |
value
| Option |
nestedT
| CLType |
Returns: CLValue
Static
fromPublicKey
▸ fromPublicKey(publicKey
: PublicKey): CLValue
Defined in clvalue.ts:174
Creates a CLValue
holding a public key.
Parameters:
Name | Type |
------ | ------ |
publicKey
| PublicKey |
Returns: CLValue
Static
fromString
▸ fromString(s
: String): CLValue
Defined in clvalue.ts:118
Creates a CLValue
holding a string.
Parameters:
Name | Type |
------ | ------ |
s
| String |
Returns: CLValue
Static
fromStringList
▸ fromStringList(values
: String[]): CLValue
Defined in clvalue.ts:167
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:125
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:146
Creates a CLValue
holding an unsigned 64-bit integer.
Parameters:
Name | Type |
------ | ------ |
value
| u64 |
Returns: CLValue
Static
fromU8
▸ fromU8(value
: u8): CLValue
Defined in clvalue.ts:132
Creates a CLValue
holding an unsigned 64-bit integer.
Parameters:
Name | Type |
------ | ------ |
value
| u8 |
Returns: CLValue
Static
fromURef
▸ fromURef(uref
: URef): CLValue
Defined in clvalue.ts:160
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
, HandlePayment
and User
. Can be created with Error.fromErrorCode |
| [65024, 65279] | Mint
- instantiation currently unsupported |
| [65280, 65535] | HandlePayment
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
: StaticArray‹u8›, contractVersion
: u32): AddContractVersionResult
Defined in index.ts:573
Parameters:
Name | Type |
------ | ------ |
contractHash
| StaticArray‹u8› |
contractVersion
| u32 |
Returns: AddContractVersionResult
Properties
contractHash
• contractHash: StaticArray‹u8›
Defined in index.ts:574
contractVersion
• contractVersion: u32
Defined in index.ts:574
Class: CreateContractPackageResult
A two-value structure that holds the result of createContractPackageAtHash.
Hierarchy
- CreateContractPackageResult
Index
Constructors
Properties
Constructors
constructor
+ new CreateContractPackageResult(packageHash
: StaticArray‹u8›, accessURef
: URef): CreateContractPackageResult
Defined in index.ts:477
Parameters:
Name | Type |
------ | ------ |
packageHash
| StaticArray‹u8› |
accessURef
| URef |
Returns: CreateContractPackageResult
Properties
accessURef
• accessURef: URef
Defined in index.ts:478
packageHash
• packageHash: StaticArray‹u8›
Defined in index.ts:478
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:445
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:449
args
• args: Array‹Pair‹String, CLType››
Defined in index.ts:447
entry_point_type
• entry_point_type: EntryPointType
Defined in index.ts:450
name
• name: String
Defined in index.ts:446
ret
• ret: CLType
Defined in index.ts:448
Methods
toBytes
▸ toBytes(): Array‹u8›
Defined in index.ts:452
Returns: Array‹u8›
Class: EntryPointAccess
Hierarchy
EntryPointAccess
Index
Constructors
Properties
Methods
Constructors
constructor
+ new EntryPointAccess(cachedBytes
: Array‹u8›): EntryPointAccess
Defined in index.ts:418
Parameters:
Name | Type |
------ | ------ |
cachedBytes
| Array‹u8› |
Returns: EntryPointAccess
Properties
cachedBytes
• cachedBytes: Array‹u8›
Defined in index.ts:419
Methods
toBytes
▸ toBytes(): Array‹u8›
Defined in index.ts:420
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:464
Methods
addEntryPoint
▸ addEntryPoint(entryPoint
: EntryPoint): void
Defined in index.ts:465
Parameters:
Name | Type |
------ | ------ |
entryPoint
| EntryPoint |
Returns: void
toBytes
▸ toBytes(): Array‹u8›
Defined in index.ts:468
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:431
Parameters:
Name | Type |
------ | ------ |
groups
| String[] |
Returns: GroupAccess
Properties
cachedBytes
• cachedBytes: Array‹u8›
Inherited from EntryPointAccess.cachedBytes
Defined in index.ts:419
Methods
toBytes
▸ toBytes(): Array‹u8›
Inherited from EntryPointAccess.toBytes
Defined in index.ts:420
Returns: Array‹u8›
Class: PublicAccess
Hierarchy
↳ PublicAccess
Index
Constructors
Properties
Methods
Constructors
constructor
+ new PublicAccess(): PublicAccess
Overrides EntryPointAccess.constructor
Defined in index.ts:425
Returns: PublicAccess
Properties
cachedBytes
• cachedBytes: Array‹u8›
Inherited from EntryPointAccess.cachedBytes
Defined in index.ts:419
Methods
toBytes
▸ toBytes(): Array‹u8›
Inherited from EntryPointAccess.toBytes
Defined in index.ts:420
Returns: Array‹u8›
Class: AccountHash
A cryptographic public key.
Hierarchy
- AccountHash
Index
Constructors
Properties
Methods
Constructors
constructor
+ new AccountHash(bytes
: Array‹u8›): AccountHash
Defined in key.ts:27
Constructs a new AccountHash
.
Parameters:
Name | Type | Description |
------ | ------ | ------ |
bytes
| Array‹u8› | The bytes constituting the public key. |
Returns: AccountHash
Properties
bytes
• bytes: Array‹u8›
Defined in key.ts:33
The bytes constituting the public key.
Methods
equalsTo
▸ equalsTo(other
: AccountHash): bool
Defined in key.ts:37
Checks whether two AccountHash
s are equal.
Parameters:
Name | Type |
------ | ------ |
other
| AccountHash |
Returns: bool
notEqualsTo
▸ notEqualsTo(other
: AccountHash): bool
Defined in key.ts:43
Checks whether two AccountHash
s are not equal.
Parameters:
Name | Type |
------ | ------ |
other
| AccountHash |
Returns: bool
toBytes
▸ toBytes(): Array‹u8›
Defined in key.ts:82
Serializes a AccountHash
into an array of bytes.
Returns: Array‹u8›
Static
fromBytes
▸ fromBytes(bytes
: Array‹u8›): Result‹AccountHash›
Defined in key.ts:70
Deserializes a AccountHash
from an array of bytes.
Parameters:
Name | Type |
------ | ------ |
bytes
| Array‹u8› |
Returns: Result‹AccountHash›
Static
fromPublicKey
▸ fromPublicKey(publicKey
: PublicKey): AccountHash
Defined in key.ts:47
Parameters:
Name | Type |
------ | ------ |
publicKey
| PublicKey |
Returns: 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:95
hash
• hash: StaticArray‹u8› | null
Defined in key.ts:93
uref
• uref: URef | null
Defined in key.ts:94
variant
• variant: KeyVariant
Defined in key.ts:92
Methods
add
▸ add(value
: CLValue): void
Defined in key.ts:250
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:264
Checks whether two Key
s are equal.
Parameters:
Name | Type |
------ | ------ |
other
| Key |
Returns: bool
isURef
▸ isURef(): bool
Defined in key.ts:211
Checks whether the Key
is of KeyVariant.UREF_ID.
Returns: bool
notEqualsTo
▸ notEqualsTo(other
: Key): bool
Defined in key.ts:296
Checks whether two keys are not equal.
Parameters:
Name | Type |
------ | ------ |
other
| Key |
Returns: bool
read
▸ read(): StaticArray‹u8› | null
Defined in key.ts:221
Reads the data stored under this Key
.
Returns: StaticArray‹u8› | null
toBytes
▸ toBytes(): Array‹u8›
Defined in key.ts:184
Serializes a Key
into an array of bytes.
Returns: Array‹u8›
toURef
▸ toURef(): URef
Defined in key.ts:216
Converts the Key
into URef
.
Returns: URef
write
▸ write(value
: CLValue): void
Defined in key.ts:238
Stores a CLValue under this Key
.
Parameters:
Name | Type |
------ | ------ |
value
| CLValue |
Returns: void
Static
create
▸ create(value
: CLValue): Key | null
Defined in key.ts:126
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:114
Creates a Key
from a [[]] representing an account.
Parameters:
Name | Type |
------ | ------ |
account
| AccountHash |
Returns: Key
Static
fromBytes
▸ fromBytes(bytes
: StaticArray‹u8›): Result‹Key›
Defined in key.ts:142
Deserializes a Key
from an array of bytes.
Parameters:
Name | Type |
------ | ------ |
bytes
| StaticArray‹u8› |
Static
fromHash
▸ fromHash(hash
: StaticArray‹u8›): Key
Defined in key.ts:106
Creates a Key
from a given hash.
Parameters:
Name | Type |
------ | ------ |
hash
| StaticArray‹u8› |
Returns: Key
Static
fromURef
Defined in key.ts:98
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
: Array‹u8› | 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
| Array‹u8› | 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:51
Serializes the Option
into an array of bytes.
Returns: Array‹u8›
unwrap
▸ unwrap(): Array‹u8›
Defined in option.ts:43
Unwraps the Option
, returning the inner value (or null
if there was none).
Returns: Array‹u8›
The inner value, or null
if there was none.
Static
fromBytes
▸ fromBytes(bytes
: StaticArray‹u8›): Option
Defined in option.ts:71
Deserializes an array of bytes into an Option
.
Parameters:
Name | Type |
------ | ------ |
bytes
| StaticArray‹u8› |
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: PublicKey
Hierarchy
- PublicKey
Index
Constructors
Methods
Constructors
constructor
+ new PublicKey(variant
: PublicKeyVariant, bytes
: Array‹u8›): PublicKey
Defined in public_key.ts:15
Parameters:
Name | Type |
------ | ------ |
variant
| PublicKeyVariant |
bytes
| Array‹u8› |
Returns: PublicKey
Methods
getAlgorithmName
▸ getAlgorithmName(): string
Defined in public_key.ts:23
Returns: string
getRawBytes
▸ getRawBytes(): Array‹u8›
Defined in public_key.ts:19
Returns: Array‹u8›
toBytes
▸ toBytes(): Array‹u8›
Defined in public_key.ts:37
Returns: Array‹u8›
Static
fromBytes
▸ fromBytes(bytes
: StaticArray‹u8›): Result‹PublicKey›
Defined in public_key.ts:43
Deserializes a PublicKey
from an array of bytes.
Parameters:
Name | Type |
------ | ------ |
bytes
| StaticArray‹u8› |
Class: TransferResult
The result of a transfer between purse and account.
Hierarchy
- TransferResult
Index
Properties
Accessors
Methods
Properties
errValue
• errValue: Error | null = null
Defined in purse.ts:33
okValue
• okValue: Ref‹TransferredTo› | null = null
Defined in purse.ts:34
Accessors
err
• get err(): Error
Defined in purse.ts:62
Returns: Error
isErr
• get isErr(): bool
Defined in purse.ts:48
Returns: bool
isOk
• get isOk(): bool
Defined in purse.ts:52
Returns: bool
ok
• get ok(): TransferredTo
Defined in purse.ts:56