SDK
crossbell.js
Guides
Operator

Operator

Operator is a role that can be granted to an address to perform certain operations on behave of a character. For example:

  • A operator can help a character edit their username, avatar, bio, etc.
  • A operator can help a character post, edit their note.
  • A operator can help a character follows others.
  • ...

An address can be an operator for multiple characters, and a character can have multiple operators.

An operator can be granted granular permissions to perform certain operations on behave of a character. You can learn more about the permissions in the Spec - Operator - Permissions section.

Granting Operators

You can:

Please refer to the API documentation for more details.

Revoking Operators

Say that we have granted an operator 0x1234567890123456789012345678901234567890 to a character 42 as below:

operator.grantForCharacter({
  characterId: 42, // characterId
  operator: '0x1234567890123456789012345678901234567890', // operator
  permissions: ['LINK_NOTE', 'UNLINK_NOTE', 'POST_NOTE'] // permissions
})

If we want to revoke the operator, we can do so by passing an empty array to the permissions argument:

operator.grantForCharacter({
  characterId: 42, // characterId
  operator: '0x1234567890123456789012345678901234567890', // operator
  permissions: [] // empty array to revoke the operator
})

Query Operators

To query the operators of a character:

// Query the operators of a character
const { list } = await indexer.operators.getManyForCharacter(42)
 
// Query a specific operator of a character
const data = await indexer.operators.getForCharacter(42, '0x1234567890123456789012345678901234567890')

To query the operators of a note:

// Query the operators of a note
const { list } = await indexer.operators.getManyForNote(42)
 
// Query a specific operator of a note
const data = await indexer.operators.getForNote(42, '0x1234567890123456789012345678901234567890')

Topics

Robot: Sync Tweets from Twitter

If you want to sync your tweets from Twitter to Crossbell automatically, here is the way using a robot operator to do it:

  1. Create a wallet to play the role of the robot. Set it up on a server to run 24/7 monitoring your Twitter account.
  2. Grant the robot address the permission "POST_NOTE" to be able to post notes on behave of your character. This can be done with contract.operator.grantForCharacter (opens in a new tab).
  3. When the robot detects a new tweet, it can post a note on behave of your character with contract.note.post (opens in a new tab).

You can basically make a robot to do anything you want on behave of your character. Use your imagination!

Note Editing Collaboration

Imagine a scenario where you’re a KOL having millions of followers on Crossbell and you’ve made a rough outlined draft about your vision of ‘Crossbell is the future’ but you don’t really had the time to take care of things here and there, so you have to ask 2 of your employees as to polish your draft.

You can post your draft with contract.note.post (opens in a new tab) first, then grant your employees the permission to edit your note with contract.operator.grantForNote (opens in a new tab):

// Post a note
const { data } = await contract.note.post(
  characterId: 42,
  metadataOrUri: "https://example.com/note.json",
);
 
// Grant operators
await contract.operator.grantForNote({
  characterId: 42,
  noteId: data.noteId,
  allowlist: [
    "0x1234567890123456789012345678901234567890",
    "0x2345678901234567890123456789012345678901",
  ],
  blocklist: [],
});

Now your employees can edit your note with contract.note.setUri (opens in a new tab):

// Set note URI
await contract.note.setUri({
  characterId: 42,
  noteId: data.noteId,
  metadataOrUri: "https://example.com/note-edited.json",
});