Socket
Book a DemoInstallSign in
Socket

@casperlabs/contract

Package Overview
Dependencies
Maintainers
2
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@casperlabs/contract

Library for developing CasperLabs smart contracts.

npmnpm
Version
0.4.1
Version published
Weekly downloads
0
Maintainers
2
Weekly downloads
 
Created
Source

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

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

add(other: U512): U512

Defined in bignum.ts:146

The addition operator - adds two U512 numbers together.

Parameters:

NameType
otherU512

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:

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:339

The division operator - divides the arguments.

Parameters:

NameType
otherU512

Returns: U512

divMod

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

Defined in bignum.ts:298

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:425

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:445

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:465

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

NameType
otherU512

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:

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:185

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

Parameters:

NameType
otherU512

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:

NameType
otherU512

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

rem(other: U512): U512

Defined in bignum.ts:349

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

Parameters:

NameType
otherU512

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:

NameType
bytesUint8Array

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:

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

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

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:359

The bitwise left-shift operator.

Parameters:

NameType
shiftu32

Returns: U512

shr

shr(shift: u32): U512

Defined in bignum.ts:381

The bitwise right-shift operator.

Parameters:

NameType
shiftu32

Returns: U512

sub

sub(other: U512): U512

Defined in bignum.ts:177

The subtraction operator - subtracts the two U512s.

Parameters:

NameType
otherU512

Returns: U512

toBytes

toBytes(): Array‹u8›

Defined in bignum.ts:573

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

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:

NameType
bytesUint8Array

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:59

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:70

Converts a 64-bit unsigned integer into a U512.

Parameters:

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

NameType
valueT

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: usize): Result

Defined in bytesrepr.ts:53

Creates new Result with wrapped value

Parameters:

NameTypeDescription
refRef‹T› | null-
errorErrorError value
positionusizePosition of input stream

Returns: Result

Properties

error

error: Error

Defined in bytesrepr.ts:60

Error value

position

position: usize

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: 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[], tag: u8[]): CLValue

Defined in clvalue.ts:69

Constructs a new CLValue with given underlying data and type tag.

Parameters:

NameType
bytesu8[]
tagu8[]

Returns: CLValue

Properties

bytes

bytes: u8[]

Defined in clvalue.ts:68

tag

tag: u8[]

Defined in clvalue.ts:69

Methods

toBytes

toBytes(): u8[]

Defined in clvalue.ts:144

Serializes a CLValue into an array of bytes.

Returns: u8[]

Static fromI32

fromI32(value: i32): CLValue

Defined in clvalue.ts:96

Creates a CLValue holding a signed 32-bit integer.

Parameters:

NameType
valuei32

Returns: CLValue

Static fromKey

fromKey(key: Key): CLValue

Defined in clvalue.ts:110

Creates a CLValue holding a Key.

Parameters:

NameType
keyKey

Returns: CLValue

Static fromOption

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

Defined in clvalue.ts:134

Creates a CLValue holding an Option.

Parameters:

NameType
valueOption
nestedTCLTypeTag

Returns: CLValue

Static fromString

fromString(s: String): CLValue

Defined in clvalue.ts:82

Creates a CLValue holding a string.

Parameters:

NameType
sString

Returns: CLValue

Static fromStringList

fromStringList(values: String[]): CLValue

Defined in clvalue.ts:124

Creates a CLValue holding a list of strings.

Parameters:

NameType
valuesString[]

Returns: CLValue

Static fromU512

fromU512(value: U512): CLValue

Defined in clvalue.ts:89

Creates a CLValue holding an unsigned 512-bit integer.

Parameters:

NameType
valueU512

Returns: CLValue

Static fromU64

fromU64(value: u64): CLValue

Defined in clvalue.ts:103

Creates a CLValue holding an unsigned 64-bit integer.

Parameters:

NameType
valueu64

Returns: CLValue

Static fromURef

fromURef(uref: URef): CLValue

Defined in clvalue.ts:117

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

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: 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: PublicKey | null

Defined in key.ts:75

hash

hash: Uint8Array | null

Defined in key.ts:73

uref

uref: URef | null

Defined in key.ts:74

variant

variant: KeyVariant

Defined in key.ts:72

Methods

add

add(value: CLValue): void

Defined in key.ts:231

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:245

Checks whether two Keys are equal.

Parameters:

NameType
otherKey

Returns: bool

isURef

isURef(): bool

Defined in key.ts:192

Checks whether the Key is of KeyVariant.UREF_ID.

Returns: bool

notEqualsTo

notEqualsTo(other: Key): bool

Defined in key.ts:278

Checks whether two keys are not equal.

Parameters:

NameType
otherKey

Returns: bool

read

read(): Uint8Array | null

Defined in key.ts:202

Reads the data stored under this Key.

Returns: Uint8Array | null

toBytes

toBytes(): Array‹u8›

Defined in key.ts:164

Serializes a Key into an array of bytes.

Returns: Array‹u8›

toURef

toURef(): URef

Defined in key.ts:197

Converts the Key into URef.

