Never Patronize Mothers

    casper-contract

    1.4.6 • Public • Published

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

    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

    div(other: U512): U512

    Defined in bignum.ts:340

    The division operator - divides the arguments.

    Parameters:

    Name Type
    other U512

    Returns: U512


    divMod

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

    Defined in bignum.ts:299

    Performs the integer division of this/other.

    Parameters:

    Name Type Description
    other U512 The 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:

    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

    mul(other: U512): U512

    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

    rem(other: U512): U512

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

    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

    sub(other: U512): U512

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

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

    An alias for [[toHex]].

    Returns: String


    Static fromBytes

    fromBytes(bytes: Uint8Array): ResultU512

    Defined in bignum.ts:551

    Deserializes a U512 from an array of bytes. The array should represent a correct U512 in the Casper serialization format.

    Parameters:

    Name Type
    bytes Uint8Array

    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:

    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

    fromKey(key: Key): CLValue

    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:

    Parameters:

    Name Type Description
    value u32 Error value

    Returns: Error

    Methods

    isSystemContractError

    isSystemContractError(): bool

    Defined in error.ts:183

    Checks if error value is contained within system contract error range.

    Returns: bool


    isUserError

    isUserError(): bool

    Defined in error.ts:176

    Checks if error value is contained within user error range.

    Returns: bool


    revert

    revert(): void

    Defined in error.ts:190

    Reverts execution of current contract with an error value contained within this error instance.

    Returns: void


    value

    value(): u32

    Defined in error.ts:169

    Returns an error value.

    Returns: u32


    Static fromErrorCode

    fromErrorCode(errorCode: ErrorCode): Error

    Defined in error.ts:162

    Creates new error object from an ErrorCode value.

    Parameters:

    Name Type Description
    errorCode ErrorCode Variant of a standarized error.

    Returns: Error


    Static fromResult

    fromResult(result: u32): Error | null

    Defined in error.ts:139

    Creates an error object from a result value.

    Results in host interface contains 0 for a successful operation, or a non-zero standardized error otherwise.

    Parameters:

    Name Type Description
    result u32 A result value obtained from host interface functions.

    Returns: Error | null

    Error object with an error ErrorCode variant.


    Static fromUserError

    fromUserError(userErrorCodeValue: u16): Error

    Defined in error.ts:153

    Creates new error from user value.

    Actual value held by returned Error object will be 65536 with added passed value.

    Parameters:

    Name Type Description
    userErrorCodeValue u16

    Returns: Error

    Class: AddContractVersionResult

    Hierarchy

    • AddContractVersionResult

    Index

    Constructors

    Properties

    Constructors

    constructor

    + new AddContractVersionResult(contractHash: Uint8Array, contractVersion: u32): AddContractVersionResult

    Defined in index.ts:536

    Parameters:

    Name Type
    contractHash Uint8Array
    contractVersion u32

    Returns: AddContractVersionResult

    Properties

    contractHash

    contractHash: Uint8Array

    Defined in index.ts:537


    contractVersion

    contractVersion: u32

    Defined in index.ts:537

    Class: CreateContractPackageResult

    A two-value structure that holds the result of createContractPackageAtHash.

    Hierarchy

    • CreateContractPackageResult

    Index

    Constructors

    Properties

    Constructors

    constructor

    + new CreateContractPackageResult(packageHash: Uint8Array, accessURef: URef): CreateContractPackageResult

    Defined in index.ts:440

    Parameters:

    Name Type
    packageHash Uint8Array
    accessURef URef

    Returns: CreateContractPackageResult

    Properties

    accessURef

    accessURef: URef

    Defined in index.ts:441


    packageHash

    packageHash: Uint8Array

    Defined in index.ts:441

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

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


    args

    args: Array‹Pair‹String, CLType››

    Defined in index.ts:410


    entry_point_type

    entry_point_type: EntryPointType

    Defined in index.ts:413


    name

    name: String

    Defined in index.ts:409


    ret

    ret: CLType

    Defined in index.ts:411

    Methods

    toBytes

    toBytes(): Array‹u8›

    Defined in index.ts:415

    Returns: Array‹u8›

    Class: EntryPointAccess

    Hierarchy

    Index

    Constructors

    Properties

    Methods

    Constructors

    constructor

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

    Defined in index.ts:381

    Parameters:

    Name Type
    cachedBytes Array‹u8›

    Returns: EntryPointAccess

    Properties

    cachedBytes

    cachedBytes: Array‹u8›

    Defined in index.ts:382

    Methods

    toBytes

    toBytes(): Array‹u8›

    Defined in index.ts:383

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

    Methods

    addEntryPoint

    addEntryPoint(entryPoint: EntryPoint): void

    Defined in index.ts:428

    Parameters:

    Name Type
    entryPoint EntryPoint

    Returns: void


    toBytes

    toBytes(): Array‹u8›

    Defined in index.ts:431

    Returns: Array‹u8›

    Class: GroupAccess

    Hierarchy

    Index

    Constructors

    Properties

    Methods

    Constructors

    constructor

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

    Overrides EntryPointAccess.constructor

    Defined in index.ts:394

    Parameters:

    Name Type
    groups String[]

    Returns: GroupAccess

    Properties

    cachedBytes

    cachedBytes: Array‹u8›

    Inherited from EntryPointAccess.cachedBytes

    Defined in index.ts:382

    Methods

    toBytes

    toBytes(): Array‹u8›

    Inherited from EntryPointAccess.toBytes

    Defined in index.ts:383

    Returns: Array‹u8›

    Class: PublicAccess

    Hierarchy

    Index

    Constructors

    Properties

    Methods

    Constructors

    constructor

    + new PublicAccess(): PublicAccess

    Overrides EntryPointAccess.constructor

    Defined in index.ts:388

    Returns: PublicAccess

    Properties

    cachedBytes

    cachedBytes: Array‹u8›

    Inherited from EntryPointAccess.cachedBytes

    Defined in index.ts:382

    Methods

    toBytes

    toBytes(): Array‹u8›

    Inherited from EntryPointAccess.toBytes

    Defined in index.ts:383

    Returns: Array‹u8›

    Class: AccountHash

    A cryptographic public key.

    Hierarchy

    • AccountHash

    Index

    Constructors

    Properties

    Methods

    Constructors

    constructor

    + new AccountHash(bytes: Uint8Array): AccountHash

    Defined in key.ts:27

    Constructs a new AccountHash.

    Parameters:

    Name Type Description
    bytes Uint8Array The bytes constituting the public key.

    Returns: AccountHash

    Properties

    bytes

    bytes: Uint8Array

    Defined in key.ts: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:

    Name Type
    other AccountHash

    Returns: bool


    notEqualsTo

    notEqualsTo(other: AccountHash): bool

    Defined in key.ts:43

    Checks whether two AccountHashs 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: Uint8Array): ResultAccountHash

    Defined in key.ts:70

    Deserializes a AccountHash from an array of bytes.

    Parameters:

    Name Type
    bytes Uint8Array

    Returns: ResultAccountHash


    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: Uint8Array | 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 Keys 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:297

    Checks whether two keys are not equal.

    Parameters:

    Name Type
    other Key

    Returns: bool


    read

    read(): Uint8Array | null

    Defined in key.ts:221

    Reads the data stored under this Key.

    Returns: Uint8Array | 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: Uint8Array): ResultKey

    Defined in key.ts:142

    Deserializes a Key from an array of bytes.

    Parameters:

    Name Type
    bytes Uint8Array

    Returns: ResultKey


    Static fromHash

    fromHash(hash: Uint8Array): Key

    Defined in key.ts:106

    Creates a Key from a given hash.

    Parameters:

    Name Type
    hash Uint8Array

    Returns: Key


    Static fromURef

    fromURef(uref: URef): Key

    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: Uint8Array | null): Option

    Defined in option.ts:10

    Constructs a new option containing the value of bytes. bytes can be null, which indicates no value.

    Parameters:

    Name Type
    bytes Uint8Array | null

    Returns: Option

    Methods

    isNone

    isNone(): bool

    Defined in option.ts:25

    Checks whether the Option contains no value.

    Returns: bool

    True if the Option has no value.


    isSome

    isSome(): bool

    Defined in option.ts:34

    Checks whether the Option contains a value.

    Returns: bool

    True if the Option has some value.


    toBytes

    toBytes(): Array‹u8›

    Defined in option.ts:51

    Serializes the Option into an array of bytes.

    Returns: Array‹u8›


    unwrap

    unwrap(): Uint8Array

    Defined in option.ts:43

    Unwraps the Option, returning the inner value (or null if there was none).

    Returns: Uint8Array

    The inner value, or null if there was none.


    Static fromBytes

    fromBytes(bytes: Uint8Array): Option

    Defined in option.ts:71

    Deserializes an array of bytes into an Option.

    Parameters:

    Name Type
    bytes Uint8Array

    Returns: Option

    Class: Pair <T1, T2>

    A pair of values.

    Type parameters

    T1

    The type of the first value.

    T2

    The type of the second value.

    Hierarchy

    • Pair

    Index

    Constructors

    Properties

    Methods

    Constructors

    constructor

    + new Pair(first: T1, second: T2): Pair

    Defined in pair.ts:15

    Constructs the pair out of the two given values.

    Parameters:

    Name Type
    first T1
    second T2

    Returns: Pair

    Properties

    first

    first: T1

    Defined in pair.ts:11

    The first value in the pair.


    second

    second: T2

    Defined in pair.ts:15

    The second value in the pair.

    Methods

    equalsTo

    equalsTo(other: Pair‹T1, T2›): bool

    Defined in pair.ts:30

    Checks whether two pairs are equal. The pairs are considered equal when both their first and second values are equal.

    Parameters:

    Name Type
    other Pair‹T1, T2›

    Returns: bool


    notEqualsTo

    notEqualsTo(other: Pair‹T1, T2›): bool

    Defined in pair.ts:38

    Checks whether two pairs are not equal (the opposite of equalsTo).

    Parameters:

    Name Type
    other Pair‹T1, T2›

    Returns: bool

    Class: PublicKey

    Hierarchy

    • PublicKey

    Index

    Constructors

    Methods

    Constructors

    constructor

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

    Defined in public_key.ts:15

    Parameters:

    Name Type
    variant PublicKeyVariant
    bytes Uint8Array

    Returns: PublicKey

    Methods

    getAlgorithmName

    getAlgorithmName(): string

    Defined in public_key.ts:23

    Returns: string


    getRawBytes

    getRawBytes(): Uint8Array

    Defined in public_key.ts:19

    Returns: Uint8Array


    toBytes

    toBytes(): Array‹u8›

    Defined in public_key.ts:37

    Returns: Array‹u8›


    Static fromBytes

    fromBytes(bytes: Uint8Array): ResultPublicKey

    Defined in public_key.ts:43

    Deserializes a PublicKey from an array of bytes.

    Parameters:

    Name Type
    bytes Uint8Array

    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

    Returns: TransferredTo

    Methods

    Static makeErr

    makeErr(err: Error): TransferResult

    Defined in purse.ts:36

    Parameters:

    Name Type
    err Error

    Returns: TransferResult


    Static makeOk

    makeOk(ok: RefTransferredTo›): TransferResult

    Defined in purse.ts:42

    Parameters:

    Name Type
    ok RefTransferredTo

    Returns: TransferResult

    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 ref.ts:4

    Parameters:

    Name Type
    value T

    Returns: Ref

    Properties

    value

    value: T

    Defined in ref.ts:5

    Class: RuntimeArgs

    Implements a collection of runtime arguments.

    Hierarchy

    • RuntimeArgs

    Index

    Constructors

    Properties

    Methods

    Constructors

    constructor

    + new RuntimeArgs(arguments: Pair‹String, CLValue›[]): RuntimeArgs

    Defined in runtime_args.ts:8

    Parameters:

    Name Type Default
    arguments Pair‹String, CLValue›[] []

    Returns: RuntimeArgs

    Properties

    arguments

    arguments: Pair‹String, CLValue›[]

    Defined in runtime_args.ts:9

    Methods

    toBytes

    toBytes(): Array‹u8›

    Defined in runtime_args.ts:15

    Returns: Array‹u8›


    Static fromArray

    fromArray(pairs: Pair‹String, CLValue›[]): RuntimeArgs

    Defined in runtime_args.ts:11

    Parameters:

    Name Type
    pairs Pair‹String, CLValue›[]

    Returns: RuntimeArgs

    Class: Unit

    A class representing the unit type, i.e. a type that has no values (equivalent to eg. void in C or () in Rust).

    Hierarchy

    • Unit

    Index

    Methods

    Methods

    toBytes

    toBytes(): Array‹u8›

    Defined in unit.ts:9

    Serializes a Unit - returns an empty array.

    Returns: Array‹u8›


    Static fromBytes

    fromBytes(bytes: Uint8Array): Unit

    Defined in unit.ts:16

    Deserializes a Unit - returns a new Unit.

    Parameters:

    Name Type
    bytes Uint8Array

    Returns: Unit

    Class: URef

    Represents an unforgeable reference, containing an address in the network's global storage and the AccessRights of the reference.

    A URef can be used to index entities such as CLValues, or smart contracts.

    Hierarchy

    • URef

    Index

    Constructors

    Methods

    Constructors

    constructor

    + new URef(bytes: Uint8Array, accessRights: AccessRights): URef

    Defined in uref.ts:56

    Constructs new instance of URef.

    Parameters:

    Name Type Description
    bytes Uint8Array Bytes representing address of the URef.
    accessRights AccessRights Access rights flag. Use AccessRights.NONE to indicate no permissions.

    Returns: URef

    Methods

    equalsTo

    equalsTo(other: URef): bool

    Defined in uref.ts:144

    The equality operator.

    Parameters:

    Name Type
    other URef

    Returns: bool

    True if this and other are equal, false otherwise.


    getAccessRights

    getAccessRights(): AccessRights

    Defined in uref.ts:80

    Returns the access rights of this URef.

    Returns: AccessRights


    getBytes

    getBytes(): Uint8Array

    Defined in uref.ts:73

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

    Validates uref against named keys.

    Returns: boolean


    notEqualsTo

    notEqualsTo(other: URef): bool

    Defined in uref.ts:154

    The not-equal operator.

    Parameters:

    Name Type
    other URef

    Returns: bool

    False if this and other are equal, true otherwise.


    setAccessRights

    setAccessRights(newAccessRights: AccessRights): void

    Defined in uref.ts:87

    Sets the access rights of this URef.

    Parameters:

    Name Type
    newAccessRights AccessRights

    Returns: void


    toBytes

    toBytes(): Array‹u8›

    Defined in uref.ts:132

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

    Returns: Array‹u8›


    withAccessRights

    withAccessRights(newAccessRights: AccessRights): URef

    Defined in uref.ts:94

    Returns new URef with modified access rights.

    Parameters:

    Name Type
    newAccessRights AccessRights

    Returns: URef


    Static fromBytes

    fromBytes(bytes: Uint8Array): ResultURef

    Defined in uref.ts:114

    Deserializes a new URef from bytes.

    Parameters:

    Name Type Description
    bytes Uint8Array Input 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:17

    Early end of stream


    FormattingError

    FormattingError: = 2

    Defined in bytesrepr.ts:21

    Unexpected data encountered while decoding byte stream


    Ok

    Ok: = 0

    Defined in bytesrepr.ts:13

    Last operation was a success

    Enumeration: CLTypeTag

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

    A value of any type.


    Bool

    Bool: = 0

    Defined in clvalue.ts:15

    A boolean value


    ByteArray

    ByteArray: = 15

    Defined in clvalue.ts:45

    A fixed-length array of bytes


    I32

    I32: = 1

    Defined in clvalue.ts:17

    A 32-bit signed integer


    I64

    I64: = 2

    Defined in clvalue.ts:19

    A 64-bit signed integer


    Key

    Key: = 11

    Defined in clvalue.ts:37

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


    List

    List: = 14

    Defined in clvalue.ts:43

    A list of values


    Map

    Map: = 17

    Defined in clvalue.ts:51

    A key-value map.


    Option

    Option: = 13

    Defined in clvalue.ts:41

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


    PublicKey

    PublicKey: = 22

    Defined in clvalue.ts:61

    A value of public key type.


    Result

    Result: = 16

    Defined in clvalue.ts:49

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

    A string of characters


    Tuple1

    Tuple1: = 18

    Defined in clvalue.ts:53

    A 1-value tuple.


    Tuple2

    Tuple2: = 19

    Defined in clvalue.ts:55

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


    Tuple3

    Tuple3: = 20

    Defined in clvalue.ts:57

    A 3-value tuple.


    U128

    U128: = 6

    Defined in clvalue.ts:27

    A 128-bit unsigned integer


    U256

    U256: = 7

    Defined in clvalue.ts:29

    A 256-bit unsigned integer


    U32

    U32: = 4

    Defined in clvalue.ts:23

    A 32-bit unsigned integer


    U512

    U512: = 8

    Defined in clvalue.ts:31

    A 512-bit unsigned integer


    U64

    U64: = 5

    Defined in clvalue.ts:25

    A 64-bit unsigned integer


    U8

    U8: = 3

    Defined in clvalue.ts:21

    An 8-bit unsigned integer (a byte)


    Unit

    Unit: = 9

    Defined in clvalue.ts:33

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


    Uref

    Uref: = 12

    Defined in clvalue.ts:39

    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

    casper_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 AccountHashs 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: EntryPointType

    Index

    Enumeration members

    Enumeration members

    Contract

    Contract: = 1

    Defined in index.ts:405


    Session

    Session: = 0

    Defined in index.ts:404

    Enumeration: Phase

    The phase in which a given contract is executing.

    Index

    Enumeration members

    Enumeration members

    FinalizePayment

    FinalizePayment: = 3

    Defined in index.ts:318

    Set while finalizing payment at the end of a deploy.


    Payment

    Payment: = 1

    Defined in index.ts:310

    Set while executing the payment code of a deploy.


    Session

    Session: = 2

    Defined in index.ts:314

    Set while executing the session code of a deploy.


    System

    System: = 0

    Defined in index.ts:306

    Set while committing the genesis or upgrade configurations.

    Enumeration: SystemContract

    System contract types.

    Index

    Enumeration members

    Enumeration members

    Auction

    Auction: = 3

    Defined in index.ts:51

    Auction contract.


    HandlePayment

    HandlePayment: = 1

    Defined in index.ts:43

    Handle Payment contract.


    Mint

    Mint: = 0

    Defined in index.ts:39

    Mint contract.


    StandardPayment

    StandardPayment: = 2

    Defined in index.ts:47

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

    The Account variant


    HASH_ID

    HASH_ID: = 1

    Defined in key.ts:21

    The Hash variant


    UREF_ID

    UREF_ID: = 2

    Defined in key.ts:23

    The URef variant

    Enumeration: PublicKeyVariant

    Index

    Enumeration members

    Enumeration members

    Ed25519

    Ed25519: = 1

    Defined in public_key.ts:10

    A public key of Ed25519 type


    Secp256k1

    Secp256k1: = 2

    Defined in public_key.ts:12

    A public key of Secp256k1 type

    Enumeration: TransferredTo

    The result of a successful transfer between purses.

    Index

    Enumeration members

    Enumeration members

    ExistingAccount

    ExistingAccount: = 0

    Defined in purse.ts:22

    The destination account already existed.


    NewAccount

    NewAccount: = 1

    Defined in purse.ts:26

    The destination account was created.

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

    Permission to add to the value under the associated URef.


    ADD_WRITE

    ADD_WRITE: = 6

    Defined in uref.ts:38

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


    NONE

    NONE: = 0

    Defined in uref.ts:14

    No permissions


    READ

    READ: = 1

    Defined in uref.ts:18

    Permission to read the value under the associated URef.


    READ_ADD

    READ_ADD: = 5

    Defined in uref.ts:34

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


    READ_ADD_WRITE

    READ_ADD_WRITE: = 7

    Defined in uref.ts:42

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


    READ_WRITE

    READ_WRITE: = 3

    Defined in uref.ts:26

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


    WRITE

    WRITE: = 2

    Defined in uref.ts:22

    Permission to write a value under the associated URef.

    Modules

    Module: "account"

    Index

    Enumerations

    Functions

    Functions

    addAssociatedKey

    addAssociatedKey(accountHash: AccountHash, 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:

    Name Type Description
    accountHash AccountHash -
    weight i32 The 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(accountHash: AccountHash): RemoveKeyFailure

    Defined in account.ts:164

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

    Parameters:

    Name Type Description
    accountHash AccountHash The 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:

    Name Type Description
    actionType ActionType The type of the action for which the threshold is being set.
    thresholdValue u8 The minimum total weight of the keys of the action to be successful.

    Returns: SetThresholdFailure

    An instance of SetThresholdFailure representing the result.


    updateAssociatedKey

    updateAssociatedKey(accountHash: AccountHash, 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:

    Name Type Description
    accountHash AccountHash The associated key to be updated.
    weight i32 The 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:349

    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:

    Name Type
    bytes Uint8Array

    Returns: Result‹Array‹T››


    fromBytesArrayU8

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

    Defined in bytesrepr.ts:313

    Deserializes an array of bytes.

    Parameters:

    Name Type
    bytes Uint8Array

    Returns: Result‹Array‹u8››


    fromBytesI32

    fromBytesI32(bytes: Uint8Array): Result‹i32›

    Defined in bytesrepr.ts:167

    Deserializes an i32 from an array of bytes.

    Parameters:

    Name Type
    bytes Uint8Array

    Returns: Result‹i32›


    fromBytesLoad

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

    Defined in bytesrepr.ts:115

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

    Type parameters:

    T

    Parameters:

    Name Type
    bytes Uint8Array

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

    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:

    Name Type
    bytes1 Uint8Array

    decodeValue: function

    A function deserializing the value type.

    ▸ (bytes2: Uint8Array): Result‹V›

    Parameters:

    Name Type
    bytes2 Uint8Array

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

    Deserializes a string from an array of bytes.

    Parameters:

    Name Type
    s Uint8Array

    Returns: Result‹String›


    fromBytesStringList

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

    Defined in bytesrepr.ts:378

    Deserializes a list of strings from an array of bytes.

    Parameters:

    Name Type
    bytes Uint8Array

    Returns: Result‹Array‹String››


    fromBytesU32

    fromBytesU32(bytes: Uint8Array): Result‹u32›

    Defined in bytesrepr.ts:147

    Deserializes a u32 from an array of bytes.

    Parameters:

    Name Type
    bytes Uint8Array

    Returns: Result‹u32›


    fromBytesU64

    fromBytesU64(bytes: Uint8Array): Result‹u64›

    Defined in bytesrepr.ts:187

    Deserializes a u64 from an array of bytes.

    Parameters:

    Name Type
    bytes Uint8Array

    Returns: Result‹u64›


    fromBytesU8

    fromBytesU8(bytes: Uint8Array): Result‹u8›

    Defined in bytesrepr.ts:127

    Deserializes a u8 from an array of bytes.

    Parameters:

    Name Type
    bytes Uint8Array

    Returns: Result‹u8›


    toBytesArrayU8

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

    Defined in bytesrepr.ts:305

    Serializes an array of bytes.

    Parameters:

    Name Type
    arr Array‹u8›

    Returns: u8[]


    toBytesI32

    toBytesI32(num: i32): u8[]

    Defined in bytesrepr.ts:154

    Converts i32 to little endian.

    Parameters:

    Name Type
    num i32

    Returns: u8[]


    toBytesMap

    toBytesMap<K, V>(vecOfPairs: Array‹Pair‹K, V››, serializeKey: function, serializeValue: function): Array‹u8›

    Defined in bytesrepr.ts:205

    Serializes a map into an array of bytes.

    Type parameters:

    K

    V

    Parameters:

    vecOfPairs: Array‹Pair‹K, V››

    serializeKey: function

    A function that will serialize given key.

    ▸ (key: K): Array‹u8›

    Parameters:

    Name Type
    key K

    serializeValue: function

    A function that will serialize given value.

    ▸ (value: V): Array‹u8›

    Parameters:

    Name Type
    value V

    Returns: Array‹u8›


    toBytesPair

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

    Defined in bytesrepr.ts:194

    Joins a pair of byte arrays into a single array.

    Parameters:

    Name Type
    key u8[]
    value u8[]

    Returns: u8[]


    toBytesString

    toBytesString(s: String): u8[]

    Defined in bytesrepr.ts:274

    Serializes a string into an array of bytes.

    Parameters:

    Name Type
    s String

    Returns: u8[]


    toBytesStringList

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

    Defined in bytesrepr.ts:385

    Serializes a list of strings into an array of bytes.

    Parameters:

    Name Type
    arr String[]

    Returns: u8[]


    toBytesU32

    toBytesU32(num: u32): u8[]

    Defined in bytesrepr.ts:134

    Converts u32 to little endian.

    Parameters:

    Name Type
    num u32

    Returns: u8[]


    toBytesU64

    toBytesU64(num: u64): u8[]

    Defined in bytesrepr.ts:174

    Converts u64 to little endian.

    Parameters:

    Name Type
    num u64

    Returns: u8[]


    toBytesU8

    toBytesU8(num: u8): u8[]

    Defined in bytesrepr.ts:106

    Serializes an u8 as an array of bytes.

    Parameters:

    Name Type
    num u8

    Returns: u8[]

    An array containing a single byte: num.


    toBytesVecT

    toBytesVecT<T>(ts: Array‹T›, encodeItem: function): Array‹u8›

    Defined in bytesrepr.ts:334

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

    Type parameters:

    T

    Parameters:

    ts: Array‹T›

    encodeItem: function

    ▸ (item: T): Array‹u8›

    Parameters:

    Name Type
    item T

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

    Serialized length of AccessRights field.

    internal


    Const KEY_HASH_LENGTH

    KEY_HASH_LENGTH: 32 = 32

    Defined in constants.ts:11

    Length of hash variant of a Key.

    internal


    Const KEY_ID_SERIALIZED_LENGTH

    KEY_ID_SERIALIZED_LENGTH: i32 = 1

    Defined in constants.ts:29

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

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

    Serialized length of URef object.

    internal

    Module: "dictionary"

    Index

    Storage Functions

    Storage Functions

    dictionaryGet

    dictionaryGet(seed_uref: URef, key: String): Uint8Array | null

    Defined in dictionary.ts:42

    Reads the value under key in the dictionary partition of global state.

    Parameters:

    Name Type
    seed_uref URef
    key String

    Returns: Uint8Array | null

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


    dictionaryPut

    dictionaryPut(uref: URef, key: String, value: CLValue): void

    Defined in dictionary.ts:63

    Writes value under key in a dictionary.

    Parameters:

    Name Type
    uref URef
    key String
    value CLValue

    Returns: void


    newDictionary

    newDictionary(keyName: String): URef

    Defined in dictionary.ts:17

    Creates new seed for a dictionary partition of the global state.

    Parameters:

    Name Type
    keyName String

    Returns: URef

    Returns newly provisioned URef

    Module: "error"

    Index

    Enumerations

    Classes

    Module: "externals"

    Index

    Functions

    Functions

    casper_new_dictionary

    casper_new_dictionary(output_size_ptr: usize): i32

    Defined in externals.ts:214

    Parameters:

    Name Type
    output_size_ptr usize

    Returns: i32


    load_named_keys

    load_named_keys(total_keys: usize, result_size: usize): i32

    Defined in externals.ts:20

    Parameters:

    Name Type
    total_keys usize
    result_size usize

    Returns: i32

    Module: "index"

    Index

    Enumerations

    Classes

    Other Functions

    Runtime Functions

    Other Functions

    addContractVersion

    addContractVersion(packageHash: Uint8Array, entryPoints: EntryPoints, namedKeys: Array‹Pair‹String, Key››): AddContractVersionResult

    Defined in index.ts:542

    Parameters:

    Name Type
    packageHash Uint8Array
    entryPoints EntryPoints
    namedKeys Array‹Pair‹String, Key››

    Returns: AddContractVersionResult


    callContract

    callContract(contractHash: Uint8Array, entryPointName: String, runtimeArgs: RuntimeArgs): Uint8Array

    Defined in index.ts:157

    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:

    Name Type Description
    contractHash Uint8Array A key under which a contract is stored
    entryPointName String -
    runtimeArgs RuntimeArgs -

    Returns: Uint8Array

    Bytes of the contract's return value.


    callVersionedContract

    callVersionedContract(packageHash: Uint8Array, contract_version: Option, entryPointName: String, runtimeArgs: RuntimeArgs): Uint8Array

    Defined in index.ts:505

    Parameters:

    Name Type
    packageHash Uint8Array
    contract_version Option
    entryPointName String
    runtimeArgs RuntimeArgs

    Returns: Uint8Array


    createContractPackageAtHash

    createContractPackageAtHash(): CreateContractPackageResult

    Defined in index.ts:444

    Returns: CreateContractPackageResult


    createContractUserGroup

    createContractUserGroup(packageHash: Uint8Array, label: String, newURefs: u8, existingURefs: Array‹URef›): Array‹URef

    Defined in index.ts:573

    Parameters:

    Name Type
    packageHash Uint8Array
    label String
    newURefs u8
    existingURefs Array‹URef

    Returns: Array‹URef


    createLockedContractPackageAtHash

    createLockedContractPackageAtHash(): CreateContractPackageResult

    Defined in index.ts:454

    Returns: CreateContractPackageResult


    extendContractUserGroupURefs

    extendContractUserGroupURefs(packageHash: Uint8Array, label: String): URef

    Defined in index.ts:623

    Parameters:

    Name Type
    packageHash Uint8Array
    label String

    Returns: URef


    getBlockTime

    getBlockTime(): u64

    Defined in index.ts:272

    Returns the current block time.

    Returns: u64


    getCaller

    getCaller(): AccountHash

    Defined in index.ts:282

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

    Returns: AccountHash


    getKey

    getKey(name: String): Key | null

    Defined in index.ts:215

    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:

    Name Type Description
    name String Name of the key in current context's named keys

    Returns: Key | null

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


    getNamedArg

    getNamedArg(name: String): Uint8Array

    Defined in index.ts:89

    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:

    Name Type
    name String

    Returns: Uint8Array

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


    getNamedArgSize

    getNamedArgSize(name: string): Ref‹u32› | null

    Defined in index.ts:60

    Returns size in bytes of I-th parameter

    internal

    Parameters:

    Name Type
    name string

    Returns: Ref‹u32› | null


    getPhase

    getPhase(): Phase

    Defined in index.ts:324

    Returns the current Phase.

    Returns: Phase


    getSystemContract

    getSystemContract(systemContract: SystemContract): Uint8Array

    Defined in index.ts:135

    Returns an URef for a given system contract

    Parameters:

    Name Type
    systemContract SystemContract

    Returns: Uint8Array

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


    hasKey

    hasKey(name: String): bool

    Defined in index.ts:263

    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:

    Name Type Description
    name String Name of the key

    Returns: bool


    listNamedKeys

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

    Defined in index.ts:350

    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


    newContract

    newContract(entryPoints: EntryPoints, namedKeys: Array‹Pair‹String, Key›› | null, hashName: String | null, urefName: String | null): AddContractVersionResult

    Defined in index.ts:464

    Parameters:

    Name Type Default
    entryPoints EntryPoints -
    namedKeys Array‹Pair‹String, Key›› | null null
    hashName String | null null
    urefName String | null null

    Returns: AddContractVersionResult


    newLockedContract

    newLockedContract(entryPoints: EntryPoints, namedKeys: Array‹Pair‹String, Key›› | null, hashName: String | null, urefName: String | null): AddContractVersionResult

    Defined in index.ts:484

    Parameters:

    Name Type Default
    entryPoints EntryPoints -
    namedKeys Array‹Pair‹String, Key›› | null null
    hashName String | null null
    urefName String | null null

    Returns: AddContractVersionResult


    readHostBuffer

    readHostBuffer(count: u32): Uint8Array

    Defined in index.ts:116

    Reads a given amount of bytes from a host buffer

    internal

    Parameters:

    Name Type Description
    count u32 Number of bytes

    Returns: Uint8Array

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


    removeContractUserGroup

    removeContractUserGroup(packageHash: Uint8Array, label: String): void

    Defined in index.ts:606

    Parameters:

    Name Type
    packageHash Uint8Array
    label String

    Returns: void


    removeContractUserGroupURefs

    removeContractUserGroupURefs(packageHash: Uint8Array, label: String, urefs: Array‹URef›): void

    Defined in index.ts:644

    Parameters:

    Name Type
    packageHash Uint8Array
    label String
    urefs Array‹URef

    Returns: void


    removeKey

    removeKey(name: String): void

    Defined in index.ts:337

    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:

    Name Type
    name String

    Returns: void


    ret

    ret(value: CLValue): void

    Defined in index.ts:246

    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:

    Name Type
    value CLValue

    Returns: void


    Runtime Functions

    putKey

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

    Defined in index.ts:195

    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:

    Name Type
    name String
    key Key

    Returns: void

    Module: "key"

    Index

    Enumerations

    Classes

    Module: "option"

    Index

    Classes

    Module: "pair"

    Index

    Classes

    Module: "public_key"

    Index

    Enumerations

    Classes

    Module: "purse"

    Index

    Enumerations

    Classes

    Functions

    Functions

    createPurse

    createPurse(): URef

    Defined in purse.ts:80

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

    Returns: URef


    getBalance

    getBalance(): U512 | null

    Defined in purse.ts:131

    Returns: U512 | null


    transferFromPurseToAccount

    transferFromPurseToAccount(sourcePurse: URef, targetAccount: Uint8Array, amount: U512, id: Ref‹u64› | null): TransferResult

    Defined in purse.ts:144

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

    Parameters:

    Name Type Default Description
    sourcePurse URef - -
    targetAccount Uint8Array - -
    amount U512 - Amount is denominated in motes
    id Ref‹u64› | null null -

    Returns: TransferResult

    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, id: Ref‹u64› | null): Error | null

    Defined in purse.ts:193

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

    Parameters:

    Name Type Default
    sourcePurse URef -
    targetPurse URef -
    amount U512 -
    id Ref‹u64› | null null

    Returns: Error | null

    This function returns non-zero value on error.


    transferToAccount

    transferToAccount(targetAccount: Uint8Array, amount: U512, id: Ref‹u64› | null): TransferResult

    Defined in purse.ts:250

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

    Parameters:

    Name Type Default Description
    targetAccount Uint8Array - -
    amount U512 - Amount is denominated in motes
    id Ref‹u64› | null null -

    Returns: TransferResult

    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.


    transferToPublicKey

    transferToPublicKey(targetPublicKey: PublicKey, amount: U512, id: Ref‹u64› | null): TransferResult

    Defined in purse.ts:299

    Transfers amount of motes from main purse to target public key. If account referenced by a target public key does not exist it will be created.

    Parameters:

    Name Type Default Description
    targetPublicKey PublicKey - -
    amount U512 - Amount is denominated in motes
    id Ref‹u64› | null null -

    Returns: TransferResult

    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.

    Module: "ref"

    Index

    Classes

    Module: "runtime"

    Index

    Functions

    Functions

    blake2b

    blake2b(data: Array‹u8›): Uint8Array

    Defined in runtime.ts:10

    Performs a blake2b hash using a host function.

    Parameters:

    Name Type Description
    data Array‹u8› Input bytes

    Returns: Uint8Array

    Module: "runtime_args"

    Index

    Classes

    Module: "unit"

    Index

    Classes

    Module: "uref"

    Index

    Enumerations

    Classes

    Module: "utils"

    Index

    Functions

    Functions

    arrayToTyped

    arrayToTyped(arr: Array‹u8›): Uint8Array

    Defined in utils.ts:20

    Converts array to typed array

    Parameters:

    Name Type
    arr Array‹u8›

    Returns: Uint8Array


    checkArraysEqual

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

    Defined in utils.ts:41

    Checks if two ordered arrays are equal

    Type parameters:

    T

    Parameters:

    Name Type Default
    a Array‹T› -
    b Array‹T› -
    len i32 0

    Returns: bool


    checkItemsEqual

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

    Defined in utils.ts:29

    Checks if items in two unordered arrays are equal

    Type parameters:

    T

    Parameters:

    Name Type
    a Array‹T›
    b Array‹T›

    Returns: bool


    checkTypedArrayEqual

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

    Defined in utils.ts:58

    Checks if two ordered arrays are equal

    Parameters:

    Name Type Default
    a Uint8Array -
    b Uint8Array -
    len i32 0

    Returns: bool


    encodeUTF8

    encodeUTF8(str: String): Uint8Array

    Defined in utils.ts:5

    Encodes an UTF8 string into bytes.

    Parameters:

    Name Type Description
    str String Input string.

    Returns: Uint8Array


    typedToArray

    typedToArray(arr: Uint8Array): Array‹u8›

    Defined in utils.ts:11

    Converts typed array to array

    Parameters:

    Name Type
    arr Uint8Array

    Returns: Array‹u8›

    Keywords

    none

    Install

    npm i casper-contract

    DownloadsWeekly Downloads

    43

    Version

    1.4.6

    License

    Apache-2.0

    Unpacked Size

    299 kB

    Total Files

    36

    Last publish

    Collaborators

    • casper-sre