Skip to content

Creating and Updating Assets

Modifying the universe

If you wish to modify the state of your universe (for example, creating a new asset, or modifying the properties of an existing asset) you must do so by creating a GraphQL mutation which passes an operation string, cryptographically signed by your account. The Freeverse platform will then check that the string's signature matches your account, to verify that you (as the universe owner) requested this change.

Using Freeverse Packages

The easiest way to create the signed GraphQL mutations is to use Freeverse's packages and our provide code examples. Currently, we only support NPM packages for NodeJS, though pip packages for python will be available soon.

NodeJS

Clone into the Freeverse examples repository and, from the terminal, navigate to the examples/nodejs directory. Run:

npm install

Using a text editor, open examples/nodejs/create_asset.js to view the example code for creating and asset.

Run the example with

npm run create -- --pvk '<your_pvk>' --owner '<address_of_owner>' --uni <universe_id_int> --nonce <asset_nonce_int>

The command takes four parameters:

  • your private key as a string (note, you could modify the code to access your private key from another method)
  • the address of the new owner of the asset (for simplicity in this demo, this could be your public address)
  • your universe ID number (provided by Freeverse)
  • the nonce value for the user (see below)

A valid GraphQL mutation, signed by your account, will be printed to console. You may now paste this into GraphQL Playground, or send it via CURL or whichever method of your choosing to our API endpoint.

Obtaining the nonce for a user

If you wish to obtain the current nonce value needed for the above command, you can do so with the following query:

query {
    usersUniverseByUserIdAndUniverseId(universeId: 0, userId: "<address_of_owner>"){
        nonce
    }
}

Sending the mutation

Paste the output of the console into GraphQL Playground (open to the API endpoint we provide you).

CreateSuccessImage

Congratulations, you have just created a new asset! You can use the ID returned by GraphQL to query information about this asset, or update its properties (see the Readme file in the examples repository for more information).

Next: Involving Your Users