Returns: URef

write

write(value: CLValue): void

Defined in key.ts:219

Stores a CLValue under this Key.

Parameters:

NameType
valueCLValue

Returns: void

Static create

create(value: CLValue): Key | null

Defined in key.ts:106

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: PublicKey): Key

Defined in key.ts:94

Creates a Key from a PublicKey representing an account.

Parameters:

NameType
accountPublicKey

Returns: Key

Static fromBytes

fromBytes(bytes: Uint8Array): ResultKey

Defined in key.ts:122

Deserializes a Key from an array of bytes.

Parameters:

NameType
bytesUint8Array

Returns: ResultKey

Static fromHash

fromHash(hash: Uint8Array): Key

Defined in key.ts:86

Creates a Key from a given hash.

Parameters:

NameType
hashUint8Array

Returns: Key

Static fromURef

fromURef(uref: URef): Key

Defined in key.ts:78

Creates a Key from a given URef.

Parameters:

NameType
urefURef

Returns: Key

Class: PublicKey

A cryptographic public key.

Hierarchy

  • PublicKey

Index

Constructors

Properties

Methods

Constructors

constructor

+ new PublicKey(variant: u8, bytes: Uint8Array): PublicKey

Defined in key.ts:28

Constructs a new PublicKey.

Parameters:

NameTypeDescription
variantu8An ID of the used key variant.
bytesUint8ArrayThe bytes constituting the public key.

Returns: PublicKey

Properties

bytes

bytes: Uint8Array

Defined in key.ts:35

The bytes constituting the public key.

variant

variant: u8

Defined in key.ts:35

An ID of the used key variant.

Methods

equalsTo

equalsTo(other: PublicKey): bool

Defined in key.ts:39

Checks whether two PublicKeys are equal.

Parameters:

NameType
otherPublicKey

Returns: bool

notEqualsTo

notEqualsTo(other: PublicKey): bool

Defined in key.ts:45

Checks whether two PublicKeys are not equal.

Parameters:

NameType
otherPublicKey

Returns: bool

toBytes

toBytes(): Array‹u8›

Defined in key.ts:62

Serializes a PublicKey into an array of bytes.

Returns: Array‹u8›

Static fromBytes

fromBytes(bytes: Uint8Array): ResultPublicKey

Defined in key.ts:50

Deserializes a PublicKey from an array of bytes.

Parameters:

NameType
bytesUint8Array

Returns: ResultPublicKey

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:

NameType
bytesUint8Array | 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:

NameType
bytesUint8Array

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

NameType
bytesUint8Array

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:

NameTypeDescription
bytesUint8ArrayBytes representing address of the URef.
accessRightsAccessRightsAccess rights flag. Use AccessRights.NONE to indicate no permissions.

Returns: URef

Methods

equalsTo

equalsTo(other: URef): bool

Defined in uref.ts:133

The equality operator.

Parameters:

NameType
otherURef

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 uref.ts:72

Returns the address of this URef as an array of bytes.

Returns: Uint8Array

A byte array with a length of 32.

isValid

isValid(): boolean

Defined in uref.ts:86

Validates uref against named keys.

Returns: boolean

notEqualsTo

notEqualsTo(other: URef): bool

Defined in uref.ts:143

The not-equal operator.

Parameters:

NameType
otherURef

Returns: bool

False if this and other are equal, true otherwise.

toBytes

toBytes(): Array‹u8›

Defined in uref.ts:117

Serializes the URef into an array of bytes that represents it in the CasperLabs serialization format.

Returns: Array‹u8›

Static fromBytes

fromBytes(bytes: Uint8Array): ResultURef

Defined in uref.ts:99

Deserializes a new URef from bytes.

Parameters:

NameTypeDescription
bytesUint8ArrayInput bytes. Requires at least 33 bytes to properly deserialize an URef.

Returns: ResultURef

Enums

Enumeration: ActionType

Enum representing an action for which a threshold is being set.

Index

Enumeration members

Enumeration members

Deployment

Deployment: = 0

Defined in account.ts:106

Required by deploy execution.

KeyManagement

KeyManagement: = 1

Defined in account.ts:110

Required when adding/removing associated keys, changing threshold levels.

Enumeration: AddKeyFailure

Enum representing the possible results of adding an associated key to an account.

Index

Enumeration members

Enumeration members

DuplicateKey

DuplicateKey: = 2

Defined in account.ts:22

Unable to add new associated key because given key already exists

MaxKeysLimit

MaxKeysLimit: = 1

Defined in account.ts:18

Unable to add new associated key because maximum amount of keys is reached

Ok

Ok: = 0

Defined in account.ts:14

Success

PermissionDenied

PermissionDenied: = 3

Defined in account.ts:26

Unable to add new associated key due to insufficient permissions

Enumeration: RemoveKeyFailure

Enum representing the possible results of removing an associated key from an account.

Index

Enumeration members

Enumeration members

MissingKey

MissingKey: = 1

Defined in account.ts:62

Key does not exist in the list of associated keys.

Ok

