Skip to content

Latest commit

 

History

History
84 lines (58 loc) · 2.82 KB

ScriptApi.md

File metadata and controls

84 lines (58 loc) · 2.82 KB

ledger.ScriptApi

All URIs are relative to http://localhost

Method HTTP request Description
runScript POST /{ledger}/script Execute a Numscript

runScript

ScriptResponse runScript(script)

This route is deprecated, and has been merged into POST /{ledger}/transactions.

Example

import { ledger } from '@numaryhq/ledger-nodejs';
import * as fs from 'fs';

const configuration = ledger.createConfiguration();
const apiInstance = new ledger.ScriptApi(configuration);

let body:ledger.ScriptApiRunScriptRequest = {
  // string | Name of the ledger.
  ledger: "ledger001",
  // Script
  script: {
    plain: `vars {
account $user
}
send [COIN 10] (
	source = @world
	destination = $user
)
`,
    vars: {},
    reference: "order_1234",
    metadata: {
      "key": null,
    },
  },
  // boolean | Set the preview mode. Preview mode doesn't add the logs to the database or publish a message to the message broker. (optional)
  preview: true,
};

apiInstance.runScript(body).then((data:any) => {
  console.log('API called successfully. Returned data: ' + data);
}).catch((error:any) => console.error(error));

Parameters

Name Type Description Notes
script Script
ledger [string] Name of the ledger. defaults to undefined
preview [boolean] Set the preview mode. Preview mode doesn't add the logs to the database or publish a message to the message broker. (optional) defaults to undefined

Return type

ScriptResponse

Authorization

No authorization required

HTTP request headers

  • Content-Type: application/json; charset=utf-8
  • Accept: application/json; charset=utf-8

HTTP response details

Status code Description Response headers
200 On success, it will return a 200 status code, and the resulting transaction under the `transaction` field. On failure, it will also return a 200 status code, and the following fields: - `details`: contains a URL. When there is an error parsing Numscript, the result can be difficult to read—the provided URL will render the error in an easy-to-read format. - `errorCode` and `error_code` (deprecated): contains the string code of the error - `errorMessage` and `error_message` (deprecated): contains a human-readable indication of what went wrong, for example that an account had insufficient funds, or that there was an error in the provided Numscript. -

[Back to top] [Back to API list] [Back to Model list] [Back to README]