near-sdk-gr

Basic Functionality

Basic constructors and operations for Promises

Promise.create

create : (String, String, String, Int128.Int128, Int64) -> Promise

Creates a promise that will execute a method on account with given arguments and attaches the given amount.

Parameters:

param type description
accountId String The account to call the function on
methodName String The function to call
arguments String The arguments to the function (a JSON-formatted string)
amount Int128.Int128 The amount to attach to the function call (a 128-bit integer)
gas Int64 The amount of gas to attach to the function call

Returns:

type description
Promise The new promise

Promise.then

then : (Promise, String, String, Bytes, Int128.Int128, Int64) -> Promise

Creates a new promise towards given account_id without any actions attached, that is executed after the given promise is complete.

Parameters:

param type description
promise Promise The promise to append the action to
accountId String The account to call the function on
methodName String The function to call
arguments Bytes The arguments to the function (a JSON-formatteds tring)
amount Int128.Int128 The amount to attach to the function call (a 128-bit integer)
gas Int64 The amount of gas to attach to the function call

Returns:

type description
Promise The new promise

Promise.and

and : Array<Promise> -> Promise

Creates a new promise which completes when time all promises passed as arguments complete.

Parameters:

param type description
promises Array<Promise> The array of promises that need to be waited on jointly.

Returns:

type description
Promise The new promise

Promise.index

index : Promise -> Int64

Returns the underlying callback index for the given promise.

Parameters:

param type description
promise Promise The promise whose index to return

Returns:

type description
Int64 The index

Promise.fromIndex

fromIndex : Int64 -> Promise

Constructs a promise instance from the given callback index.

Parameters:

param type description
promiseIndex Int64 The promise index to wrap

Returns:

type description
Promise The promise object

Batched Actions

For more information, see https://github.com/nearprotocol/NEPs/pull/8/files#diff-15b6752ec7d78e7b85b8c7de4a19cbd4R48

Promise.batchActionCreateAccount

batchActionCreateAccount : Promise -> Void

Appends a CreateAccount action to the batch of actions for the given promise.

https://nomicon.io/RuntimeSpec/Actions.html#createaccountaction

Parameters:

param type description
promise Promise The promise to append the action to

Promise.batchActionDeployContract

batchActionDeployContract : (Promise, Bytes) -> Void

Appends a DeployContract action to the batch of actions for the given promise.

Sets the contract code for the account.

https://nomicon.io/RuntimeSpec/Actions.html#deploycontractaction

Parameters:

param type description
promise Promise The promise to append the action to
code Bytes The contract to deploy

Promise.batchActionFunctionCall

batchActionFunctionCall :
  (Promise, String, Bytes, Int128.Int128, Int64) -> Void

Appends a FunctionCall action to the batch of actions for the given promise.

https://nomicon.io/RuntimeSpec/Actions.html#functioncallaction

Parameters:

param type description
promise Promise The promise to append the action to
methodName String The name of the method to call
arguments Bytes The arguments for the function call
amount Int128.Int128 The amount to attach to the function call (a 128-bit integer)
gas Int64 The amount of gas to attach to the function call

Promise.batchActionTransfer

batchActionTransfer : (Promise, Int128.Int128) -> Void

Appends a Transfer action to the batch of actions for the given promise.

This will transfer the amount specified in amount from predecessorId to a receiverId account.

https://nomicon.io/RuntimeSpec/Actions.html#transferaction

Parameters:

param type description
promise Promise The promise to append the action to
amount Int128.Int128 The amount to transfer (a 128-bit integer)

Promise.batchActionStake

batchActionStake : (Promise, Int128.Int128, Bytes) -> Void

Appends a Stake action to the batch of actions for the given promise.

A validator proposal that contains the staking public key and the staking amount will be generated and will be included in the next block.

https://nomicon.io/RuntimeSpec/Actions.html#stakeaction

Parameters:

param type description
promise Promise The promise to append the action to
amount Int128.Int128 The amount of tokens to stake (a 128-bit integer)
publicKey Bytes A public key of the validator node

Promise.FunctionCallPermission

record FunctionCallPermission {
  allowance: Option<Int128.Int128>,
  receiverId: String,
  methodNames: Array<String>,
}

Permission structure which allows FunctionCalls to a specified receiverId.

Source: https://nomicon.io/DataStructures/AccessKey.html#accesskeypermissionfunctioncall

This record has the following fields:

Promise.AccessKeyPermission

enum AccessKeyPermission {
  FullAccess,
  FunctionCallAccess(FunctionCallPermission),
}

Types of permissions which can be associated with an AccessKey.

Source: https://nomicon.io/DataStructures/AccessKey.html#access-keys

Promise.AccessKey

record AccessKey {
  nonce: Bytes,
  permission: AccessKeyPermission,
}

An access key which provides an access for a particular account.

Source: https://nomicon.io/DataStructures/AccessKey.html#access-keys

This record has the following fields:

Promise.batchActionAddKey

batchActionAddKey : (Promise, Bytes, AccessKey) -> Void