Ok: = 0

Defined in account.ts:58

Success

PermissionDenied

PermissionDenied: = 2

Defined in account.ts:66

Unable to remove the associated key due to insufficient permissions

ThresholdViolation

ThresholdViolation: = 3

Defined in account.ts:70

Unable to remove a key which would violate action threshold constraints

Enumeration: SetThresholdFailure

Enum representing the possible results of setting the threshold of an account.

Index

Enumeration members

Enumeration members

DeploymentThreshold

DeploymentThreshold: = 2

Defined in account.ts:88

New threshold should be lower or equal than key management threshold

InsufficientTotalWeight

InsufficientTotalWeight: = 4

Defined in account.ts:96

New threshold should be lower or equal than total weight of associated keys

KeyManagementThreshold

KeyManagementThreshold: = 1

Defined in account.ts:84

New threshold should be lower or equal than deployment threshold

Ok

Ok: = 0

Defined in account.ts:80

Success

PermissionDeniedError

PermissionDeniedError: = 3

Defined in account.ts:92

Unable to set action threshold due to insufficient permissions

Enumeration: UpdateKeyFailure

Enum representing the possible results of updating an associated key of an account.

Index

Enumeration members

Enumeration members

MissingKey

MissingKey: = 1

Defined in account.ts:40

Key does not exist in the list of associated keys.

Ok

Ok: = 0

Defined in account.ts:36

Success

PermissionDenied

PermissionDenied: = 2

Defined in account.ts:44

Unable to update the associated key due to insufficient permissions

ThresholdViolation

ThresholdViolation: = 3

Defined in account.ts:48

Unable to update weight that would fall below any of action thresholds

Enumeration: Error

Enum representing possible results of deserialization.

Index

Enumeration members

Enumeration members

EarlyEndOfStream

EarlyEndOfStream: = 1

Defined in bytesrepr.ts:24

Early end of stream

FormattingError

FormattingError: = 2

Defined in bytesrepr.ts:28

Unexpected data encountered while decoding byte stream

Ok

Ok: = 0

Defined in bytesrepr.ts:20

Last operation was a success

Enumeration: CLTypeTag

CasperLabs types, i.e. types which can be stored and manipulated by smart contracts.

Provides a description of the underlying data type of a CLValue.

Index

Enumeration members

Enumeration members

Any

Any: = 21

Defined in clvalue.ts:58

A value of any type.

Bool

Bool: = 0

Defined in clvalue.ts:14

A boolean value

Fixed_list

Fixed_list: = 15

Defined in clvalue.ts:44

A fixed-length list of values

I32

I32: = 1

Defined in clvalue.ts:16

A 32-bit signed integer

I64

I64: = 2

Defined in clvalue.ts:18

A 64-bit signed integer

Key

Key: = 11

Defined in clvalue.ts:36

A key in the global state - URef/hash/etc.

List

List: = 14

Defined in clvalue.ts:42

A list of values

Map

Map: = 17

Defined in clvalue.ts:50

A key-value map.

Option

Option: = 13

Defined in clvalue.ts:40

An Option, i.e. a type that can contain a value or nothing at all

Result

Result: = 16

Defined in clvalue.ts:48

A Result, i.e. a type that can contain either a value representing success or one representing failure.

String

String: = 10

Defined in clvalue.ts:34

A string of characters

Tuple1

Tuple1: = 18

Defined in clvalue.ts:52

A 1-value tuple.

Tuple2

Tuple2: = 19

Defined in clvalue.ts:54

A 2-value tuple, i.e. a pair of values.

Tuple3

Tuple3: = 20

Defined in clvalue.ts:56

A 3-value tuple.

U128

U128: = 6

Defined in clvalue.ts:26

A 128-bit unsigned integer

U256

U256: = 7

Defined in clvalue.ts:28

A 256-bit unsigned integer

U32

U32: = 4

Defined in clvalue.ts:22

A 32-bit unsigned integer

U512

U512: = 8

Defined in clvalue.ts:30

A 512-bit unsigned integer

U64

U64: = 5

Defined in clvalue.ts:24

A 64-bit unsigned integer

U8

U8: = 3

Defined in clvalue.ts:20

An 8-bit unsigned integer (a byte)

Unit

Unit: = 9

Defined in clvalue.ts:32

A unit type, i.e. type with no values (analogous to void in C and () in Rust)

Uref

Uref: = 12

Defined in clvalue.ts:38

An Unforgeable Reference (URef)

Enumeration: ErrorCode

Standard error codes which can be encountered while running a smart contract.

An ErrorCode can be passed to Error.fromErrorCode function to create an error object. This error object later can be used to stop execution by using Error.revert method.

Index

Enumeration members

Enumeration members

BufferTooSmall

BufferTooSmall: = 32

Defined in error.ts:84

The provided buffer is too small to complete an operation.

CLTypeMismatch

CLTypeMismatch: = 16

Defined in error.ts:52

A given type could not be constructed from a CLValue.

ContractNotFound

ContractNotFound: = 7

