1.4.15-alt • Published 1 year ago

casper-contract v1.4.15-alt

Weekly downloads
-
License
Apache-2.0
Repository
github
Last release
1 year ago

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 assemblyscript@0.9.1
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

Classes

Class: U512

An implementation of 512-bit unsigned integers.

Hierarchy

  • U512

Index

Constructors

Accessors

Methods

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

add(other: U512): U512

Defined in bignum.ts:147

The addition operator - adds two U512 numbers together.

Parameters:

NameType
otherU512

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:

NameTypeDescription
otherU512The 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

div(other: U512): U512

Defined in bignum.ts:340

The division operator - divides the arguments.

Parameters:

NameType
otherU512

Returns: U512


divMod

divMod(other: U512): PairU512, U512› | null

Defined in bignum.ts:299

Performs the integer division of this/other.

Parameters:

NameTypeDescription
otherU512The divisor.

Returns: PairU512, 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:

NameType
otherU512

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:

NameType
otherU512

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:

NameType
otherU512

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:

NameType
otherU512

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:

NameType
otherU512

Returns: bool

True if this is less than or equal to other, false otherwise.


mul

mul(other: U512): U512

Defined in bignum.ts:186

The multiplication operator - calculates the product of the two arguments.

Parameters:

NameType
otherU512

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:

NameType
otherU512

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

rem(other: U512): U512

Defined in bignum.ts:350

The 'modulo' operator - calculates the remainder from the division of the arguments.

Parameters:

NameType
otherU512

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:

NameType
bytesStaticArray‹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:

NameTypeDescription
valueStringThe 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:

NameTypeDescription
valueu64The 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:

NameTypeDescription
pnUint32ArrayThe 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:

NameType
shiftu32

Returns: U512


shr

shr(shift: u32): U512

Defined in bignum.ts:382

The bitwise right-shift operator.

Parameters:

NameType
shiftu32

Returns: U512


sub

sub(other: U512): U512

Defined in bignum.ts:178

The subtraction operator - subtracts the two U512s.

Parameters:

NameType
otherU512

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›): ResultU512

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:

NameType
bytesStaticArray‹u8›

Returns: ResultU512

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:

NameType
hexString

Returns: U512


Static fromU64

fromU64(value: u64): U512

Defined in bignum.ts:71

Converts a 64-bit unsigned integer into a U512.

Parameters:

NameTypeDescription
valueu64The 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:

NameTypeDescription
refRef‹T› | null-
errorErrorError value
positionu32Position 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:

NameTypeDefault
tagCLTypeTag-
extraArray‹u8› | nullnull

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:

NameType
sizeu32

Returns: CLType


Static list

list(typeTag: CLType): CLType

Defined in clvalue.ts:84

Parameters:

NameType
typeTagCLType

Returns: CLType


Static option

option(typeTag: CLType): CLType

Defined in clvalue.ts:88

Parameters:

NameType
typeTagCLType

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:

NameType
bytesu8[]
clTypeCLType

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:

NameType
valuei32

Returns: CLValue


Static fromKey

fromKey(key: Key): CLValue

Defined in clvalue.ts:153

Creates a CLValue holding a Key.

Parameters:

NameType
keyKey

Returns: CLValue


Static fromOption

fromOption(value: Option, nestedT: CLType): CLValue

Defined in clvalue.ts:181

Creates a CLValue holding an Option.

Parameters:

NameType
valueOption
nestedTCLType

Returns: CLValue


Static fromPublicKey

fromPublicKey(publicKey: PublicKey): CLValue

Defined in clvalue.ts:174

Creates a CLValue holding a public key.

Parameters:

NameType
publicKeyPublicKey

Returns: CLValue


Static fromString

fromString(s: String): CLValue

Defined in clvalue.ts:118

Creates a CLValue holding a string.

Parameters:

NameType
sString

Returns: CLValue


Static fromStringList

fromStringList(values: String[]): CLValue

Defined in clvalue.ts:167

Creates a CLValue holding a list of strings.

Parameters:

NameType
valuesString[]

Returns: CLValue


Static fromU512

fromU512(value: U512): CLValue

Defined in clvalue.ts:125

Creates a CLValue holding an unsigned 512-bit integer.

Parameters:

NameType
valueU512

Returns: CLValue


Static fromU64

fromU64(value: u64): CLValue

Defined in clvalue.ts:146

Creates a CLValue holding an unsigned 64-bit integer.

Parameters:

NameType
valueu64

Returns: CLValue


Static fromU8

fromU8(value: u8): CLValue

Defined in clvalue.ts:132

Creates a CLValue holding an unsigned 64-bit integer.

Parameters:

NameType
valueu8

