casperlabs-contract-test v0.2.0
@casperlabs/contract
This package allows a distributed app developer to create smart contracts for the open source CasperLabs project using AssemblyScript.
Installation
For each smart contract you create, make a project directory and initialize it.
mkdir project
cd project
npm init
npm init will prompt you for various details about your project;
answer as you see fit but you may safely default everything except name
which should follow the convention of
your-contract-name
.
Then install assembly script and this package in the project directory.
npm install --save-dev assemblyscript@0.9.1
npm install --save @casperlabs/contract
Usage
Add script entries for assembly script to your project's package.json
; note that your contract name is used
for the name of the wasm file.
{
"name": "your-contract-name",
...
"scripts": {
"asbuild:optimized": "asc assembly/index.ts -b dist/your-contract-name.wasm --validate --optimize --use abort=",
"asbuild": "npm run asbuild:optimized",
...
},
...
}
In your project root, create an index.js
file with the following contents:
const fs = require("fs");
const compiled = new WebAssembly.Module(fs.readFileSync(__dirname + "/dist/your-contract-name.wasm"));
const imports = {
env: {
abort(_msg, _file, line, column) {
console.error("abort called at index.ts:" + line + ":" + column);
}
}
};
Object.defineProperty(module, "exports", {
get: () => new WebAssembly.Instance(compiled, imports).exports
});
Create an assembly/tsconfig.json
file in the following way:
{
"extends": "../node_modules/assemblyscript/std/assembly.json",
"include": [
"./**/*.ts"
]
}
Sample smart contract
Create a assembly/index.ts
file. This is where the code for your contract will go.
You can use the following sample snippet which demonstrates a very simple smart contract that immediately returns an error, which will write a message to a block if executed on the CasperLabs platform.
//@ts-nocheck
import {Error, ErrorCode} from "@casperlabs/contract/error";
// simplest possible feedback loop
export function call(): void {
Error.fromErrorCode(ErrorCode.None).revert(); // ErrorCode: 1
}
If you prefer a more complicated first contract, you can look at example contracts on the CasperLabs github repository for inspiration.
Compile to wasm
To compile your contract to wasm, use npm to run the asbuild script from your project root.
npm run asbuild
If the build is successful, you should see a dist
folder in your root folder and in it
should be your-contract-name.wasm
casperlabs-contract-test
Index
Modules
- "account"
- "bignum"
- "bytesrepr"
- "clvalue"
- "constants"
- "error"
- "externals"
- "index"
- "key"
- "local"
- "option"
- "pair"
- "purse"
- "unit"
- "uref"
- "utils"
Classes
Class: U512
An implementation of 512-bit unsigned integers.
Hierarchy
- U512
Index
Constructors
Accessors
Methods
- add
- bits
- clone
- cmp
- div
- divMod
- eq
- gt
- gte
- isZero
- lt
- lte
- mul
- neg
- neq
- postfixDec
- postfixInc
- prefixDec
- prefixInc
- rem
- setBytesLE
- setHex
- setU64
- setValues
- shl
- shr
- sub
- toBytes
- toBytesLE
- toString
- fromBytes
- fromHex
- fromU64
Constructors
constructor
+ new U512(): U512
Defined in bignum.ts:31
Constructs a new instance of U512.
Returns: U512
Accessors
width
• get width(): i32
Defined in bignum.ts:79
Gets the width of the number in bytes.
Returns: i32
Static
MAX_VALUE
• get MAX_VALUE(): U512
Defined in bignum.ts:43
Returns: U512
The maximum possible value of a U512.
Static
MIN_VALUE
• get MIN_VALUE(): U512
Defined in bignum.ts:52
Returns: U512
The minimum possible value of a U512 (which is 0).
Methods
add
Defined in bignum.ts:146
The addition operator - adds two U512 numbers together.
Parameters:
Name | Type |
---|---|
other | U512 |
Returns: U512
bits
▸ bits(): u32
Defined in bignum.ts:282
Returns length of the integer in bits (not counting the leading zero bits).
Returns: u32
clone
▸ clone(): U512
Defined in bignum.ts:273
Clones the U512.
Returns: U512
cmp
▸ cmp(other
: U512): i32
Defined in bignum.ts:406
Compares this
and other
.
Parameters:
Name | Type | Description |
---|---|---|
other | U512 | The number to compare this to. |
Returns: i32
-1 if this
is less than other
, 1 if this
is greater than other
, 0 if this
and other
are equal.
div
Defined in bignum.ts:339
The division operator - divides the arguments.
Parameters:
Name | Type |
---|---|
other | U512 |
Returns: U512
divMod
▸ divMod(other
: U512): Pair‹U512, U512› | null
Defined in bignum.ts: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
▸ 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
▸ 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
▸ 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
▸ isZero(): bool
Defined in bignum.ts:133
Checks whether this U512 is equal to 0.
Returns: bool
True if this U512 is 0, false otherwise.
lt
▸ lt(other
: U512): bool
Defined in bignum.ts:455
The less-than operator.
Parameters:
Name | Type |
---|---|
other | U512 |
Returns: bool
True if this
is less than other
, false otherwise.
lte
▸ lte(other
: U512): bool
Defined in bignum.ts:475
The less-than-or-equal operator.
Parameters:
Name | Type |
---|---|
other | U512 |
Returns: bool
True if this
is less than or equal to other
, false otherwise.
mul
Defined in bignum.ts:185
The multiplication operator - calculates the product of the two arguments.
Parameters:
Name | Type |
---|---|
other | U512 |
Returns: U512
neg
▸ neg(): U512
Defined in bignum.ts:164
The negation operator - returns the two's complement of the argument.
Returns: U512
neq
▸ neq(other
: U512): bool
Defined in bignum.ts:435
The not-equal operator.
Parameters:
Name | Type |
---|---|
other | U512 |
Returns: bool
False if this
and other
are equal, true otherwise.
postfixDec
▸ postfixDec(): U512
Defined in bignum.ts:253
Postfix operator --
- decrements this U512.
Returns: U512
postfixInc
▸ postfixInc(): U512
Defined in bignum.ts:243
Postfix operator ++
- increments this U512.
Returns: U512
prefixDec
▸ prefixDec(): U512
Defined in bignum.ts:234
Prefix operator --
- decrements this U512.
Returns: U512
prefixInc
▸ prefixInc(): U512
Defined in bignum.ts:225
Prefix operator ++
- increments this U512.
Returns: U512
rem
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
▸ 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
▸ 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
▸ 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
▸ 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
▸ shl(shift
: u32): U512
Defined in bignum.ts:359
The bitwise left-shift operator.
Parameters:
Name | Type |
---|---|
shift | u32 |
Returns: U512
shr
▸ shr(shift
: u32): U512
Defined in bignum.ts:381
The bitwise right-shift operator.
Parameters:
Name | Type |
---|---|
shift | u32 |
Returns: U512
sub
Defined in bignum.ts:177
The subtraction operator - subtracts the two U512s.
Parameters:
Name | Type |
---|---|
other | U512 |
Returns: U512
toBytes
▸ toBytes(): Array‹u8›
Defined in bignum.ts:573
Serializes the U512 into an array of bytes that represents it in the CasperLabs serialization format.
Returns: Array‹u8›
toBytesLE
▸ toBytesLE(): Uint8Array
Defined in bignum.ts:483
Returns a little-endian byte-array representation of this U512 (i.e. result[0]
is the least
significant byte.
Returns: Uint8Array
toString
▸ toString(): String
Defined in bignum.ts:539
An alias for [toHex].
Returns: String
Static
fromBytes
▸ fromBytes(bytes
: Uint8Array): 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
Class: Ref <T>
Boxes a value which could then be nullable in any context.
Type parameters
▪ T
Hierarchy
- Ref
Index
Constructors
Properties
Constructors
constructor
+ new Ref(value
: T): Ref
Defined in bytesrepr.ts:8
Parameters:
Name | Type |
---|---|
value | T |
Returns: Ref
Properties
value
• value: T
Defined in bytesrepr.ts:9
Class: Result <T>
Class representing a result of an operation that might have failed. Can contain either a value
resulting from a successful completion of a calculation, or an error. Similar to Result
in Rust
or Either
in Haskell.
Type parameters
▪ T
Hierarchy
- Result
Index
Constructors
Properties
Accessors
Methods
Constructors
constructor
+ new Result(ref
: Ref‹T› | null, error
: Error, position
: usize): Result
Defined in bytesrepr.ts:53
Creates new Result with wrapped value
Parameters:
Name | Type | Description |
---|---|---|
ref | Ref‹T› | null | - |
error | Error | Error value |
position | usize | Position of input stream |
Returns: Result
Properties
error
• error: Error
Defined in bytesrepr.ts:60
Error value
position
• position: usize
Defined in bytesrepr.ts:60
Position of input stream
ref
• ref: Ref‹T› | null
Defined in bytesrepr.ts:60
Accessors
value
• get value(): T
Defined in bytesrepr.ts:65
Assumes that reference wrapper contains a value and then returns it
Returns: T
Methods
hasError
▸ hasError(): bool
Defined in bytesrepr.ts:83
Checks if error value is set.
Truth also implies !hasValue(), false value implies hasValue()
Returns: bool
hasValue
▸ hasValue(): bool
Defined in bytesrepr.ts:74
Checks if given Result contains a value
Returns: bool
ok
▸ ok(): T | null
Defined in bytesrepr.ts:90
For nullable types, this returns the value itself, or a null.
Returns: T | null
unwrap
▸ unwrap(): T
Defined in bytesrepr.ts:97
Returns success value, or reverts error value.
Returns: T
Class: CLValue
A CasperLabs value, i.e. a value which can be stored and manipulated by smart contracts.
It holds the underlying data as a type-erased, serialized array of bytes and also holds the [CLType] of the underlying data as a separate member.
Hierarchy
- CLValue
Index
Constructors
Properties
Methods
Constructors
constructor
+ new CLValue(bytes
: u8[], tag
: u8[]): CLValue
Defined in clvalue.ts:69
Constructs a new CLValue
with given underlying data and type tag.
Parameters:
Name | Type |
---|---|
bytes | u8[] |
tag | u8[] |
Returns: CLValue
Properties
bytes
• bytes: u8[]
Defined in clvalue.ts:68
tag
• tag: u8[]
Defined in clvalue.ts:69
Methods
toBytes
▸ toBytes(): u8[]
Defined in clvalue.ts:144
Serializes a CLValue
into an array of bytes.
Returns: u8[]
Static
fromI32
▸ fromI32(value
: i32): CLValue
Defined in clvalue.ts:96
Creates a CLValue
holding a signed 32-bit integer.
Parameters:
Name | Type |
---|---|
value | i32 |
Returns: CLValue
Static
fromKey
Defined in clvalue.ts:110
Creates a CLValue
holding a Key.
Parameters:
Name | Type |
---|---|
key | Key |
Returns: CLValue
Static
fromOption
▸ fromOption(value
: Option, nestedT
: CLTypeTag): CLValue
Defined in clvalue.ts:134
Creates a CLValue
holding an Option.
Parameters:
Name | Type |
---|---|
value | Option |
nestedT | CLTypeTag |
Returns: CLValue
Static
fromString
▸ fromString(s
: String): CLValue
Defined in clvalue.ts:82
Creates a CLValue
holding a string.
Parameters:
Name | Type |
---|---|
s | String |
Returns: CLValue
Static
fromStringList
▸ fromStringList(values
: String[]): CLValue
Defined in clvalue.ts:124
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:89
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:103
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:117
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 , ProofOfStake and User . Can be created with Error.fromErrorCode |
65024, 65279 | Mint - instantiation currently unsupported |
65280, 65535 | ProofOfStake errors |
65536, 131071 | User error codes created with Error.fromUserError |
Example usage
// Creating using user error which adds 65536 to the error value.
Error.fromUserError(1234).revert();
// Creating using standard error variant.
Error.fromErrorCode(ErrorCode.InvalidArguent).revert();
Hierarchy
- Error
Index
Constructors
Methods
Constructors
constructor
+ new Error(value
: u32): Error
Defined in error.ts:115
Creates an error object with given error value.
Recommended way to use this class is through its static members:
Parameters:
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: Key
The type under which data (e.g. CLValues, smart contracts, user accounts) are indexed on the network.
Hierarchy
- Key
Index
Properties
Methods
Properties
account
• account: PublicKey | null
Defined in key.ts:75
hash
• hash: Uint8Array | null
Defined in key.ts:73
uref
• uref: URef | null
Defined in key.ts:74
variant
• variant: KeyVariant
Defined in key.ts:72
Methods
add
▸ add(value
: CLValue): void
Defined in key.ts:235
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:249
Checks whether two Key
s are equal.
Parameters:
Name | Type |
---|---|
other | Key |
Returns: bool
isURef
▸ isURef(): bool
Defined in key.ts:196
Checks whether the Key
is of KeyVariant.UREF_ID.
Returns: bool
notEqualsTo
▸ notEqualsTo(other
: Key): bool
Defined in key.ts:282
Checks whether two keys are not equal.
Parameters:
Name | Type |
---|---|
other | Key |
Returns: bool
read
▸ read(): Uint8Array | null
Defined in key.ts:206
Reads the data stored under this Key
.
Returns: Uint8Array | null
toBytes
▸ toBytes(): Array‹u8›
Defined in key.ts:168
Serializes a Key
into an array of bytes.
Returns: Array‹u8›
toURef
▸ toURef(): URef
Defined in key.ts:201
Converts the Key
into URef
.
Returns: URef
write
▸ write(value
: CLValue): void
Defined in key.ts:223
Stores a CLValue under this Key
.
Parameters:
Name | Type |
---|---|
value | CLValue |
Returns: void
Static
create
▸ create(value
: CLValue): Key | null
Defined in key.ts:106
Attempts to write value
under a new Key::URef
If a key is returned it is always of KeyVariant.UREF_ID
Parameters:
Name | Type |
---|---|
value | CLValue |
Returns: Key | null
Static
fromAccount
▸ fromAccount(account
: PublicKey): Key
Defined in key.ts:94
Creates a Key
from a PublicKey representing an account.
Parameters:
Name | Type |
---|---|
account | PublicKey |
Returns: Key
Static
fromBytes
▸ fromBytes(bytes
: Uint8Array): Result‹Key›
Defined in key.ts:126
Deserializes a Key
from an array of bytes.
Parameters:
Name | Type |
---|---|
bytes | Uint8Array |
Static
fromHash
▸ fromHash(hash
: Uint8Array): Key
Defined in key.ts:86
Creates a Key
from a given hash.
Parameters:
Name | Type |
---|---|
hash | Uint8Array |
Returns: Key
Static
fromURef
Defined in key.ts:78
Creates a Key
from a given URef.
Parameters:
Name | Type |
---|---|
uref | URef |
Returns: Key
Class: PublicKey
A cryptographic public key.
Hierarchy
- PublicKey
Index
Constructors
Properties
Methods
Constructors
constructor
+ new PublicKey(variant
: u8, bytes
: Uint8Array): PublicKey
Defined in key.ts:28
Constructs a new PublicKey
.
Parameters:
Name | Type | Description |
---|---|---|
variant | u8 | An ID of the used key variant. |
bytes | Uint8Array | The bytes constituting the public key. |
Returns: PublicKey
Properties
bytes
• bytes: Uint8Array
Defined in key.ts:35
The bytes constituting the public key.
variant
• variant: u8
Defined in key.ts:35
An ID of the used key variant.
Methods
equalsTo
▸ equalsTo(other
: PublicKey): bool
Defined in key.ts:39
Checks whether two PublicKey
s are equal.
Parameters:
Name | Type |
---|---|
other | PublicKey |
Returns: bool
notEqualsTo
▸ notEqualsTo(other
: PublicKey): bool
Defined in key.ts:45
Checks whether two PublicKey
s are not equal.
Parameters:
Name | Type |
---|---|
other | PublicKey |
Returns: bool
toBytes
▸ toBytes(): Array‹u8›
Defined in key.ts:62
Serializes a PublicKey
into an array of bytes.
Returns: Array‹u8›
Static
fromBytes
▸ fromBytes(bytes
: Uint8Array): Result‹PublicKey›
Defined in key.ts:50
Deserializes a PublicKey
from an array of bytes.
Parameters:
Name | Type |
---|---|
bytes | Uint8Array |
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:50
Serializes the Option
into an array of bytes.
Returns: Array‹u8›
unwrap
▸ unwrap(): Uint8Array | null
Defined in option.ts:43
Unwraps the Option
, returning the inner value (or null
if there was none).
Returns: Uint8Array | null
The inner value, or null
if there was none.
Static
fromBytes
▸ fromBytes(bytes
: Uint8Array): Option
Defined in option.ts:70
Deserializes an array of bytes into an Option
.
Parameters:
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: 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: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
Methods
equalsTo
▸ equalsTo(other
: URef): bool
Defined in uref.ts:133
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:79
Returns the access rights of this URef.
Returns: AccessRights
getBytes
▸ getBytes(): Uint8Array
Defined in uref.ts:72
Returns the address of this URef as an array of bytes.
Returns: Uint8Array
A byte array with a length of 32.
isValid
▸ isValid(): boolean
Defined in uref.ts:86
Validates uref against named keys.
Returns: boolean
notEqualsTo
▸ notEqualsTo(other
: URef): bool
Defined in uref.ts:143
The not-equal operator.
Parameters:
Name | Type |
---|---|
other | URef |
Returns: bool
False if this
and other
are equal, true otherwise.
toBytes
▸ toBytes(): Array‹u8›
Defined in uref.ts:117
Serializes the URef into an array of bytes that represents it in the CasperLabs serialization format.
Returns: Array‹u8›
Static
fromBytes
▸ fromBytes(bytes
: Uint8Array): 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. |
Enums
Enumeration: ActionType
Enum representing an action for which a threshold is being set.
Index
Enumeration members
Enumeration members
Deployment
• Deployment: = 0
Defined in account.ts:106
Required by deploy execution.
KeyManagement
• KeyManagement: = 1
Defined in account.ts:110
Required when adding/removing associated keys, changing threshold levels.
Enumeration: AddKeyFailure
Enum representing the possible results of adding an associated key to an account.
Index
Enumeration members
Enumeration members
DuplicateKey
• DuplicateKey: = 2
Defined in account.ts:22
Unable to add new associated key because given key already exists
MaxKeysLimit
• MaxKeysLimit: = 1
Defined in account.ts:18
Unable to add new associated key because maximum amount of keys is reached
Ok
• Ok: = 0
Defined in account.ts:14
Success
PermissionDenied
• PermissionDenied: = 3
Defined in account.ts:26
Unable to add new associated key due to insufficient permissions
Enumeration: RemoveKeyFailure
Enum representing the possible results of removing an associated key from an account.
Index
Enumeration members
Enumeration members
MissingKey
• MissingKey: = 1
Defined in account.ts:62
Key does not exist in the list of associated keys.
Ok
• Ok: = 0
Defined in account.ts:58
Success
PermissionDenied
• PermissionDenied: = 2
Defined in account.ts:66
Unable to remove the associated key due to insufficient permissions
ThresholdViolation
• ThresholdViolation: = 3
Defined in account.ts:70
Unable to remove a key which would violate action threshold constraints
Enumeration: SetThresholdFailure
Enum representing the possible results of setting the threshold of an account.
Index
Enumeration members
Enumeration members
DeploymentThreshold
• DeploymentThreshold: = 2
Defined in account.ts:88
New threshold should be lower or equal than key management threshold
InsufficientTotalWeight
• InsufficientTotalWeight: = 4
Defined in account.ts:96
New threshold should be lower or equal than total weight of associated keys
KeyManagementThreshold
• KeyManagementThreshold: = 1
Defined in account.ts:84
New threshold should be lower or equal than deployment threshold
Ok
• Ok: = 0
Defined in account.ts:80
Success
PermissionDeniedError
• PermissionDeniedError: = 3
Defined in account.ts:92
Unable to set action threshold due to insufficient permissions
Enumeration: UpdateKeyFailure
Enum representing the possible results of updating an associated key of an account.
Index
Enumeration members
Enumeration members
MissingKey
• MissingKey: = 1
Defined in account.ts:40
Key does not exist in the list of associated keys.
Ok
• Ok: = 0
Defined in account.ts:36
Success
PermissionDenied
• PermissionDenied: = 2
Defined in account.ts:44
Unable to update the associated key due to insufficient permissions
ThresholdViolation
• ThresholdViolation: = 3
Defined in account.ts:48
Unable to update weight that would fall below any of action thresholds
Enumeration: Error
Enum representing possible results of deserialization.
Index
Enumeration members
Enumeration members
EarlyEndOfStream
• EarlyEndOfStream: = 1
Defined in bytesrepr.ts:24
Early end of stream
FormattingError
• FormattingError: = 2
Defined in bytesrepr.ts:28
Unexpected data encountered while decoding byte stream
Ok
• Ok: = 0
Defined in bytesrepr.ts:20
Last operation was a success
Enumeration: CLTypeTag
CasperLabs types, i.e. types which can be stored and manipulated by smart contracts.
Provides a description of the underlying data type of a CLValue.
Index
Enumeration members
Enumeration members
Any
• Any: = 21
Defined in clvalue.ts:58
A value of any type.
Bool
• Bool: = 0
Defined in clvalue.ts:14
A boolean value
Fixed_list
• Fixed_list: = 15
Defined in clvalue.ts:44
A fixed-length list of values
I32
• I32: = 1
Defined in clvalue.ts:16
A 32-bit signed integer
I64
• I64: = 2
Defined in clvalue.ts:18
A 64-bit signed integer
Key
• Key: = 11
Defined in clvalue.ts:36
A key in the global state - URef/hash/etc.
List
• List: = 14
Defined in clvalue.ts:42
A list of values
Map
• Map: = 17
Defined in clvalue.ts:50
A key-value map.
Option
• Option: = 13
Defined in clvalue.ts:40
An Option, i.e. a type that can contain a value or nothing at all
Result
• Result: = 16
Defined in clvalue.ts:48
A Result, i.e. a type that can contain either a value representing success or one representing failure.
String
• String: = 10
Defined in clvalue.ts:34
A string of characters
Tuple1
• Tuple1: = 18
Defined in clvalue.ts:52
A 1-value tuple.
Tuple2
• Tuple2: = 19
Defined in clvalue.ts:54
A 2-value tuple, i.e. a pair of values.
Tuple3
• Tuple3: = 20
Defined in clvalue.ts:56
A 3-value tuple.
U128
• U128: = 6
Defined in clvalue.ts:26
A 128-bit unsigned integer
U256
• U256: = 7
Defined in clvalue.ts:28
A 256-bit unsigned integer
U32
• U32: = 4
Defined in clvalue.ts:22
A 32-bit unsigned integer
U512
• U512: = 8
Defined in clvalue.ts:30
A 512-bit unsigned integer
U64
• U64: = 5
Defined in clvalue.ts:24
A 64-bit unsigned integer
U8
• U8: = 3
Defined in clvalue.ts:20
An 8-bit unsigned integer (a byte)
Unit
• Unit: = 9
Defined in clvalue.ts:32
A unit type, i.e. type with no values (analogous to void
in C and ()
in Rust)
Uref
• Uref: = 12
Defined in clvalue.ts:38
An Unforgeable Reference (URef)
Enumeration: ErrorCode
Standard error codes which can be encountered while running a smart contract.
An ErrorCode can be passed to Error.fromErrorCode function to create an error object. This error object later can be used to stop execution by using Error.revert method.
Index
Enumeration members
4 years ago