Defined in error.ts:34

Failed to find a specified contract.

DeploymentThreshold

DeploymentThreshold: = 27

Defined in error.ts:74

Setting the deployment threshold to a value greater than any other threshold is disallowed.

Deserialize

Deserialize: = 4

Defined in error.ts:28

Failed to deserialize a value.

DuplicateKey

DuplicateKey: = 22

Defined in error.ts:64

The given public key is already associated with the given account.

EarlyEndOfStream

EarlyEndOfStream: = 17

Defined in error.ts:54

Early end of stream while deserializing.

Formatting

Formatting: = 18

Defined in error.ts:56

Formatting error while deserializing.

GetKey

GetKey: = 8

Defined in error.ts:36

A call to getKey returned a failure.

HostBufferEmpty

HostBufferEmpty: = 33

Defined in error.ts:86

No data available in the host buffer.

HostBufferFull

HostBufferFull: = 34

Defined in error.ts:88

The host buffer has been set to a value and should be consumed first by a read operation.

InsufficientTotalWeight

InsufficientTotalWeight: = 28

Defined in error.ts:76

Setting a threshold to a value greater than the total weight of associated keys is disallowed.

InvalidArgument

InvalidArgument: = 3

Defined in error.ts:26

Argument not of correct type.

InvalidPurse

InvalidPurse: = 12

Defined in error.ts:44

Invalid purse retrieved.

InvalidPurseName

InvalidPurseName: = 11

Defined in error.ts:42

Invalid purse name given.

InvalidSystemContract

InvalidSystemContract: = 29

Defined in error.ts:78

The given u32 doesn't map to a [[SystemContractType]].

KeyManagementThreshold

KeyManagementThreshold: = 26

Defined in error.ts:72

Setting the key-management threshold to a value lower than the deployment threshold is disallowed.

LeftOverBytes

LeftOverBytes: = 19

Defined in error.ts:58

Not all input bytes were consumed in deserializing operation

MaxKeysLimit

MaxKeysLimit: = 21

Defined in error.ts:62

There are already maximum public keys associated with the given account.

MissingArgument

MissingArgument: = 2

Defined in error.ts:24

Specified argument not provided.

MissingKey

MissingKey: = 24

Defined in error.ts:68

The given public key is not associated with the given account.

NoAccessRights

NoAccessRights: = 15

Defined in error.ts:50

The given URef has no access rights.

None

None: = 1

Defined in error.ts:22

Optional data was unexpectedly None.

OutOfMemory

OutOfMemory: = 20

Defined in error.ts:60

Out of memory error.

PermissionDenied

PermissionDenied: = 23

Defined in error.ts:66

Caller doesn't have sufficient permissions to perform the given action.

PurseNotCreated

PurseNotCreated: = 30

Defined in error.ts:80

Failed to create a new purse.

Read

Read: = 5

Defined in error.ts:30

casperlabs_contract::storage::read() returned an error.

ThresholdViolation

ThresholdViolation: = 25

Defined in error.ts:70

Removing/updating the given associated public key would cause the total weight of all remaining PublicKeys to fall below one of the action thresholds for the given account.

Transfer

Transfer: = 14

Defined in error.ts:48

Failed to transfer motes.

UnexpectedContractRefVariant

UnexpectedContractRefVariant: = 10

Defined in error.ts:40

The Contract variant was not as expected.

UnexpectedKeyVariant

UnexpectedKeyVariant: = 9

Defined in error.ts:38

The Key variant was not as expected.

Unhandled

Unhandled: = 31

Defined in error.ts:82

An unhandled value, likely representing a bug in the code.

UpgradeContractAtURef

UpgradeContractAtURef: = 13

Defined in error.ts:46

Failed to upgrade contract at URef.

ValueNotFound

ValueNotFound: = 6

Defined in error.ts:32

The given key returned a None value.

Enumeration: Phase

The phase in which a given contract is executing.

Index

Enumeration members

Enumeration members

FinalizePayment

FinalizePayment: = 3

Defined in index.ts:345

Set while finalizing payment at the end of a deploy.

Payment

Payment: = 1

Defined in index.ts:337

Set while executing the payment code of a deploy.

Session

Session: = 2

Defined in index.ts:341

Set while executing the session code of a deploy.

System

System: = 0

Defined in index.ts:333

Set while committing the genesis or upgrade configurations.

Enumeration: SystemContract

System contract types.

Index

Enumeration members

Enumeration members

Mint

Mint: = 0

Defined in index.ts:32

Mint contract.

ProofOfStake

ProofOfStake: = 1

Defined in index.ts:36

Proof of Stake contract.

StandardPayment

StandardPayment: = 2

Defined in index.ts:40

Standard Payment contract.

Enumeration: KeyVariant

Enum representing a variant of a Key - Account, Hash or URef.

Index

Enumeration members

Enumeration members

ACCOUNT_ID

ACCOUNT_ID: = 0

Defined in key.ts:15

The Account variant

HASH_ID

HASH_ID: = 1

Defined in key.ts:17

The Hash variant

