Alright, straight to business?
First things first, get familiar with these links; you'll need to use them quite often:
- Official guidelines
- API documentation
- Glider itself
- #glider channel in Discord
- Security wiki by Remedy to find interesting attack vectors (or contribute yours!)
After registering on the website, you'll see QUERY EXPLORER
on the left. Click New Query
above and give it some name, then copy and insert this:
from glider import *
def query():
contracts = Contracts().with_name("HelloWorld").exec()
return contracts
Throughout this course you'll see mentions of both queries and glides. These are the same things used interchangeably.
Click Run
:
The result of the glide will appear on the right side. It returned all the contracts with HelloWorld
name on Kovan. E.g.:
contract HelloWorld {
...
}
Below, under the Results
tab, you will find the total number of such contracts, the total memory usage, and the execution time. The memory and execution times are currently limited.
Read more about the web interface in the guidelines: Usage.
As you might have guessed, the code is a restricted Python. It helps if you are familiar with the syntax, but it's not complicated anyway.
The glide starts with an import:
from glider import *
It is only required to enable Intellisense autocomplete. You can drop it if you want; it's optional.
Next comes the main function of any glide:
def query():
You must write it in every glide because it acts as an entry point. Otherwise, you'll get KeyError: 'query'
.
Inside this function, you can see the glide's declarative part:
contracts = Contracts().with_name("HelloWorld").exec()
From the guidelines:
A glider code can be separated into two parts: declarative queries (also called online part) and imperative arbitrary logic part (offline part)
I'll explain this distinction in more detail in the following articles.
For now, you just need to understand what it does, which is very obvious:
Contracts()
is used to get access to all the contracts on a blockchain (docs).with_name("HelloWorld")
filters out only those with the specified name (docs).exec()
indicates the end of this request (docs)
The contracts
variable will contain List[Contract]
, which you can loop through or just return as was done in the glide:
return contracts
The query()
return statement will output the object to the standard output on the right. The object should be of a List[Dict]
type. An array of JSONs, in other words. If you don't want to output anything, you can return an empty array:
return []
You'll see some examples later on.