SDK
crossbell.js
Contract API
Character
Update Metadata

Update Metadata

See more about character metadata in the Spec - Character Metadata section.

setCharacterUri

This sets (overwrites) a character's metadata (URI).

setCharacterUri(characterId: BigNumberish, metadataOrUri: string | CharacterMetadata, overrides?: Overrides): Promise<Result<{ metadata: CharacterMetadata; uri: string; }, true>>

Usage

contract.setCharacterUri(10, 'https://example.com/character.json');

Or:

contract.setCharacterUri(10, {
  name: 'My Character',
  bio: 'This is my character',
});
⚠️

The new metadata will overwrite the old metadata, so if you only want to update a single field, you'll need to fetch the existing metadata first and merge it with the new metadata. Otherwise, you'll lose the other fields. If you want to update a part of fields, you can use the changeCharacterMetadata method instead.

Parameters

characterId

  • Type: BigNumberish

The ID of the character to update.

metadataOrUri

  • Type: string | CharacterMetadata

The new metadata or URI to set.

Returns

interface Returns {
  data: {
    metadata: CharacterMetadata;
    uri: string;
  },
  transactionHash: string;
}

Alternative: setCharacterMetadata

This is basically the same as setCharacterUri, but it takes a CharacterMetadata object instead of a string.

contract.setCharacterMetadata(10, {
  name: 'My Character',
  bio: 'This is my character',
});

changeCharacterMetadata

This changes a character's metadata by merging the new metadata with the existing metadata.

changeCharacterMetadata(characterId: BigNumberish, modifier: ((metadata?: CharacterMetadata) => CharacterMetadata), overrides?: Overrides): Promise<Result<{ metadata: CharacterMetadata; uri: string; }, true>>

Usage

contract.changeCharacterMetadata('42', metadata => {
  if (metadata !== undefined) {
    metadata.name = 'John Doe'
    metadata.bio = 'I am a person'
  } else {
    metadata = {
      name: 'John Doe',
      bio: 'I am a person',
    }
  }
  return metadata
})

Or you can use the spread operator to merge:

contract.changeCharacterMetadata('42', metadata => {
  metadata = {
    ...metadata,
    name: 'John Doe',
    bio: 'I am a person',
  }
  return metadata
})

Parameters

characterId

  • Type: BigNumberish

The ID of the character to update.

modifier

  • Type: (metadata?: CharacterMetadata) => CharacterMetadata

A function that takes the existing metadata and returns the new metadata.

Returns

interface Returns {
  data: {
    metadata: CharacterMetadata;
    uri: string;
  },
  transactionHash: string;
}