UREF_ID

UREF_ID: = 2

Defined in key.ts:19

The URef variant

Enumeration: TransferredTo

The result of a successful transfer between purses.

Index

Enumeration members

Enumeration members

ExistingAccount

ExistingAccount: = 0

Defined in purse.ts:19

The destination account already existed.

NewAccount

NewAccount: = 1

Defined in purse.ts:23

The destination account was created.

TransferError

TransferError: = -1

Defined in purse.ts:15

The transfer operation resulted in an error.

Enumeration: AccessRights

A set of bitflags that defines access rights associated with a URef.

Index

Enumeration members

Enumeration members

ADD

ADD: = 4

Defined in uref.ts:29

Permission to add to the value under the associated URef.

ADD_WRITE

ADD_WRITE: = 6

Defined in uref.ts:37

Permission to add to, or write the value under the associated URef.

NONE

NONE: = 0

Defined in uref.ts:13

No permissions

READ

READ: = 1

Defined in uref.ts:17

Permission to read the value under the associated URef.

READ_ADD

READ_ADD: = 5

Defined in uref.ts:33

Permission to read or add to the value under the associated URef.

READ_ADD_WRITE

READ_ADD_WRITE: = 7

Defined in uref.ts:41

Permission to read, add to, or write the value under the associated URef.

READ_WRITE

READ_WRITE: = 3

Defined in uref.ts:25

Permission to read or write the value under the associated URef.

WRITE

WRITE: = 2

Defined in uref.ts:21

Permission to write a value under the associated URef.

Modules

Module: "account"

Index

Enumerations

Functions

Functions

addAssociatedKey

addAssociatedKey(publicKey: PublicKey, weight: i32): AddKeyFailure

Defined in account.ts:122

Adds an associated key to the account. Associated keys are the keys allowed to sign actions performed in the context of the account.

Parameters:

NameTypeDescription
publicKeyPublicKeyThe public key to be added as the associated key.
weighti32The weight that will be assigned to the new associated key. See setActionThreshold for more info about weights.

Returns: AddKeyFailure

An instance of AddKeyFailure representing the result.

getMainPurse

getMainPurse(): URef

Defined in account.ts:175

Gets the URef representing the main purse of the account.

Returns: URef

The URef that can be used to access the main purse.

removeAssociatedKey

removeAssociatedKey(publicKey: PublicKey): RemoveKeyFailure

Defined in account.ts:164

Removes the associated key from the account. See addAssociatedKey for more info about associated keys.

Parameters:

NameTypeDescription
publicKeyPublicKeyThe associated key to be removed.

Returns: RemoveKeyFailure

An instance of RemoveKeyFailure representing the result.

setActionThreshold

setActionThreshold(actionType: ActionType, thresholdValue: u8): SetThresholdFailure

Defined in account.ts:138

Sets a threshold for the action performed in the context of the account.

Each request has to be signed by one or more of the keys associated with the account. The action is only successful if the total weights of the signing associated keys is greater than the threshold.

Parameters:

NameTypeDescription
actionTypeActionTypeThe type of the action for which the threshold is being set.
thresholdValueu8The minimum total weight of the keys of the action to be successful.

Returns: SetThresholdFailure

An instance of SetThresholdFailure representing the result.

updateAssociatedKey

updateAssociatedKey(publicKey: PublicKey, weight: i32): UpdateKeyFailure

Defined in account.ts:151

Changes the weight of an existing associated key. See addAssociatedKey and setActionThreshold for info about associated keys and their weights.

Parameters:

NameTypeDescription
publicKeyPublicKeyThe associated key to be updated.
weighti32The new desired weight of the associated key.

Returns: UpdateKeyFailure

An instance of UpdateKeyFailure representing the result.

Module: "bignum"

Index

Classes

Module: "bytesrepr"

Index

Enumerations

Classes

Functions

Functions

fromBytesArray

fromBytesArray<T>(bytes: Uint8Array, decodeItem: function): Result‹Array‹T››

Defined in bytesrepr.ts:360

Deserializes an array of bytes into an array of type T.

Type parameters:

T

Parameters:

bytes: Uint8Array

The array of bytes to be deserialized.

decodeItem: function

A function deserializing a value of type T.

▸ (bytes: Uint8Array): Result‹T›

Parameters:

NameType
bytesUint8Array

Returns: Result‹Array‹T››

fromBytesArrayU8

fromBytesArrayU8(bytes: Uint8Array): Result‹Array‹u8››

Defined in bytesrepr.ts:325

Deserializes an array of bytes.

Parameters:

NameType
bytesUint8Array

Returns: Result‹Array‹u8››

fromBytesI32

fromBytesI32(bytes: Uint8Array): Result‹i32›

Defined in bytesrepr.ts:174

Deserializes an i32 from an array of bytes.

Parameters:

NameType
bytesUint8Array

Returns: Result‹i32›

fromBytesLoad

fromBytesLoad<T>(bytes: Uint8Array): Result‹T›

Defined in bytesrepr.ts:122

