# Local script

# A brief introduction to local scripts

The local callback script is also applicable to this language and syntax, but does not need to follow the contract format, does not need to return a table at the end of the script, and can also define global variables.

When the local callback script is executed, it will be executed in sequence according to the code order in the script.。

# A simple script that accepts contract events

pprint("got event ", event_type, " from contract ", contract_id(emit Contract ID), " param is ", param)

# Global variables of local scripts

truncated: Whether the parameters thrown by emit are truncated
param: Parameters in string format thrown during emit
contract_id: The contract ID where the emit trigger code is located
event_type: Event type in string format

# Local script module usage

Local scripts can introduce modules of built-in libraries through the require function to use the functions of these modules in scripts

such as

let http = require 'http'
http.listen('127.0.0.1', 3000)  -- Listen to http requests on port 3000

# How to bind local scripts to on-chain contracts

Operate buttons in the console or interface of the blockchain.

Use the command "compile_script script source file path" to compile

Use the command "add_script script compiled file path description string" to register the local script on the chain