invokescript

Returns the result after passing a script through the VM.

πŸ“˜

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βœ…StringA script runnable in the VM. This is the same script that is returned in invokefunction
SIGNERβœ…ArrayList of objects containing contract signature accounts.

SIGNER has the following fields:

KeyRequiredTypeDetail
accountβœ…StringThe signature account.
scopesβœ…StringThe signature's valid scopes, allowed values: FeeOnly, CalledByEntry, CustomContracts, CustomGroups, Global
allowedcontracts❌ArrayThe contracts of the signature that can take effect if scopes is CustomContracts
allowedgroups❌ArrayThe pubkeys of the signature that can take effect if scopes is CustomGroups
"params": [
        "wh8MCG15TWV0aG9kDBT6aFfj1fLFXfPkwMmGI1xhVLBqK0FifVtS", 
        [{
                "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.

Example

Request

curl <your-endpoint> \
   -X POST \
   -H "Content-Type: application/json" \
   -d '{"jsonrpc": "2.0","id": 1,"method": "invokescript","params": ["wh8MCG15TWV0aG9kDBT6aFfj1fLFXfPkwMmGI1xhVLBqK0FifVtS",[{"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!