invokefunction

Invokes a smart contract with the specified script hash, passing in the method name and its params.

📘

This method is used to test your VM script as if they ran on the blockchain at that point in time. This RPC call does not affect the blockchain in any way.

Parameters

Object NameRequiredTypeDetail
SCRIPT HASHStringThe smart contract script hash.
OPERATIONStringThe operation name.
PARAMSArrayThe parameters to be passed into the smart contract operation.
SIGNERSArrayList of objects containing contract signature accounts.

SIGNERS has the following fields:

KeyRequiredTypeDetail
accountStringThe signature account.
scopesStringThe signature's valid scopes, allowed values: None, CalledByEntry, CustomContracts, CustomGroups, Global
allowedcontractsArrayThe contracts of the signature that can take effect if scopes is CustomContracts
allowedgroupsArrayThe pubkeys of the signature that can take effect if scopes is CustomGroups

📘

You need to use the proper byte order of the address passed according to its data type. If the data type is Hash160, use the big endian script hash; if the data type is ByteArray, use the little endian scripthash.

{
  "type": "String",
  "value": "Hello"
}

{
  "type": "Hash160",
  "value": "0xf621168b1fce3a89c33a5f6bcf7e774b4657031c"
}

{
  "type": "ByteArray",
  "value": "7472616e73666572"
}
"params": [
  "0x2b6ab054615c2386c9c0e4f35dc5f2d5e35768fa",
  "myMethod",
  [],
  [{
    "account": "NSk8xEBm3FNAFDueUf21cMugkWidJn5N1n",
    "scopes": "CalledByEntry",
    "allowedcontracts": [],
    "allowedgroups": []
  }]
]

Result

The smart contract result.

Result Fields

KeyTypeDetail
scriptStringThe invocation script of the contract.
stateStringHALT means the vm executed successfully, and FAULT means the vm exited due to an exception.
gasconsumedStringThe system fee consumed for invocation.
stackStringThe contract execution result. If the value is String or ByteArray, it is encoded by Base64.
txStringThe transaction's hex string of this invocation, need open wallet and added signers correctly.

Example

Request

curl <your-endpoint> \
   -X POST \
   -H "Content-Type: application/json" \
   -d '{"jsonrpc": "2.0","id": 1,"method": "invokefunction","params": ["0x2b6ab054615c2386c9c0e4f35dc5f2d5e35768fa","myMethod",[],[{"account": "NSk8xEBm3FNAFDueUf21cMugkWidJn5N1n","scopes": "CalledByEntry","allowedcontracts": [],"allowedgroups": []}]]}'

Return

{
    "jsonrpc": "2.0",
    "id": 1,
    "result": {
        "script": "wh8MCG15TWV0aG9kDBT6aFfj1fLFXfPkwMmGI1xhVLBqK0FifVtS",
        "state": "HALT",
        "gasconsumed": "196863",
        "exception": null,
        "stack": [{
            "type": "ByteString",
            "value": "V29ybGQ="
        }]
    }
}
Language
Click Try It! to start a request and see the response here!