Appends a AddKey action to the batch of actions for the given promise.

Adds a new AccessKey to the receiver’s account and associates it with a publicKey provided.

https://nomicon.io/RuntimeSpec/Actions.html#addkeyaction

Parameters:

param type description
promise Promise The promise to append the action to
publicKey Bytes A public key to associate the access key with
accessKey AccessKey The access key to add

Promise.batchActionDeleteKey

batchActionDeleteKey : (Promise, Bytes) -> Void

Appends a DeleteKey action to the batch of actions for the given promise.

Deletes the AccessKey from the receiver’s account associed with the publicKey provided.

https://nomicon.io/RuntimeSpec/Actions.html#deletekeyaction

Parameters:

param type description
promise Promise The promise to append the action to
publicKey Bytes A public key to delete the associated access key from

Promise.batchActionDeleteAccount

batchActionDeleteAccount : (Promise, String) -> Void

Appends a DeleteAccount action to the batch of actions for the given promise.

The account, as well as all the data stored under the account, is deleted and the tokens are transferred to beneficiaryId.

https://nomicon.io/RuntimeSpec/Actions.html#deleteaccountaction

Parameters:

param type description
promise Promise The promise to append the action to
publicKey String The account ID to transfer the remaining balance to

Promise Results

Results

Promise.resultsCount

resultsCount : () -> Int64

If the current execution is invoked by a callback we can access the execution results of the promises that caused the callback. This function returns the number of complete and incomplete callbacks.

Note, there will only be incomplete callbacks once there is an or combinator.

Promise.checkResult

checkResult : Promise -> Option<Bool>

If the current function is invoked by a callback we can access the execution results of the promises that caused the callback. This function returns the result in blob format and places it into register 0.

Parameters:

param type description
promise Promise The promise whose result to load

Returns:

type description
Option<Bool> None if the promise has not completed, or Some(flag) if it has (where flag is true if the promise succeeded)

Promise.getResultBytes

getResultBytes : Promise -> Option<Result<Bytes, String>>

If the current function is invoked by a callback we can access the execution results of the promises that caused the callback. This function returns the result as a byte sequence. If the promise result is complete and successful, register 0 will be overwritten.

Parameters:

param type description
promise Promise The promise whose result to load

Returns:

type description
Option<Result<Bytes, String>> None if the promise has not completed, or Some(Ok(result)) if it has successfully, or Some(Err(msg)) if it has failed

Promise.getResultString

getResultString : Promise -> Option<Result<String, String>>

If the current function is invoked by a callback we can access the execution results of the promises that caused the callback. This function returns the result as a string. If the promise result is complete and successful, register 0 will be overwritten.

Parameters:

param type description
promise Promise The promise whose result to load

Returns:

type description
Option<Result<String, String>> None if the promise has not completed, or Some(Ok(result)) if it has successfully, or Some(Err(msg)) if it has failed

Promise.getResultInt32

getResultInt32 : Promise -> Option<Result<Int32, String>>

If the current function is invoked by a callback we can access the execution results of the promises that caused the callback. This function returns the result as a 32-bit integer. If the promise result is complete and successful, register 0 will be overwritten.

Parameters:

param type description
promise Promise The promise whose result to load

Returns:

type description
Option<Result<Int32, String>> None if the promise has not completed, or Some(Ok(result)) if it has successfully, or Some(Err(msg)) if it has failed

Promise.getResultInt64

getResultInt64 : Promise -> Option<Result<Int64, String>>

If the current function is invoked by a callback we can access the execution results of the promises that caused the callback. This function returns the result as a 64-bit integer. If the promise result is complete and successful, register 0 will be overwritten.

Parameters:

param type description
promise Promise The promise whose result to load

Returns:

type description
Option<Result<Int64, String>> None if the promise has not completed, or Some(Ok(result)) if it has successfully, or Some(Err(msg)) if it has failed

Promise.getResultInt128

getResultInt128 : Promise -> Option<Result<Int128.Int128, String>>

If the current function is invoked by a callback we can access the execution results of the promises that caused the callback. This function returns the result as a 128-bit integer. If the promise result is complete and successful, register 0 will be overwritten.

Parameters:

param type description
promise Promise The promise whose result to load

Returns:

type description
Option<Result<Int128.Int128, String>> None if the promise has not completed, or Some(Ok(result)) if it has successfully, or Some(Err(msg)) if it has failed

Promise.getResultInt256

getResultInt256 : Promise -> Option<Result<Int256.Int256, String>>

If the current function is invoked by a callback we can access the execution results of the promises that caused the callback. This function returns the result as a 256-bit integer. If the promise result is complete and successful, register 0 will be overwritten.

Parameters:

param type description
promise Promise The promise whose result to load

Returns:

type description
Option<Result<Int256.Int256, String>> None if the promise has not completed, or Some(Ok(result)) if it has successfully, or Some(Err(msg)) if it has failed

Promise.promiseReturn

promiseReturn : Promise -> Void

When the given promise finishes executing its result is considered to be the result of the current function.

Parameters:

param type description
promise Promise The promise whose result to return