API Reference
Overview and detailed explanations of the individual API functions
A reference for fx(params) related API functions can be found in the API Reference fx(params)
API Overview
Function
Function Signature
Purpose / Effect
$fx.hash
string
The hash string provided (or injected into) for each iteration.
$fx.rand()
() => number
Generates a pseudo-random number using the hash as the seed, ranging from 0 (inclusive) to just under 1 (exclusive).
$fx.rand.reset()
() => void
Reinitialises the $fx.rand()
generator to its original state.
$fx.minter
string
The wallet address of the minter, provided (or injected into) for each iteration.
$fx.randminter()
() => number
Similar to rand()
, but uses the minter's address as the seed, with the same output range.
$fx.randminter.reset()
() => void
Reinitialises the $fx.randminter()
generator just like rand.reset()
.
$fx.context
string
Indicates where the code is running: standalone, during capture, or while minting.
$fx.iteration
number
The iteration number of the collected GENTK.
$fx.preview()
() => void
Triggers the image capture module at mint time to create the image preview for the collected iteration.
$fx.isPreview
boolean
Set to true when the code runs in the fxhash capture module. Useful for defining capture-specific properties.
$fx.features()
(object) => void
Function that specifies the features of the collected iteration.
$fx.getFeature()
(string) => any
Retrieves the value of a named feature as set by the features()
function.
$fx.getFeatures()
() => object
Returns the entire features object as defined by features()
.
$fx.params()
(array) => void
Define collector-modifiable parameters for your piece by calling this with an array.
$fx.getParam()
(string) => any
Returns the value of a param via its ID.
$fx.getParams()
() => object
Returns a dictionary of all parameter key-value pairs, as currently set.
$fx.getRawParam()
(string) => string
Provides the raw parameter data (as a bytes string) as it was passed to the iteration.
$fx.on()
(string, function, function) => function
Registers an event listener and returns a function to deregister it.
$fx.emit()
(string, any) => void
Sends an event to the parent context, useful for dynamic parameter updates from within the code.
$fx.hash
$fx.hash
The string hash injected into the iteration. Will be unique for every iteration of a project. Directly grabbed from the fxhash URL parameter when the iteration is loaded.
$fx.rand()
$fx.rand()
The $fx.rand()
function is a Pseudorandom Number Generator which outputs a number between 0 and 1 ([0; 1[). It uses the unique hash injected into the code as a seed, and will always output the same sequence of numbers.
The fx(hash) API provides an implementation of SFC32 (Standard Fast Counter 32) as the PRNG. The $fx.rand()
function also points to the equivalent fxrand()
function, although they can be used interchangeably, we recommend using the syntax that prepends the $fx
object for consistency across your code.
It is not mandatory to use the $fx.rand()
function as your source of randomness, you can implement the PRNG of your choice instead, as long as it uses the hash as the seed.
$fx.rand.reset()
$fx.rand.reset()
You can reset $fx.rand()
PRNG to its initial state by calling $fx.rand.reset()
:
$fx.minter
$fx.minter
The string wallet address of the minter injected into the iteration. Directly grabbed from the fxminter URL parameter when the iteration is loaded.
$fx.randminter()
$fx.randminter()
Similarly to the $fx.rand()
function, the $fx.randminter()
function is another Pseudorandom Number Generator that derives its randomness from the minter address injected into the code as a seed, and will always output the same sequence of numbers. It outputs a number between 0 and 1 ([0; 1[)
.
The fxhash snippet provides an implementation of SFC32 (Standard Fast Counter 32) as the PRNG. The $fx.randminter()
function also points to the fxrandminter()
function. You can use the two of them interchangeably, but we recommend using the $fx
syntax for consistency accross your code.
It is not mandatory to use the $fx.randminter()
function as your source of randomness, you can implement the PRNG of your choice instead, as long as it uses the minter address as the seed.
$fx.randminter.reset()
$fx.randminter.reset()
Similarly to $fx.rand.reset()
you can also reset the $fx.randminter()
PRNG to its initial state by calling $fx.randminter.reset()
.
$fx.context
$fx.context
The $fx.context
property is a flag that indicates the context in which the code is executed. There are 3 possible values for this flag:
standalone: (default) when the final output should be displayed, on the main project page for instance
capture: when the code is executed in the capture environment, to get an image preview of an iteration
minting: when the code is executed during the minting flow of the collector
This flag is passed in by fx(hash) via the fxcontext
URL parameter.
$fx.iteration
$fx.iteration
The $fx.iteration
property indicates the iteration number of the collected GENTK, it can be used for experimental purposes to base certain aspects of the artwork off of it:
The iteration number is passed in by fx(hash) via the fxiteration
URL parameter.
$fx.preview()
$fx.preview()
The $fx.preview() function triggers the capture module when the code is run in the capture context, which creates the image previews that will be displayed by fxhash and other websites to show the collected iterations.
For projects where an animation is rendered, this function can be particularly useful to trigger a capture for a particular frame:
Also make sure to properly configure the capture settings when minting your project on fxhash, you can read more about this in Minting Interface Walkthrough
$fx.isPreview
$fx.isPreview
The $fx.isPreview
is a boolean which will be set to true if your code is being run in the capture context. It can be useful when you want to run a certain snippet of code only during when the artwork is being captured.
When a capture of an iteration is taken by fxhash capture module, an url parameter preview=1
is added. The fxhash snippet detects if this parameter is set to 1 and sets $fx.isPreview
to true or false based on that.
$fx.features(features)
$fx.features(features)
Artists have the option to expose certain characteristics in an explicit manner via fx(hash) ‘features’. Features are essentially attributes that describe certain aspects of the artwork once it is collected. For instance, the artist can choose to explicitely indicate the rarity of a certain output with a feature, or can also describe the randomly chosen color palette that is used for the coloration of the artwork by exposing the name of this color palette with another feature.
In other words, features are tags that describe the randomly chosen qualities of the collected artwork. They are entirely optional.
If you would like to set them in your project, you can do so via the $fx.features()
function. This function expects as input an object with key:value pairs, where these values can have the following types string
, number
or boolean
. Here’s an example:
What’s important is that features should not be hardcoded, but rather be randomly generated with the PRNG, and they should always match the visual characteristics of the Token (ie reflect the settings behind the generative process of the token).
$fx.features()
should only be called once, as multiple calls of $fx.features()
will erase features set by a previous function call. For the fx(hash) module to pick up the artist set features, the $fx.features()
function must be called once the page is loaded. For instance, the following code might result in features not getting picked up by our module:
Fxhash automatically computes the rarity of a particular feature by counting the number of occurences among all the tokens of the collection. Two feature values are considered the same if a strict equality between those returns true. If you want the rarity of a feature to be meaningful, you must define its values in a way that ensures multiple occurrences to appear.
For instance, this will not work well with the rarity module:
If defined in such a way, each token will have a different Intensity
feature value and thus they will all have the same rarity in regard to that feature. What you can do instead, is to assign a string to a range of values:
With this implementation, the value of the feature will only be low
, medium
or high
. This ensures that the rarity module will correctly assign the Intensity
feature rarity when a Token is minted. Of course, this is a very naïve implementation, you may want to adapt it to fit your needs in a better way.
$fx.getFeature(name)
$fx.getFeature(name)
This function outputs the value of a feature, given its name. Must be called after $fx.features()
. The name
parameter should match a key defined of the object passed to $fx.features()
:
Since this function requires the name of the feature to be passed to it, it can become quite verbose and redundant to call it every time you need to access the value of a feature, especially if you need this value a lot. In such a case, we recommend storing the feature value in a variable instead:
$fx.getFeatures()
$fx.getFeatures()
Returns the whole object passed to the $fx.features(object)
function. Must be called after $fx.features()
.
Last updated