Deserializes a [[T]] from an array of bytes.

Type parameters:

T

Parameters:

NameType
bytesUint8Array

Returns: Result‹T›

A Result that contains the value of type T, or an error if deserialization failed.

fromBytesMap

fromBytesMap<K, V>(bytes: Uint8Array, decodeKey: function, decodeValue: function): Result‹Array‹Pair‹K, V›››

Defined in bytesrepr.ts:230

Deserializes an array of bytes into a map.

Type parameters:

K

V

Parameters:

bytes: Uint8Array

The array of bytes to be deserialized.

decodeKey: function

A function deserializing the key type.

▸ (bytes1: Uint8Array): Result‹K›

Parameters:

NameType
bytes1Uint8Array

decodeValue: function

A function deserializing the value type.

▸ (bytes2: Uint8Array): Result‹V›

Parameters:

NameType
bytes2Uint8Array

Returns: Result‹Array‹Pair‹K, V›››

An array of key-value pairs or an error in case of failure.

fromBytesString

fromBytesString(s: Uint8Array): Result‹String›

Defined in bytesrepr.ts:294

Deserializes a string from an array of bytes.

Parameters:

NameType
sUint8Array

Returns: Result‹String›

fromBytesStringList

fromBytesStringList(bytes: Uint8Array): Result‹Array‹String››

Defined in bytesrepr.ts:389

Deserializes a list of strings from an array of bytes.

Parameters:

NameType
bytesUint8Array

Returns: Result‹Array‹String››

fromBytesU32

fromBytesU32(bytes: Uint8Array): Result‹u32›

Defined in bytesrepr.ts:154

Deserializes a u32 from an array of bytes.

Parameters:

NameType
bytesUint8Array

Returns: Result‹u32›

fromBytesU64

fromBytesU64(bytes: Uint8Array): Result‹u64›

Defined in bytesrepr.ts:194

Deserializes a u64 from an array of bytes.

Parameters:

NameType
bytesUint8Array

Returns: Result‹u64›

fromBytesU8

fromBytesU8(bytes: Uint8Array): Result‹u8›

Defined in bytesrepr.ts:134

Deserializes a u8 from an array of bytes.

Parameters:

NameType
bytesUint8Array

Returns: Result‹u8›

toBytesArrayU8

toBytesArrayU8(arr: Array‹u8›): u8[]

Defined in bytesrepr.ts:317

Serializes an array of bytes.

Parameters:

NameType
arrArray‹u8›

Returns: u8[]

toBytesI32

toBytesI32(num: i32): u8[]

Defined in bytesrepr.ts:161

Converts i32 to little endian.

Parameters:

NameType
numi32

Returns: u8[]

toBytesMap

toBytesMap(pairs: u8[][]): u8[]

Defined in bytesrepr.ts:210

Serializes a map into an array of bytes.

Parameters:

NameTypeDescription
pairsu8[][]Array of serialized key-value pairs.

Returns: u8[]

toBytesPair

toBytesPair(key: u8[], value: u8[]): u8[]

Defined in bytesrepr.ts:201

Joins a pair of byte arrays into a single array.

Parameters:

NameType
keyu8[]
valueu8[]

Returns: u8[]

toBytesString

toBytesString(s: String): u8[]

Defined in bytesrepr.ts:281

Serializes a string into an array of bytes.

Parameters:

NameType
sString

Returns: u8[]

toBytesStringList

toBytesStringList(arr: String[]): u8[]

Defined in bytesrepr.ts:396

Serializes a list of strings into an array of bytes.

Parameters:

NameType
arrString[]

Returns: u8[]

toBytesU32

toBytesU32(num: u32): u8[]

Defined in bytesrepr.ts:141

Converts u32 to little endian.

Parameters:

NameType
numu32

Returns: u8[]

toBytesU64

toBytesU64(num: u64): u8[]

Defined in bytesrepr.ts:181

Converts u64 to little endian.

Parameters:

NameType
numu64

Returns: u8[]

toBytesU8

toBytesU8(num: u8): u8[]

Defined in bytesrepr.ts:113

Serializes an u8 as an array of bytes.

Parameters:

NameType
numu8

Returns: u8[]

An array containing a single byte: num.

toBytesVecT

toBytesVecT<T>(ts: T[]): Array‹u8›

Defined in bytesrepr.ts:346

Serializes a vector of values of type T into an array of bytes.

Type parameters:

T

Parameters:

NameType
tsT[]

Returns: Array‹u8›

Module: "clvalue"

Index

Enumerations

Classes

Module: "constants"

Index

Variables

Variables

Const ACCESS_RIGHTS_SERIALIZED_LENGTH

ACCESS_RIGHTS_SERIALIZED_LENGTH: 1 = 1

Defined in constants.ts:10

Serialized length of AccessRights field.

internal

Const KEY_ID_SERIALIZED_LENGTH

KEY_ID_SERIALIZED_LENGTH: usize = 1

Defined in constants.ts:22

Serialized length of ID of key.

internal

Const KEY_UREF_SERIALIZED_LENGTH

