Search…
Templating
How our templating system works
We recently rolled out a new templating system based on Go Template. It will be soon hidden away by a new UI, but for now you have full access to the raw templating engine.
You can access the following fields, as well as using all the power of Go Templates to write conditions, loops etc.

Watch a Transaction

Template
Meaning
{{.Contract.Address}}
Address of the contract
{{.Block.Number}}
Block number
{{.Block.Timestamp}}
Block timestamp
{{.Block.Hash }}
Block hash
{{.Tx.From}}
Transaction from
{{.Tx.Gas}}
Transaction gas
{{.Tx.GasPrice}}
Transaction gas price
{{.Tx.Nonce}}
Transaction nonce
{{.Tx.To}}
Transaction to
{{.Tx.Hash}}
Transaction hash
{{.Tx.Value}}
Transaction value in WEI
{{.Tx.InputData}}
Input data for the transaction
{{ .Contract.MethodName }}
Function called by the transaction, if any
{{.Contract.MethodParameters.ParameterName}}
Function parameter

Watch a Contract

Specific fields for a Watch a Contract trigger are:
Template
Meaning
{{ .Contract.ReturnedValues }}
All values returned by the function invoked
{{ .Contract.MatchedValues }}
All values matched by the function invoked
{{ index .Contract.ReturnedValues 1 }}
The second value returned by the function, if the function returns more than one value

Watch an Event

Specific fields for Watch an Event trigger are:
Template
Meaning
{{ .Contract.EventName }}
Name of the Event
{{ .Contract.EventParameters.to }}
Access the "to" field on the Event
{{ .Contract.EventParameters.value }}
Access the "value" field on the Event
{{ index (.Contract.EventParameters.arrayParam) 1 }}
Access the second value on an event field, if the field is an array

Custom Functions

We also support a bunch of handy custom functions:
Template
Meaning
{{ fromWei .Object N }}
Divides a value by 10^N. Useful to convert WEI to other currencies.
{{ humanTime .Object }}
Prints a timestamp in some human readable format
{{ hexToASCII .Object }}
Hex to ASCII
{{ hexToInt .Object }}
Hex to int
{{ etherscanTxLink .Object }}
Creates an Etherscan transaction link
{{ etherscanTokenLink .Object }}
Creates an Etherscan token link
{{ etherscanAddressLink .Object }}
Creates an Etherscan address link

A more complex example

You can leverage the full power of Go Templates, thus using if/else statements, for loops and so on. This is an example that combines some of the features discussed above:
1
{{ if eq .Contract.EventParameters.to "0xcd95b32c98423172e04b1c76841e5a73f4532a7f" }}
2
the amount in DAI is {{ fromWei .Contract.EventParameters.value 18 }}
3
{{ else }}
4
{{ range .Contract.EventParameters.arrayParam }}
5
looping through: {{ . }}
6
{{ end }}
7
{{ end }}
Copied!
Last modified 2yr ago