invokeRead

Execute a contract invocation in read-only mode.

Input Arguments

ParameterDescription

scriptHash: string

Script hash of the smart contract to invoke a read on

operation: string

Operation on the smart contract to call

Any input arguments for the operation

Sender and the effective scope of signature

Success Response

The wallet will return the direct response from the RPC node.

ParameterDescription

script: string

The script which was run

state: string

Status of the executeion

gas_consumed: string

Estimated amount of GAS to be used to execute the invocation. (Up to 10 free per transaction)

An array of response arguments

Argument

ParameterDescription

type: 'String' | 'Boolean' | 'Hash160' | 'Hash256' | 'Integer' | 'ByteArray' | 'Array' | 'Address'

The type of the argument with you are using. The type is an array, please see the example for the value.

value: string

String representation of the argument which you are using

Signer

ParameterDescription

account: string

scriptHash of the address

Effective range of the signature

allowedContracts?: Array

Contracts of the signature can take effect, if scopes is CustomContracts

allowedGroups?: Array

Pubkeys of the signature can take effect, if scopes is CustomGroups

Custom rules for witness to adhere by, if scopes is WitnessRules

Scopes

FieldDescription

0

Only transactions are signed and no contracts are allowed to use this signature.

1

It only applies to the chain call entry. That is, if the user invokes contract A, and then contract A calls contract B, only contract A can use the signature. It is recommended as the default value for the wallet.

16

Custom contract. The signature can be used in the specified contract. It can be used in conjunction with CalledByEntry.

32

Custom contract groups that can be used in a specified contract group. It can be used in conjunction with CalledByEntry.

64

Indicates that the current context must satisfy the specified rules.

128

Global. The risk is extremely high because the contract may transfer all assets in the address. Only choose it when the contract is extremely trusted.

WitnessRule

ParameterDescription

action: 'Deny' | 'Allow'

Represents the action of a WitnessRule.

Represents the condition of a WitnessRule.

WitnessCondition

FieldDescription

Indicates that the condition will always be met or not met.

Indicates that all conditions must be met.

Reverse another condition.

Indicates that any of the conditions meets.

Indicates that the condition is met when the current context has the specified script hash.

Indicates that the condition is met when the current context has the specified group.

Indicates that the condition is met when the current context is the entry point or is called by the entry point.

Indicates that the condition is met when the current context is called by the specified contract.

Indicates that the condition is met when the current context is called by the specified group.

BooleanWitnessCondition

ParameterDescription

type: 'Boolean'

The type of the BooleanWitnessCondition.

expression: boolean

The expression of the BooleanWitnessCondition.

AndWitnessCondition

ParameterDescription

type: 'And'

The type of the AndWitnessCondition.

The expressions of the AndWitnessCondition.

NotWitnessCondition

ParameterDescription

type: 'Not'

The type of the NotWitnessCondition.

The expression of the NotWitnessCondition.

OrWitnessCondition

ParameterDescription

type: 'Or'

The type of the OrWitnessCondition.

The expressions of the OrWitnessCondition.

ScriptHashWitnessCondition

ParameterDescription

type: 'ScriptHash'

The type of the ScriptHashWitnessCondition.

hash: string

The hash of the ScriptHashWitnessCondition.

GroupWitnessCondition

ParameterDescription

type: 'Group'

The type of the GroupWitnessCondition.

group: string

The group of the GroupWitnessCondition.

CalledByEntryWitnessCondition

ParameterDescription

type: 'CalledByEntry'

The type of the CalledByEntryWitnessCondition.

CalledByContractWitnessCondition

ParameterDescription

type: 'CalledByContract'

The type of the CalledByContractWitnessCondition.

hash: string

The hash of the CalledByContractWitnessCondition.

CalledByGroupWitnessCondition

ParameterDescription

type: 'CalledByGroup'

The type of the CalledByGroupWitnessCondition.

group: string

The group of the CalledByGroupWitnessCondition.

Error Response

ParameterDescription

type: string

The type of error which has occured

description: string

A description of the error which has occured

data: string

Any raw data associated with the error

Example

Request

neolineN3.invokeRead({
    scriptHash: 'd2a4cff31913016155e38e474a2c06d08be276cf',
    operation: 'transfer',
    args: [
        {
            "type": "Hash160",
            "value": "0xebae4ab3f21765e5f604dfdd590fdf142cfb89fa"
        },
        {
            "type": "Hash160",
            "value": "0xebae4ab3f21765e5f604dfdd590fdf142cfb89fa"
        },
        {
            "type": "Integer",
            "value": "10000"
        },
        {
            "type": "String",
            "value": ""
        }
    ],
    signers: [
        {
            account: "2cab903ff032ac693f8514581665be534beac39f",
            scopes: 1
        }
    ],
})
.then(result => {
  console.log('Read invocation result: ' + JSON.stringify(result));
})
.catch((error) => {
  const {type, description, data} = error;
  switch(type) {
    case 'NO_PROVIDER':
        console.log('No provider available.');
        break;
    case 'CONNECTION_REFUSED':
        console.log('Connection dApp not connected. Please call the "connect" function.');
        break;
    case 'RPC_ERROR':
        console.log('There was an error when broadcasting this transaction to the network.');
        break;
    default:
        // Not an expected error object.  Just write the error to the console.
        console.error(error);
        break;
  }
});

Response

{
    script: "DAABECcMFPqJ+ywU3w9Z3d8E9uVlF/KzSq7rDBT6ifssFN8PWd3fBPblZRfys0qu6xTAHwwIdHJhbnNmZXIMFM924ovQBixKR47jVWEBExnzz6TSQWJ9W1I=",
    state:"HALT",
    stack:[
        {
            type:"Boolean",
            value:false
        }
    ]
}
/* Example, Type is array */
args: [
        {
            type: "Array",
            value: [
              {
                type: "String",
                value: "0x576f726c64"
              }, {
                type: "String",
                value: "0x576f726c64"
              }
            ]
        }
    ]

最后更新于