KEY_UREF_SERIALIZED_LENGTH: any = KEY_ID_SERIALIZED_LENGTH + UREF_SERIALIZED_LENGTH

Defined in constants.ts:27

Serialized length of Key object.

Const UREF_ADDR_LENGTH

UREF_ADDR_LENGTH: 32 = 32

Defined in constants.ts:5

Length of URef address field.

internal

Const UREF_SERIALIZED_LENGTH

UREF_SERIALIZED_LENGTH: number = UREF_ADDR_LENGTH + ACCESS_RIGHTS_SERIALIZED_LENGTH

Defined in constants.ts:16

Serialized length of URef object.

internal

Module: "error"

Index

Enumerations

Classes

Module: "externals"

Module: "index"

Index

Enumerations

Other Functions

Runtime Functions

Other Functions

callContract

callContract(key: Key, args: CLValue[]): Uint8Array

Defined in index.ts:186

Calls the given stored contract, passing the given arguments to it.

If the stored contract calls ret, then that value is returned from callContract. If the stored contract calls Error.revert, then execution stops and callContract doesn't return. Otherwise callContract returns null.

Parameters:

NameTypeDescription
keyKeyA key under which a contract is stored
argsCLValue[]A list of values

Returns: Uint8Array

Bytes of the contract's return value.

getArg

getArg(i: u32): Uint8Array | null

Defined in index.ts:77

Returns the i-th argument passed to the host for the current module invocation.

Note that this is only relevant to contracts stored on-chain since a contract deployed directly is not invoked with any arguments.

Parameters:

NameTypeDescription
iu32I-th parameter

Returns: Uint8Array | null

Array of bytes with ABI serialized argument. A null value if given parameter is not present.

getArgSize

getArgSize(i: u32): RefU32› | null

Defined in index.ts:49

Returns size in bytes of I-th parameter

internal

Parameters:

NameTypeDescription
iu32I-th parameter

Returns: RefU32› | null

getBlockTime

getBlockTime(): u64

Defined in index.ts:299

Returns the current block time.

Returns: u64

getCaller

getCaller(): PublicKey

Defined in index.ts:309

Returns the caller of the current context, i.e. the PublicKey of the account which made the deploy request.

Returns: PublicKey

getKey

getKey(name: String): Key | null

Defined in index.ts:242

Removes the Key stored under name in the current context's named keys.

The current context is either the caller's account or a stored contract depending on whether the currently-executing module is a direct call or a sub-call respectively.

Parameters:

NameTypeDescription
nameStringName of the key in current context's named keys

Returns: Key | null

An instance of Key if it exists, or a null otherwise.

getPhase

getPhase(): Phase

Defined in index.ts:351

Returns the current Phase.

Returns: Phase

getSystemContract

getSystemContract(system_contract: SystemContract): URef

Defined in index.ts:120

Returns an URef for a given system contract

Parameters:

NameTypeDescription
system_contractSystemContractSystem contract variant

Returns: URef

A valid URef that points at system contract, otherwise null.

hasKey

hasKey(name: String): bool

Defined in index.ts:290

Returns true if name exists in the current context's named keys.

The current context is either the caller's account or a stored contract depending on whether the currently-executing module is a direct call or a sub-call respectively.

Parameters:

NameTypeDescription
nameStringName of the key

Returns: bool

listNamedKeys

listNamedKeys(): Array‹Pair‹String, Key››

Defined in index.ts:377

Returns the named keys of the current context.

The current context is either the caller's account or a stored contract depending on whether the currently-executing module is a direct call or a sub-call respectively.

Returns: Array‹Pair‹String, Key››

An array of String and Key pairs

readHostBuffer

readHostBuffer(count: u32): Uint8Array

Defined in index.ts:101

Reads a given amount of bytes from a host buffer

internal

Parameters:

NameTypeDescription
countu32Number of bytes

Returns: Uint8Array

A byte array with bytes received, otherwise a null in case of errors.

removeKey

removeKey(name: String): void

Defined in index.ts:364

Removes the Key stored under name in the current context's named keys.

The current context is either the caller's account or a stored contract depending on whether the currently-executing module is a direct call or a sub-call respectively.

Parameters:

NameType
nameString

Returns: void

ret

ret(value: CLValue): void

Defined in index.ts:273

Returns the given CLValue to the host, terminating the currently running module.

Note this function is only relevant to contracts stored on chain which are invoked via callContract and can thus return a value to their caller. The return value of a directly deployed contract is never used.

Parameters:

NameType
valueCLValue

Returns: void

storeFunction

storeFunction(name: String, namedKeysBytes: u8[]): Key

Defined in index.ts:140

Stores the serialized bytes of an exported function as a new contract under a URef generated by the host.

Parameters:

NameTypeDescription
nameStringName of the exported function
namedKeysBytesu8[]Serialized bytes of named keys. Use toBytesMap to serialize pairs.

Returns: Key

storeFunctionAtHash

storeFunctionAtHash(name: String, namedKeysBytes: u8[]): Key