Returns: CLValue


Static fromURef

fromURef(uref: URef): CLValue

Defined in clvalue.ts:160

Creates a CLValue holding a URef.

Parameters:

NameType
urefURef

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 rangeVariant(s)
1, 65023all except Mint, HandlePayment and User. Can be created with Error.fromErrorCode
65024, 65279Mint - instantiation currently unsupported
65280, 65535HandlePayment errors
65536, 131071User 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:

Parameters:

NameTypeDescription
valueu32Error 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:

NameTypeDescription
errorCodeErrorCodeVariant 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:

NameTypeDescription
resultu32A 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:

NameTypeDescription
userErrorCodeValueu16

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:

NameType
contractHashStaticArray‹u8›
contractVersionu32

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:

NameType
packageHashStaticArray‹u8›
accessURefURef

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:

NameType
nameString
argsArray‹Pair‹String, CLType››
retCLType
accessEntryPointAccess
entry_point_typeEntryPointType

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

Index

Constructors

Properties

Methods

Constructors

constructor

+ new EntryPointAccess(cachedBytes: Array‹u8›): EntryPointAccess

Defined in index.ts:418

Parameters:

NameType
cachedBytesArray‹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:

NameType
entryPointEntryPoint

Returns: void


toBytes

toBytes(): Array‹u8›

Defined in index.ts:468

Returns: Array‹u8›

Class: GroupAccess

Hierarchy

Index

Constructors

Properties

Methods

Constructors

constructor

+ new GroupAccess(groups: String[]): GroupAccess

Overrides EntryPointAccess.constructor

Defined in index.ts:431

Parameters:

NameType
groupsString[]

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

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:

NameTypeDescription
bytesArray‹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 AccountHashs are equal.

Parameters:

NameType
otherAccountHash

Returns: bool


notEqualsTo

notEqualsTo(other: AccountHash): bool

Defined in key.ts:43

Checks whether two AccountHashs are not equal.

Parameters:

NameType
otherAccountHash

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›): ResultAccountHash

Defined in key.ts:70

Deserializes a AccountHash from an array of bytes.

Parameters:

NameType
bytesArray‹u8›

Returns: ResultAccountHash


Static fromPublicKey

fromPublicKey(publicKey: PublicKey): AccountHash

Defined in key.ts:47

Parameters:

NameType
publicKeyPublicKey

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:

NameType
valueCLValue

Returns: void


equalsTo

equalsTo(other: Key): bool

Defined in key.ts:264

Checks whether two Keys are equal.

Parameters:

NameType
otherKey

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:

NameType
otherKey

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:

NameType
valueCLValue

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:

NameType
valueCLValue

Returns: Key | null


Static fromAccount

fromAccount(account: AccountHash): Key

Defined in key.ts:114

Creates a Key from a [] representing an account.

Parameters:

NameType
accountAccountHash

Returns: Key


Static fromBytes

fromBytes(bytes: StaticArray‹u8›): ResultKey

Defined in key.ts:142

Deserializes a Key from an array of bytes.

Parameters:

NameType
bytesStaticArray‹u8›

Returns: ResultKey


Static fromHash

fromHash(hash: StaticArray‹u8›): Key

Defined in key.ts:106

Creates a Key from a given hash.

Parameters:

NameType
hashStaticArray‹u8›

Returns: Key


Static fromURef

fromURef(uref: URef): Key

Defined in key.ts:98

Creates a Key from a given URef.

Parameters:

NameType
urefURef

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:

NameType
bytesArray‹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:

NameType
bytesStaticArray‹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:

NameType
firstT1
secondT2

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:

NameType
otherPair‹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:

NameType
otherPair‹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:

NameType
variantPublicKeyVariant
bytesArray‹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›): ResultPublicKey

Defined in public_key.ts:43

Deserializes a PublicKey from an array of bytes.

Parameters:

NameType
bytesStaticArray‹u8›

Returns: ResultPublicKey

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: RefTransferredTo› | 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

1.4.15

1 year ago

1.4.14

1 year ago

1.4.15-alt

1 year ago

1.4.13

1 year ago

1.4.8

2 years ago

1.4.6

2 years ago

1.4.5

2 years ago

1.4.3

2 years ago

1.4.2

2 years ago

1.3.4

3 years ago

1.4.1

3 years ago

1.4.0

3 years ago

1.3.2

3 years ago

1.3.1

3 years ago

1.3.0

3 years ago

1.2.1

3 years ago

1.2.0

3 years ago

1.1.1

3 years ago

1.1.0

3 years ago

1.0.1

3 years ago

1.0.0

3 years ago

0.9.4

3 years ago

0.9.3

3 years ago

0.9.0

3 years ago