Skip to main content
A Function receives parameters, performs a calculation, and returns a result. This example converts a raw USDC amount into token units. Open your Space. This example uses demo; replace it with your Space ID.

Create the function

  1. Open Functions and click + at the top right of the list.
  2. In New Function, enter usdc_amount and click Save and open.
  3. Replace the default editor code with:
The console uses _ as the entry point. raw_amount is the raw integer USDC amount. USDC has 6 decimal places, so dividing by 10 ** 6 gives the token amount.

Define parameters

Hover over the parameter bar below the editor and click +. In Add parameter, set: Click Save in the dialog, then Save at the top of the page. Parameter order must match the positional arguments of _. Once saved, click the parameter chip to reopen the same dialog, now titled Edit parameter.
The Add parameter dialog with raw_amount and type UINT256
The saved Function ID is demo.usdc_amount: demo is the Space ID and usdc_amount is the Function name.

Test the result

Enter 1500000 in the parameter input, move focus out of the input, and click Run. Return should show 1.5.
usdc_amount returns 1.5 for input 1500000
Make later changes in the same editor. When unsaved changes appears, click Review to inspect changes and Save to save them. See Test and debug for saving test parameters.