Defined in index.ts:162

Stores the serialized bytes of an exported function as a new contract at an immutable address generated by the host.

Parameters:

NameTypeDescription
nameStringName of the exported function
namedKeysBytesu8[]Serialized bytes of named keys. Use toBytesMap to serialize pairs.

Returns: Key

upgradeContractAtURef

upgradeContractAtURef(name: String, uref: URef): void

Defined in index.ts:413

Takes the name of an exported function to store as a contract under the given URef which should already reference a stored contract.

If successful, this overwrites the value under uref with a new contract instance containing the original contract's named_keys, the current protocol version, and the newly created bytes of the stored function.

Parameters:

NameType
nameString
urefURef

Returns: void

Runtime Functions

putKey

putKey(name: String, key: Key): void

Defined in index.ts:222

Stores the given Key under a given name in the current context's named keys.

The current context is either the caller's account or a stored contract depending on whether the currently-executing module is a direct call or a sub-call respectively.

Parameters:

NameType
nameString
keyKey

Returns: void

Module: "key"

Index

Enumerations

Classes

Variables

Variables

Const PUBLIC_KEY_ED25519_ID

PUBLIC_KEY_ED25519_ID: u8 = 0

Defined in key.ts:25

The ID of an ED25519 public key.

Module: "local"

Index

Storage Functions

Storage Functions

addLocal

addLocal(local: Uint8Array, value: CLValue): void

Defined in local.ts:45

Adds value to the one currently under key in the context-local partition of global state.

Parameters:

NameType
localUint8Array
valueCLValue

Returns: void

readLocal

readLocal(local: Uint8Array): Uint8Array | null

Defined in local.ts:13

Reads the value under key in the context-local partition of global state.

Parameters:

NameType
localUint8Array

Returns: Uint8Array | null

Returns bytes of serialized value, otherwise a null if given local key does not exists.

writeLocal

writeLocal(local: Uint8Array, value: CLValue): void

Defined in local.ts:31

Writes value under key in the context-local partition of global state.

Parameters:

NameType
localUint8Array
valueCLValue

Returns: void

Module: "option"

Index

Classes

Module: "pair"

Index

Classes

Module: "purse"

Index

Enumerations

Functions

Functions

createPurse

createPurse(): URef

Defined in purse.ts:30

Creates a new empty purse and returns its URef, or a null in case a purse couldn't be created.

Returns: URef

getPurseBalance

getPurseBalance(purse: URef): U512 | null

Defined in purse.ts:55

Returns the balance in motes of the given purse or a null if given purse is invalid.

Parameters:

NameType
purseURef

Returns: U512 | null

transferFromPurseToAccount

transferFromPurseToAccount(sourcePurse: URef, targetAccount: Uint8Array, amount: U512): TransferredTo

Defined in purse.ts:89

Transfers amount of motes from source purse to target account. If target does not exist it will be created.

Parameters:

NameTypeDescription
sourcePurseURef-
targetAccountUint8Array-
amountU512Amount is denominated in motes

Returns: TransferredTo

This function will return a TransferredTo.TransferError in case of transfer error, in case of any other variant the transfer itself can be considered successful.

transferFromPurseToPurse

transferFromPurseToPurse(sourcePurse: URef, targetPurse: URef, amount: U512): i32

Defined in purse.ts:120

Transfers amount of motes from source purse to target purse. If target does not exist the transfer fails.

Parameters:

NameType
sourcePurseURef
targetPurseURef
amountU512

Returns: i32

This function returns non-zero value on error.

Module: "unit"

Index

Classes

Module: "uref"

Index

Enumerations

Classes

Module: "utils"

Index

Functions

Functions

arrayToTyped

arrayToTyped(arr: Array‹u8›): Uint8Array

Defined in utils.ts:11

Converts array to typed array

Parameters:

NameType
arrArray‹u8›

Returns: Uint8Array

checkArraysEqual

checkArraysEqual<T>(a: Array‹T›, b: Array‹T›, len: i32): bool

Defined in utils.ts:32

Checks if two ordered arrays are equal

Type parameters:

T

Parameters:

NameTypeDefault
aArray‹T›-
bArray‹T›-
leni320

Returns: bool

checkItemsEqual

checkItemsEqual<T>(a: Array‹T›, b: Array‹T›): bool

Defined in utils.ts:20

Checks if items in two unordered arrays are equal

Type parameters:

T

Parameters:

NameType
aArray‹T›
bArray‹T›

Returns: bool

checkTypedArrayEqual

checkTypedArrayEqual(a: Uint8Array, b: Uint8Array, len: i32): bool

Defined in utils.ts:49

Checks if two ordered arrays are equal

Parameters:

NameTypeDefault
aUint8Array-
bUint8Array-
leni320

Returns: bool

typedToArray

typedToArray(arr: Uint8Array): Array‹u8›

Defined in utils.ts:2

Converts typed array to array

Parameters:

NameType
arrUint8Array

Returns: Array‹u8›

FAQs

Package last updated on 02 Jul 2020

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts