
Research
Malicious npm Packages Impersonate Flashbots SDKs, Targeting Ethereum Wallet Credentials
Four npm packages disguised as cryptographic tools steal developer credentials and send them to attacker-controlled Telegram infrastructure.
@casperlabs/contract
Advanced tools
This package allows a distributed app developer to create smart contracts for the open source CasperLabs project using AssemblyScript.
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
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"
]
}
Create a assembly/index.ts
file. This is where the code for your contract will go.
You can use the following sample snippet which demonstrates a very simple smart contract that immediately returns an error, which will write a message to a block if executed on the CasperLabs platform.
//@ts-nocheck
import {Error, ErrorCode} from "@casperlabs/contract/error";
// simplest possible feedback loop
export function call(): void {
Error.fromErrorCode(ErrorCode.None).revert(); // ErrorCode: 1
}
If you prefer a more complicated first contract, you can look at client contracts on the CasperLabs github repository for inspiration.
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
An implementation of 512-bit unsigned integers.
+ new U512(): U512
Defined in bignum.ts:31
Constructs a new instance of U512.
Returns: U512
• 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).
Defined in bignum.ts:146
The addition operator - adds two U512 numbers together.
Parameters:
Name | Type |
---|---|
other | U512 |
Returns: U512
▸ bits(): u32
Defined in bignum.ts:282
Returns length of the integer in bits (not counting the leading zero bits).
Returns: u32
▸ clone(): U512
Defined in bignum.ts:273
Clones the U512.
Returns: U512
▸ cmp(other
: U512): i32
Defined in bignum.ts:406
Compares this
and other
.
Parameters:
Name | Type | Description |
---|---|---|
other | U512 | The number to compare this to. |
Returns: i32
-1 if this
is less than other
, 1 if this
is greater than other
, 0 if this
and other
are equal.
Defined in bignum.ts:339
The division operator - divides the arguments.
Parameters:
Name | Type |
---|---|
other | U512 |
Returns: U512
▸ divMod(other
: U512): Pair‹U512, U512› | null
Defined in bignum.ts:298
Performs the integer division of this/other
.
Parameters:
Name | Type | Description |
---|---|---|
other | U512 | The divisor. |
Returns: Pair‹U512, U512› | null
A pair consisting of the quotient and the remainder, or null if the divisor was 0.
▸ eq(other
: U512): bool
Defined in bignum.ts:425
The equality operator.
Parameters:
Name | Type |
---|---|
other | U512 |
Returns: bool
True if this
and other
are equal, false otherwise.
▸ gt(other
: U512): bool
Defined in bignum.ts:445
The greater-than operator.
Parameters:
Name | Type |
---|---|
other | U512 |
Returns: bool
True if this
is greater than other
, false otherwise.
▸ gte(other
: U512): bool
Defined in bignum.ts:465
The greater-than-or-equal operator.
Parameters:
Name | Type |
---|---|
other | U512 |
Returns: bool
True if this
is greater than or equal to other
, false otherwise.
▸ isZero(): 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(other
: U512): bool
Defined in bignum.ts:455
The less-than operator.
Parameters:
Name | Type |
---|---|
other | U512 |
Returns: bool
True if this
is less than other
, false otherwise.
▸ lte(other
: U512): bool
Defined in bignum.ts:475
The less-than-or-equal operator.
Parameters:
Name | Type |
---|---|
other | U512 |
Returns: bool
True if this
is less than or equal to other
, false otherwise.
Defined in bignum.ts:185
The multiplication operator - calculates the product of the two arguments.
Parameters:
Name | Type |
---|---|
other | U512 |
Returns: U512
▸ neg(): U512
Defined in bignum.ts:164
The negation operator - returns the two's complement of the argument.
Returns: U512
▸ neq(other
: U512): bool
Defined in bignum.ts:435
The not-equal operator.
Parameters:
Name | Type |
---|---|
other | U512 |
Returns: bool
False if this
and other
are equal, true otherwise.
▸ postfixDec(): U512
Defined in bignum.ts:253
Postfix operator --
- decrements this U512.
Returns: U512
▸ postfixInc(): U512
Defined in bignum.ts:243
Postfix operator ++
- increments this U512.
Returns: U512
▸ prefixDec(): U512
Defined in bignum.ts:234
Prefix operator --
- decrements this U512.
Returns: U512
▸ prefixInc(): U512
Defined in bignum.ts:225
Prefix operator ++
- increments this U512.
Returns: U512
Defined in bignum.ts:349
The 'modulo' operator - calculates the remainder from the division of the arguments.
Parameters:
Name | Type |
---|---|
other | U512 |
Returns: U512
▸ setBytesLE(bytes
: Uint8Array): void
Defined in bignum.ts:496
Sets the value of this U512 to the value represented by bytes
when treated as a
little-endian representation of a number.
Parameters:
Name | Type |
---|---|
bytes | Uint8Array |
Returns: void
▸ setHex(value
: String): void
Defined in bignum.ts:100
Sets the value of this U512 to a value represented by the given string of hex digits.
Parameters:
Name | Type | Description |
---|---|---|
value | String | The string of hex digits representing the desired value. |
Returns: void
▸ setU64(value
: u64): void
Defined in bignum.ts:88
Sets the value of this U512 to a given 64-bit value.
Parameters:
Name | Type | Description |
---|---|---|
value | u64 | The desired new value of this U512. |
Returns: void
▸ setValues(pn
: Uint32Array): void
Defined in bignum.ts:264
Sets the values of the internally kept 32-bit "digits" (or "limbs") of the U512.
Parameters:
Name | Type | Description |
---|---|---|
pn | Uint32Array | The array of unsigned 32-bit integers to be used as the "digits"/"limbs". |
Returns: void
▸ shl(shift
: u32): U512
Defined in bignum.ts:359
The bitwise left-shift operator.
Parameters:
Name | Type |
---|---|
shift | u32 |
Returns: U512
▸ shr(shift
: u32): U512
Defined in bignum.ts:381
The bitwise right-shift operator.
Parameters:
Name | Type |
---|---|
shift | u32 |
Returns: U512
Defined in bignum.ts:177
The subtraction operator - subtracts the two U512s.
Parameters:
Name | Type |
---|---|
other | U512 |
Returns: U512
▸ toBytes(): Array‹u8›
Defined in bignum.ts:578
Serializes the U512 into an array of bytes that represents it in the CasperLabs serialization format.
Returns: Array‹u8›
▸ toBytesLE(): 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(): String
Defined in bignum.ts:539
An alias for [[toHex]].
Returns: String
Static
fromBytes▸ fromBytes(bytes
: Uint8Array): Result‹U512›
Defined in bignum.ts:550
Deserializes a U512 from an array of bytes. The array should represent a correct U512 in the CasperLabs serialization format.
Parameters:
Name | Type |
---|---|
bytes | Uint8Array |
A Result that contains the deserialized U512 if the deserialization was successful, or an error otherwise.
Static
fromHex▸ fromHex(hex
: String): U512
Defined in bignum.ts:59
Constructs a new U512 from a string of hex digits.
Parameters:
Name | Type |
---|---|
hex | String |
Returns: U512
Static
fromU64▸ fromU64(value
: u64): U512
Defined in bignum.ts:70
Converts a 64-bit unsigned integer into a U512.
Parameters:
Name | Type | Description |
---|---|---|
value | u64 | The value to be converted. |
Returns: U512
Boxes a value which could then be nullable in any context.
▪ T
+ new Ref(value
: T): Ref
Defined in bytesrepr.ts:8
Parameters:
Name | Type |
---|---|
value | T |
Returns: Ref
• value: T
Defined in bytesrepr.ts:9
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.
▪ T
+ new Result(ref
: Ref‹T› | null, error
: Error, position
: u32): Result
Defined in bytesrepr.ts:53
Creates new Result with wrapped value
Parameters:
Name | Type | Description |
---|---|---|
ref | Ref‹T› | null | - |
error | Error | Error value |
position | u32 | Position of input stream |
Returns: Result
• error: Error
Defined in bytesrepr.ts:60
Error value
• position: u32
Defined in bytesrepr.ts:60
Position of input stream
• ref: Ref‹T› | null
Defined in bytesrepr.ts:60
• get value(): T
Defined in bytesrepr.ts:65
Assumes that reference wrapper contains a value and then returns it
Returns: T
▸ hasError(): bool
Defined in bytesrepr.ts:83
Checks if error value is set.
Truth also implies !hasValue(), false value implies hasValue()
Returns: bool
▸ hasValue(): bool
Defined in bytesrepr.ts:74
Checks if given Result contains a value
Returns: bool
▸ ok(): T | null
Defined in bytesrepr.ts:90
For nullable types, this returns the value itself, or a null.
Returns: T | null
▸ unwrap(): T
Defined in bytesrepr.ts:97
Returns success value, or reverts error value.
Returns: T
+ new CLType(tag
: CLTypeTag, extra
: Array‹u8› | null): CLType
Defined in clvalue.ts:63
Parameters:
Name | Type | Default |
---|---|---|
tag | CLTypeTag | - |
extra | Array‹u8› | null | null |
Returns: CLType
• bytes: Array‹u8›
Defined in clvalue.ts:63
• tag: CLTypeTag
Defined in clvalue.ts:62
▸ toBytes(): u8[]
Defined in clvalue.ts:90
Returns: u8[]
Static
fixedList▸ fixedList(typeTag
: CLType, size
: u32): CLType
Defined in clvalue.ts:73
Parameters:
Name | Type |
---|---|
typeTag | CLType |
size | u32 |
Returns: CLType
Static
list▸ list(typeTag
: CLType): CLType
Defined in clvalue.ts:82
Parameters:
Name | Type |
---|---|
typeTag | CLType |
Returns: CLType
Static
option▸ option(typeTag
: CLType): CLType
Defined in clvalue.ts:86
Parameters:
Name | Type |
---|---|
typeTag | CLType |
Returns: CLType
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.
+ new CLValue(bytes
: u8[], clType
: CLType): CLValue
Defined in clvalue.ts:103
Constructs a new CLValue
with given underlying data and type.
Parameters:
Name | Type |
---|---|
bytes | u8[] |
clType | CLType |
Returns: CLValue
• bytes: u8[]
Defined in clvalue.ts:102
• clType: CLType
Defined in clvalue.ts:103
▸ toBytes(): u8[]
Defined in clvalue.ts:172
Serializes a CLValue
into an array of bytes.
Returns: u8[]
Static
fromI32▸ fromI32(value
: i32): CLValue
Defined in clvalue.ts:130
Creates a CLValue
holding a signed 32-bit integer.
Parameters:
Name | Type |
---|---|
value | i32 |
Returns: CLValue
Static
fromKeyDefined in clvalue.ts:144
Creates a CLValue
holding a Key.
Parameters:
Name | Type |
---|---|
key | Key |
Returns: CLValue
Static
fromOption▸ fromOption(value
: Option, nestedT
: CLType): CLValue
Defined in clvalue.ts:165
Creates a CLValue
holding an Option.
Parameters:
Name | Type |
---|---|
value | Option |
nestedT | CLType |
Returns: CLValue
Static
fromString▸ fromString(s
: String): CLValue
Defined in clvalue.ts:116
Creates a CLValue
holding a string.
Parameters:
Name | Type |
---|---|
s | String |
Returns: CLValue
Static
fromStringList▸ fromStringList(values
: String[]): CLValue
Defined in clvalue.ts:158
Creates a CLValue
holding a list of strings.
Parameters:
Name | Type |
---|---|
values | String[] |
Returns: CLValue
Static
fromU512▸ fromU512(value
: U512): CLValue
Defined in clvalue.ts:123
Creates a CLValue
holding an unsigned 512-bit integer.
Parameters:
Name | Type |
---|---|
value | U512 |
Returns: CLValue
Static
fromU64▸ fromU64(value
: u64): CLValue
Defined in clvalue.ts:137
Creates a CLValue
holding an unsigned 64-bit integer.
Parameters:
Name | Type |
---|---|
value | u64 |
Returns: CLValue
Static
fromURef▸ fromURef(uref
: URef): CLValue
Defined in clvalue.ts:151
Creates a CLValue
holding a URef.
Parameters:
Name | Type |
---|---|
uref | URef |
Returns: CLValue
This class represents error condition and is constructed by passing an error value.
The variants are split into numeric ranges as follows:
Inclusive range | Variant(s) |
---|---|
[1, 65023] | all except Mint , ProofOfStake and User . Can be created with Error.fromErrorCode |
[65024, 65279] | Mint - instantiation currently unsupported |
[65280, 65535] | ProofOfStake errors |
[65536, 131071] | User error codes created with Error.fromUserError |
// 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();
+ 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
▸ isSystemContractError(): bool
Defined in error.ts:183
Checks if error value is contained within system contract error range.
Returns: bool
▸ isUserError(): bool
Defined in error.ts:176
Checks if error value is contained within user error range.
Returns: bool
▸ revert(): void
Defined in error.ts:190
Reverts execution of current contract with an error value contained within this error instance.
Returns: void
▸ 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
+ new AddContractVersionResult(contractHash
: Uint8Array, contractVersion
: u32): AddContractVersionResult
Defined in index.ts:501
Parameters:
Name | Type |
---|---|
contractHash | Uint8Array |
contractVersion | u32 |
Returns: AddContractVersionResult
• contractHash: Uint8Array
Defined in index.ts:502
• contractVersion: u32
Defined in index.ts:502
A two-value structure that holds the result of createContractPackageAtHash.
+ new CreateContractPackageResult(packageHash
: Uint8Array, accessURef
: URef): CreateContractPackageResult
Defined in index.ts:436
Parameters:
Name | Type |
---|---|
packageHash | Uint8Array |
accessURef | URef |
Returns: CreateContractPackageResult
• accessURef: URef
Defined in index.ts:437
• packageHash: Uint8Array
Defined in index.ts:437
+ new EntryPoint(name
: String, args
: Array‹Pair‹String, CLType››, ret
: CLType, access
: EntryPointAccess, entry_point_type
: EntryPointType): EntryPoint
Defined in index.ts:404
Parameters:
Name | Type |
---|---|
name | String |
args | Array‹Pair‹String, CLType›› |
ret | CLType |
access | EntryPointAccess |
entry_point_type | EntryPointType |
Returns: EntryPoint
• access: EntryPointAccess
Defined in index.ts:408
• args: Array‹Pair‹String, CLType››
Defined in index.ts:406
• entry_point_type: EntryPointType
Defined in index.ts:409
• name: String
Defined in index.ts:405
• ret: CLType
Defined in index.ts:407
▸ toBytes(): Array‹u8›
Defined in index.ts:411
Returns: Array‹u8›
EntryPointAccess
+ new EntryPointAccess(cachedBytes
: Array‹u8›): EntryPointAccess
Defined in index.ts:377
Parameters:
Name | Type |
---|---|
cachedBytes | Array‹u8› |
Returns: EntryPointAccess
• cachedBytes: Array‹u8›
Defined in index.ts:378
▸ toBytes(): Array‹u8›
Defined in index.ts:379
Returns: Array‹u8›
• entryPoints: Array‹Pair‹String, EntryPoint›› = new Array<Pair<String, EntryPoint>>()
Defined in index.ts:423
▸ addEntryPoint(entryPoint
: EntryPoint): void
Defined in index.ts:424
Parameters:
Name | Type |
---|---|
entryPoint | EntryPoint |
Returns: void
▸ toBytes(): Array‹u8›
Defined in index.ts:427
Returns: Array‹u8›
↳ GroupAccess
+ new GroupAccess(groups
: String[]): GroupAccess
Overrides EntryPointAccess.constructor
Defined in index.ts:390
Parameters:
Name | Type |
---|---|
groups | String[] |
Returns: GroupAccess
• cachedBytes: Array‹u8›
Inherited from EntryPointAccess.cachedBytes
Defined in index.ts:378
▸ toBytes(): Array‹u8›
Inherited from EntryPointAccess.toBytes
Defined in index.ts:379
Returns: Array‹u8›
↳ PublicAccess
+ new PublicAccess(): PublicAccess
Overrides EntryPointAccess.constructor
Defined in index.ts:384
Returns: PublicAccess
• cachedBytes: Array‹u8›
Inherited from EntryPointAccess.cachedBytes
Defined in index.ts:378
▸ toBytes(): Array‹u8›
Inherited from EntryPointAccess.toBytes
Defined in index.ts:379
Returns: Array‹u8›
A cryptographic public key.
+ new AccountHash(bytes
: Uint8Array): AccountHash
Defined in key.ts:23
Constructs a new AccountHash
.
Parameters:
Name | Type | Description |
---|---|---|
bytes | Uint8Array | The bytes constituting the public key. |
Returns: AccountHash
• bytes: Uint8Array
Defined in key.ts:29
The bytes constituting the public key.
▸ equalsTo(other
: AccountHash): bool
Defined in key.ts:33
Checks whether two AccountHash
s are equal.
Parameters:
Name | Type |
---|---|
other | AccountHash |
Returns: bool
▸ notEqualsTo(other
: AccountHash): bool
Defined in key.ts:39
Checks whether two AccountHash
s are not equal.
Parameters:
Name | Type |
---|---|
other | AccountHash |
Returns: bool
▸ toBytes(): Array‹u8›
Defined in key.ts:56
Serializes a AccountHash
into an array of bytes.
Returns: Array‹u8›
Static
fromBytes▸ fromBytes(bytes
: Uint8Array): Result‹AccountHash›
Defined in key.ts:44
Deserializes a AccountHash
from an array of bytes.
Parameters:
Name | Type |
---|---|
bytes | Uint8Array |
Returns: Result‹AccountHash›
The type under which data (e.g. CLValues, smart contracts, user accounts) are indexed on the network.
• account: AccountHash | null
Defined in key.ts:69
• hash: Uint8Array | null
Defined in key.ts:67
• uref: URef | null
Defined in key.ts:68
• variant: KeyVariant
Defined in key.ts:66
▸ add(value
: CLValue): void
Defined in key.ts:225
Adds the given CLValue
to a value already stored under this Key
.
Parameters:
Name | Type |
---|---|
value | CLValue |
Returns: void
▸ equalsTo(other
: Key): bool
Defined in key.ts:239
Checks whether two Key
s are equal.
Parameters:
Name | Type |
---|---|
other | Key |
Returns: bool
▸ isURef(): bool
Defined in key.ts:186
Checks whether the Key
is of KeyVariant.UREF_ID.
Returns: bool
▸ notEqualsTo(other
: Key): bool
Defined in key.ts:272
Checks whether two keys are not equal.
Parameters:
Name | Type |
---|---|
other | Key |
Returns: bool
▸ read(): Uint8Array | null
Defined in key.ts:196
Reads the data stored under this Key
.
Returns: Uint8Array | null
▸ toBytes(): Array‹u8›
Defined in key.ts:158
Serializes a Key
into an array of bytes.
Returns: Array‹u8›
▸ toURef(): URef
Defined in key.ts:191
Converts the Key
into URef
.
Returns: URef
▸ write(value
: CLValue): void
Defined in key.ts:213
Stores a CLValue under this Key
.
Parameters:
Name | Type |
---|---|
value | CLValue |
Returns: void
Static
create▸ create(value
: CLValue): Key | null
Defined in key.ts:100
Attempts to write value
under a new Key::URef
If a key is returned it is always of KeyVariant.UREF_ID
Parameters:
Name | Type |
---|---|
value | CLValue |
Returns: Key | null
Static
fromAccount▸ fromAccount(account
: AccountHash): Key
Defined in key.ts:88
Creates a Key
from a [[]] representing an account.
Parameters:
Name | Type |
---|---|
account | AccountHash |
Returns: Key
Static
fromBytes▸ fromBytes(bytes
: Uint8Array): Result‹Key›
Defined in key.ts:116
Deserializes a Key
from an array of bytes.
Parameters:
Name | Type |
---|---|
bytes | Uint8Array |
Static
fromHash▸ fromHash(hash
: Uint8Array): Key
Defined in key.ts:80
Creates a Key
from a given hash.
Parameters:
Name | Type |
---|---|
hash | Uint8Array |
Returns: Key
Static
fromURefDefined in key.ts:72
Creates a Key
from a given URef.
Parameters:
Name | Type |
---|---|
uref | URef |
Returns: Key
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
.
+ 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
▸ isNone(): bool
Defined in option.ts:25
Checks whether the Option
contains no value.
Returns: bool
True if the Option
has no value.
▸ isSome(): bool
Defined in option.ts:34
Checks whether the Option
contains a value.
Returns: bool
True if the Option
has some value.
▸ toBytes(): Array‹u8›
Defined in option.ts:50
Serializes the Option
into an array of bytes.
Returns: Array‹u8›
▸ unwrap(): Uint8Array | null
Defined in option.ts:43
Unwraps the Option
, returning the inner value (or null
if there was none).
Returns: Uint8Array | null
The inner value, or null
if there was none.
Static
fromBytes▸ fromBytes(bytes
: Uint8Array): Option
Defined in option.ts:70
Deserializes an array of bytes into an Option
.
Parameters:
Name | Type |
---|---|
bytes | Uint8Array |
Returns: Option
A pair of values.
▪ T1
The type of the first value.
▪ T2
The type of the second value.
+ 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
• first: T1
Defined in pair.ts:11
The first value in the pair.
• second: T2
Defined in pair.ts:15
The second value in the pair.
▸ 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(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
Implements a collection of runtime arguments.
+ new RuntimeArgs(arguments
: Pair‹String, CLValue›[]): RuntimeArgs
Defined in runtime_args.ts:8
Parameters:
Name | Type | Default |
---|---|---|
arguments | Pair‹String, CLValue›[] | [] |
Returns: RuntimeArgs
• arguments: Pair‹String, CLValue›[]
Defined in runtime_args.ts:9
▸ 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
A class representing the unit type, i.e. a type that has no values (equivalent to eg. void
in
C or ()
in Rust).
▸ 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
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.
+ new URef(bytes
: Uint8Array, accessRights
: AccessRights): URef
Defined in uref.ts:55
Constructs new instance of URef.
Parameters:
Name | Type | Description |
---|---|---|
bytes | Uint8Array | Bytes representing address of the URef. |
accessRights | AccessRights | Access rights flag. Use AccessRights.NONE to indicate no permissions. |
Returns: URef
▸ equalsTo(other
: URef): bool
Defined in uref.ts:129
The equality operator.
Parameters:
Name | Type |
---|---|
other | URef |
Returns: bool
True if this
and other
are equal, false otherwise.
▸ getAccessRights(): AccessRights
Defined in uref.ts:79
Returns the access rights of this URef.
Returns: AccessRights
▸ 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(): boolean
Defined in uref.ts:86
Validates uref against named keys.
Returns: boolean
▸ notEqualsTo(other
: URef): bool
Defined in uref.ts:139
The not-equal operator.
Parameters:
Name | Type |
---|---|
other | URef |
Returns: bool
False if this
and other
are equal, true otherwise.
▸ 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): Result‹URef›
Defined in uref.ts:99
Deserializes a new URef from bytes.
Parameters:
Name | Type | Description |
---|---|---|
bytes | Uint8Array | Input bytes. Requires at least 33 bytes to properly deserialize an URef. |
Enum representing an action for which a threshold is being set.
• Deployment: = 0
Defined in account.ts:106
Required by deploy execution.
• KeyManagement: = 1
Defined in account.ts:110
Required when adding/removing associated keys, changing threshold levels.
Enum representing the possible results of adding an associated key to an account.
• DuplicateKey: = 2
Defined in account.ts:22
Unable to add new associated key because given key already exists
• MaxKeysLimit: = 1
Defined in account.ts:18
Unable to add new associated key because maximum amount of keys is reached
• Ok: = 0
Defined in account.ts:14
Success
• PermissionDenied: = 3
Defined in account.ts:26
Unable to add new associated key due to insufficient permissions
Enum representing the possible results of removing an associated key from an account.
• MissingKey: = 1
Defined in account.ts:62
Key does not exist in the list of associated keys.
• Ok: = 0
Defined in account.ts:58
Success
• PermissionDenied: = 2
Defined in account.ts:66
Unable to remove the associated key due to insufficient permissions
• ThresholdViolation: = 3
Defined in account.ts:70
Unable to remove a key which would violate action threshold constraints
Enum representing the possible results of setting the threshold of an account.
• DeploymentThreshold: = 2
Defined in account.ts:88
New threshold should be lower or equal than key management threshold
• InsufficientTotalWeight: = 4
Defined in account.ts:96
New threshold should be lower or equal than total weight of associated keys
• KeyManagementThreshold: = 1
Defined in account.ts:84
New threshold should be lower or equal than deployment threshold
• Ok: = 0
Defined in account.ts:80
Success
• PermissionDeniedError: = 3
Defined in account.ts:92
Unable to set action threshold due to insufficient permissions
Enum representing the possible results of updating an associated key of an account.
• MissingKey: = 1
Defined in account.ts:40
Key does not exist in the list of associated keys.
• Ok: = 0
Defined in account.ts:36
Success
• PermissionDenied: = 2
Defined in account.ts:44
Unable to update the associated key due to insufficient permissions
• ThresholdViolation: = 3
Defined in account.ts:48
Unable to update weight that would fall below any of action thresholds
Enum representing possible results of deserialization.
• EarlyEndOfStream: = 1
Defined in bytesrepr.ts:24
Early end of stream
• FormattingError: = 2
Defined in bytesrepr.ts:28
Unexpected data encountered while decoding byte stream
• Ok: = 0
Defined in bytesrepr.ts:20
Last operation was a success
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.
• Any: = 21
Defined in clvalue.ts:58
A value of any type.
• Bool: = 0
Defined in clvalue.ts:14
A boolean value
• Fixed_list: = 15
Defined in clvalue.ts:44
A fixed-length list of values
• I32: = 1
Defined in clvalue.ts:16
A 32-bit signed integer
• I64: = 2
Defined in clvalue.ts:18
A 64-bit signed integer
• Key: = 11
Defined in clvalue.ts:36
A key in the global state - URef/hash/etc.
• List: = 14
Defined in clvalue.ts:42
A list of values
• Map: = 17
Defined in clvalue.ts:50
A key-value map.
• Option: = 13
Defined in clvalue.ts:40
An Option, i.e. a type that can contain a value or nothing at all
• 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: = 10
Defined in clvalue.ts:34
A string of characters
• Tuple1: = 18
Defined in clvalue.ts:52
A 1-value tuple.
• Tuple2: = 19
Defined in clvalue.ts:54
A 2-value tuple, i.e. a pair of values.
• Tuple3: = 20
Defined in clvalue.ts:56
A 3-value tuple.
• U128: = 6
Defined in clvalue.ts:26
A 128-bit unsigned integer
• U256: = 7
Defined in clvalue.ts:28
A 256-bit unsigned integer
• U32: = 4
Defined in clvalue.ts:22
A 32-bit unsigned integer
• U512: = 8
Defined in clvalue.ts:30
A 512-bit unsigned integer
• U64: = 5
Defined in clvalue.ts:24
A 64-bit unsigned integer
• U8: = 3
Defined in clvalue.ts:20
An 8-bit unsigned integer (a byte)
• 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: = 12
Defined in clvalue.ts:38
An Unforgeable Reference (URef)
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.
• BufferTooSmall: = 32
Defined in error.ts:84
The provided buffer is too small to complete an operation.
• CLTypeMismatch: = 16
Defined in error.ts:52
A given type could not be constructed from a CLValue.
• ContractNotFound: = 7
Defined in error.ts:34
Failed to find a specified contract.
• DeploymentThreshold: = 27
Defined in error.ts:74
Setting the deployment threshold to a value greater than any other threshold is disallowed.
• Deserialize: = 4
Defined in error.ts:28
Failed to deserialize a value.
• DuplicateKey: = 22
Defined in error.ts:64
The given public key is already associated with the given account.
• EarlyEndOfStream: = 17
Defined in error.ts:54
Early end of stream while deserializing.
• Formatting: = 18
Defined in error.ts:56
Formatting error while deserializing.
• GetKey: = 8
Defined in error.ts:36
A call to getKey returned a failure.
• HostBufferEmpty: = 33
Defined in error.ts:86
No data available in the host buffer.
• 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: = 28
Defined in error.ts:76
Setting a threshold to a value greater than the total weight of associated keys is disallowed.
• InvalidArgument: = 3
Defined in error.ts:26
Argument not of correct type.
• InvalidPurse: = 12
Defined in error.ts:44
Invalid purse retrieved.
• InvalidPurseName: = 11
Defined in error.ts:42
Invalid purse name given.
• InvalidSystemContract: = 29
Defined in error.ts:78
The given u32
doesn't map to a [[SystemContractType]].
• KeyManagementThreshold: = 26
Defined in error.ts:72
Setting the key-management threshold to a value lower than the deployment threshold is disallowed.
• LeftOverBytes: = 19
Defined in error.ts:58
Not all input bytes were consumed in deserializing operation
• MaxKeysLimit: = 21
Defined in error.ts:62
There are already maximum public keys associated with the given account.
• MissingArgument: = 2
Defined in error.ts:24
Specified argument not provided.
• MissingKey: = 24
Defined in error.ts:68
The given public key is not associated with the given account.
• NoAccessRights: = 15
Defined in error.ts:50
The given URef has no access rights.
• None: = 1
Defined in error.ts:22
Optional data was unexpectedly None
.
• OutOfMemory: = 20
Defined in error.ts:60
Out of memory error.
• PermissionDenied: = 23
Defined in error.ts:66
Caller doesn't have sufficient permissions to perform the given action.
• PurseNotCreated: = 30
Defined in error.ts:80
Failed to create a new purse.
• Read: = 5
Defined in error.ts:30
casperlabs_contract::storage::read()
returned an error.
• ThresholdViolation: = 25
Defined in error.ts:70
Removing/updating the given associated public key would cause the total weight of all remaining AccountHash
s to fall below one of the action thresholds for the given account.
• Transfer: = 14
Defined in error.ts:48
Failed to transfer motes.
• UnexpectedContractRefVariant: = 10
Defined in error.ts:40
The Contract
variant was not as expected.
• UnexpectedKeyVariant: = 9
Defined in error.ts:38
The Key variant was not as expected.
• Unhandled: = 31
Defined in error.ts:82
An unhandled value, likely representing a bug in the code.
• UpgradeContractAtURef: = 13
Defined in error.ts:46
Failed to upgrade contract at URef.
• ValueNotFound: = 6
Defined in error.ts:32
The given key returned a None
value.
• Contract: = 1
Defined in index.ts:401
• Session: = 0
Defined in index.ts:400
The phase in which a given contract is executing.
• FinalizePayment: = 3
Defined in index.ts:314
Set while finalizing payment at the end of a deploy.
• Payment: = 1
Defined in index.ts:306
Set while executing the payment code of a deploy.
• Session: = 2
Defined in index.ts:310
Set while executing the session code of a deploy.
• System: = 0
Defined in index.ts:302
Set while committing the genesis or upgrade configurations.
System contract types.
• Mint: = 0
Defined in index.ts:39
Mint contract.
• ProofOfStake: = 1
Defined in index.ts:43
Proof of Stake contract.
• StandardPayment: = 2
Defined in index.ts:47
Standard Payment contract.
Enum representing a variant of a Key - Account, Hash or URef.
• ACCOUNT_ID: = 0
Defined in key.ts:15
The Account variant
• HASH_ID: = 1
Defined in key.ts:17
The Hash variant
• UREF_ID: = 2
Defined in key.ts:19
The URef variant
The result of a successful transfer between purses.
• ExistingAccount: = 0
Defined in purse.ts:19
The destination account already existed.
• NewAccount: = 1
Defined in purse.ts:23
The destination account was created.
• TransferError: = -1
Defined in purse.ts:15
The transfer operation resulted in an error.
A set of bitflags that defines access rights associated with a URef.
• ADD: = 4
Defined in uref.ts:29
Permission to add to the value under the associated URef.
• ADD_WRITE: = 6
Defined in uref.ts:37
Permission to add to, or write the value under the associated URef.
• NONE: = 0
Defined in uref.ts:13
No permissions
• READ: = 1
Defined in uref.ts:17
Permission to read the value under the associated URef.
• READ_ADD: = 5
Defined in uref.ts:33
Permission to read or add to the value under the associated URef.
• READ_ADD_WRITE: = 7
Defined in uref.ts:41
Permission to read, add to, or write the value under the associated URef.
• READ_WRITE: = 3
Defined in uref.ts:25
Permission to read or write the value under the associated URef.
• WRITE: = 2
Defined in uref.ts:21
Permission to write a value under the associated URef.
▸ 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(): 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(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(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(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.
▸ fromBytesArray<T>(bytes
: Uint8Array, decodeItem
: function): Result‹Array‹T››
Defined in bytesrepr.ts:356
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(bytes
: Uint8Array): Result‹Array‹u8››
Defined in bytesrepr.ts:320
Deserializes an array of bytes.
Parameters:
Name | Type |
---|---|
bytes | Uint8Array |
Returns: Result‹Array‹u8››
▸ fromBytesI32(bytes
: Uint8Array): Result‹i32›
Defined in bytesrepr.ts:174
Deserializes an i32
from an array of bytes.
Parameters:
Name | Type |
---|---|
bytes | Uint8Array |
Returns: Result‹i32›
▸ fromBytesLoad<T>(bytes
: Uint8Array): Result‹T›
Defined in bytesrepr.ts:122
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<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:
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(s
: Uint8Array): Result‹String›
Defined in bytesrepr.ts:289
Deserializes a string from an array of bytes.
Parameters:
Name | Type |
---|---|
s | Uint8Array |
Returns: Result‹String›
▸ fromBytesStringList(bytes
: Uint8Array): Result‹Array‹String››
Defined in bytesrepr.ts:385
Deserializes a list of strings from an array of bytes.
Parameters:
Name | Type |
---|---|
bytes | Uint8Array |
Returns: Result‹Array‹String››
▸ fromBytesU32(bytes
: Uint8Array): Result‹u32›
Defined in bytesrepr.ts:154
Deserializes a u32
from an array of bytes.
Parameters:
Name | Type |
---|---|
bytes | Uint8Array |
Returns: Result‹u32›
▸ fromBytesU64(bytes
: Uint8Array): Result‹u64›
Defined in bytesrepr.ts:194
Deserializes a u64
from an array of bytes.
Parameters:
Name | Type |
---|---|
bytes | Uint8Array |
Returns: Result‹u64›
▸ fromBytesU8(bytes
: Uint8Array): Result‹u8›
Defined in bytesrepr.ts:134
Deserializes a u8
from an array of bytes.
Parameters:
Name | Type |
---|---|
bytes | Uint8Array |
Returns: Result‹u8›
▸ toBytesArrayU8(arr
: Array‹u8›): u8[]
Defined in bytesrepr.ts:312
Serializes an array of bytes.
Parameters:
Name | Type |
---|---|
arr | Array‹u8› |
Returns: u8[]
▸ toBytesI32(num
: i32): u8[]
Defined in bytesrepr.ts:161
Converts i32
to little endian.
Parameters:
Name | Type |
---|---|
num | i32 |
Returns: u8[]
▸ toBytesMap<K, V>(vecOfPairs
: Array‹Pair‹K, V››, serializeKey
: function, serializeValue
: function): Array‹u8›
Defined in bytesrepr.ts:212
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(key
: u8[], value
: u8[]): u8[]
Defined in bytesrepr.ts:201
Joins a pair of byte arrays into a single array.
Parameters:
Name | Type |
---|---|
key | u8[] |
value | u8[] |
Returns: u8[]
▸ toBytesString(s
: String): u8[]
Defined in bytesrepr.ts:281
Serializes a string into an array of bytes.
Parameters:
Name | Type |
---|---|
s | String |
Returns: u8[]
▸ toBytesStringList(arr
: String[]): u8[]
Defined in bytesrepr.ts:392
Serializes a list of strings into an array of bytes.
Parameters:
Name | Type |
---|---|
arr | String[] |
Returns: u8[]
▸ toBytesU32(num
: u32): u8[]
Defined in bytesrepr.ts:141
Converts u32
to little endian.
Parameters:
Name | Type |
---|---|
num | u32 |
Returns: u8[]
▸ toBytesU64(num
: u64): u8[]
Defined in bytesrepr.ts:181
Converts u64
to little endian.
Parameters:
Name | Type |
---|---|
num | u64 |
Returns: u8[]
▸ toBytesU8(num
: u8): u8[]
Defined in bytesrepr.ts:113
Serializes an u8
as an array of bytes.
Parameters:
Name | Type |
---|---|
num | u8 |
Returns: u8[]
An array containing a single byte: num
.
▸ toBytesVecT<T>(ts
: Array‹T›, encodeItem
: function): Array‹u8›
Defined in bytesrepr.ts:341
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›
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
▸ load_named_keys(total_keys
: usize, result_size
: usize): i32
Defined in externals.ts:23
Parameters:
Name | Type |
---|---|
total_keys | usize |
result_size | usize |
Returns: i32
▸ addContractVersion(packageHash
: Uint8Array, entryPoints
: EntryPoints, namedKeys
: Array‹Pair‹String, Key››): AddContractVersionResult
Defined in index.ts:507
Parameters:
Name | Type |
---|---|
packageHash | Uint8Array |
entryPoints | EntryPoints |
namedKeys | Array‹Pair‹String, Key›› |
Returns: AddContractVersionResult
▸ callContract(contractHash
: Uint8Array, entryPointName
: String, runtimeArgs
: RuntimeArgs): Uint8Array
Defined in index.ts:153
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(packageHash
: Uint8Array, contract_version
: Option, entryPointName
: String, runtimeArgs
: RuntimeArgs): Uint8Array
Defined in index.ts:470
Parameters:
Name | Type |
---|---|
packageHash | Uint8Array |
contract_version | Option |
entryPointName | String |
runtimeArgs | RuntimeArgs |
Returns: Uint8Array
▸ createContractPackageAtHash(): CreateContractPackageResult
Defined in index.ts:440
Returns: CreateContractPackageResult
▸ createContractUserGroup(packageHash
: Uint8Array, label
: String, newURefs
: u8, existingURefs
: Array‹URef›): Array‹URef›
Defined in index.ts:538
Parameters:
Name | Type |
---|---|
packageHash | Uint8Array |
label | String |
newURefs | u8 |
existingURefs | Array‹URef› |
Returns: Array‹URef›
▸ extendContractUserGroupURefs(packageHash
: Uint8Array, label
: String): URef
Defined in index.ts:588
Parameters:
Name | Type |
---|---|
packageHash | Uint8Array |
label | String |
Returns: URef
▸ getBlockTime(): u64
Defined in index.ts:268
Returns the current block time.
Returns: u64
▸ getCaller(): AccountHash
Defined in index.ts:278
Returns the caller of the current context, i.e. the AccountHash of the account which made the deploy request.
Returns: AccountHash
▸ getKey(name
: String): Key | null
Defined in index.ts:211
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(name
: String): Uint8Array
Defined in index.ts:85
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(name
: String): Ref‹U32› | null
Defined in index.ts:56
Returns size in bytes of I-th parameter
internal
Parameters:
Name | Type |
---|---|
name | String |
▸ getPhase(): Phase
Defined in index.ts:320
Returns the current Phase.
Returns: Phase
▸ getSystemContract(systemContract
: SystemContract): Uint8Array
Defined in index.ts:131
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(name
: String): bool
Defined in index.ts:259
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(): Array‹Pair‹String, Key››
Defined in index.ts:346
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(entryPoints
: EntryPoints, namedKeys
: Array‹Pair‹String, Key›› | null, hashName
: String | null, urefName
: String | null): AddContractVersionResult
Defined in index.ts:450
Parameters:
Name | Type | Default |
---|---|---|
entryPoints | EntryPoints | - |
namedKeys | Array‹Pair‹String, Key›› | null | null |
hashName | String | null | null |
urefName | String | null | null |
Returns: AddContractVersionResult
▸ readHostBuffer(count
: u32): Uint8Array
Defined in index.ts:112
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(packageHash
: Uint8Array, label
: String): void
Defined in index.ts:571
Parameters:
Name | Type |
---|---|
packageHash | Uint8Array |
label | String |
Returns: void
▸ removeContractUserGroupURefs(packageHash
: Uint8Array, label
: String, urefs
: Array‹URef›): void
Defined in index.ts:609
Parameters:
Name | Type |
---|---|
packageHash | Uint8Array |
label | String |
urefs | Array‹URef› |
Returns: void
▸ removeKey(name
: String): void
Defined in index.ts:333
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(value
: CLValue): void
Defined in index.ts:242
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
▸ putKey(name
: String, key
: Key): void
Defined in index.ts:191
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
▸ 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:
Name | Type |
---|---|
local | Uint8Array |
value | CLValue |
Returns: void
▸ readLocal(local
: Uint8Array): Uint8Array | null
Defined in local.ts:13
Reads the value under key
in the context-local partition of global state.
Parameters:
Name | Type |
---|---|
local | Uint8Array |
Returns: Uint8Array | null
Returns bytes of serialized value, otherwise a null if given local key does not exists.
▸ writeLocal(local
: Uint8Array, value
: CLValue): void
Defined in local.ts:31
Writes value
under key
in the context-local partition of global state.
Parameters:
Name | Type |
---|---|
local | Uint8Array |
value | CLValue |
Returns: void
▸ 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(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:
Name | Type |
---|---|
purse | URef |
Returns: U512 | null
▸ 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:
Name | Type | Description |
---|---|---|
sourcePurse | URef | - |
targetAccount | Uint8Array | - |
amount | U512 | Amount 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(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:
Name | Type |
---|---|
sourcePurse | URef |
targetPurse | URef |
amount | U512 |
Returns: i32
This function returns non-zero value on error.
▸ arrayToTyped(arr
: Array‹u8›): Uint8Array
Defined in utils.ts:20
Converts array to typed array
Parameters:
Name | Type |
---|---|
arr | Array‹u8› |
Returns: Uint8Array
▸ 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<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(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(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(arr
: Uint8Array): Array‹u8›
Defined in utils.ts:11
Converts typed array to array
Parameters:
Name | Type |
---|---|
arr | Uint8Array |
Returns: Array‹u8›
FAQs
Library for developing CasperLabs smart contracts.
The npm package @casperlabs/contract receives a total of 0 weekly downloads. As such, @casperlabs/contract popularity was classified as not popular.
We found that @casperlabs/contract demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 2 open source maintainers collaborating on the project.
Did you know?
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.
Research
Four npm packages disguised as cryptographic tools steal developer credentials and send them to attacker-controlled Telegram infrastructure.
Security News
Ruby maintainers from Bundler and rbenv teams are building rv to bring Python uv's speed and unified tooling approach to Ruby development.
Security News
Following last week’s supply chain attack, Nx published findings on the GitHub Actions exploit and moved npm publishing to Trusted Publishers.