# Intro to Otterspace

What is Otterspace?

The Otterspace Protocol is a flexible and composable platform for building with non-transferable NFTs, which we call 'badges'. Badges are a status and reputation primitive used throughout communities, social applications, marketplaces, and media to represent achievements, skills, experience, roles, trustworthiness, and more. Badges are already an established concept in Web2, but why bring them on-chain?

**Not-transferable tokens**

We believe that primitives such as identity and reputation should not be sold to the highest bidder and are something that should be earned. Non-transferable tokens or Soulbound token standards are most well suited for this. Our protocol implement [EIP-4973](https://eips.ethereum.org/EIPS/eip-4973), the specification for Account Bound Token, for which we're an active contributor as well.&#x20;

**The benefits of on-chain Badges**

By bringing badges on-chain, builders can benefit from Web3 composability. Existing integrations enable Badges to be used as token gates for Discord and Telegram, as well as in governance applications like Snapshot. Users' memberships, roles, status, and achievements become platformless, instead of being stuck in a specific application. While Web2 applications maintain user Badges in a centralized database, Web3 enables internet users to own their status and reputation and take it with them across experiences.&#x20;

**Why build with Otterspace?**

We're building the Otterspace Protocol to solve all the core challenges related to issuing, interpreting, holding, and managing reputation primitives on-chain, so developers can focus on application-specific experiences. The Otterspace Protocol includes open-source contracts for direct integrations, as well as an API and no-code interface for ease of use.&#x20;


# Key Concepts

**Raft**

A Raft is an entity in the Otterspace Protocol that is able to issue Badges. You can think of it as an account that can create new Badge Specs and distribute Badges to individuals. Within the Protocol, a Raft is represented by a transferable ERC721 NFT called a 'Raft Token'. The Ethereum Account holding a Raft Token is the super admin of the Raft.

{% hint style="info" %}
In order to get your own Raft token, please fill out this [form](https://forms.otterspace.xyz/get-started)
{% endhint %}

**Badge Spec**

A Badge Spec is a blueprint of a Badge and contains metadata like a name and image. A single spec can have many Badges issued against it, all of which have the same metadata. For example, the Otterspace[ 'Early Otter' Badge Spec](https://beta.otterspace.xyz/badges/10:bafyreifcjs56sk5gseb75e45rjebh4kwln3trwi6aphhacf727lkshq74e) has 138 Badges issued against it. Every Badge Spec is created by a Raft and references that Raft in its metadata.

**Badge**

A Badge is an ERC4973 non-transferable NFT with a unique token id in the Otterspace Badge collection. Every Badge is associated with a Badge Spec and gets its metadata from that spec. All badges are minted under a single collection


# Burning and revocation

All Badges can be burned by the owner. Owning this non-transferable token means that you can, if you choose to, dissociate from it. This action deletes this record from the storage.

Badges can be revoked by the issuer, which renders them inactive but does not burn them. This is particularly useful if you have something like "Community Manager" in X DAO. Once you leave the DAO, you can still prove that you owned the badge but it will be set to an inactive status

If a Badge has been revoked or burned, it should no longer be used for granting access to a resource. You can check a Badge's active status by calling the `isBadgeValid` function.

Note - this status currently does not check for the "timed expiration" of the badge


# Expiration

Otterspace Badges can be set to expire. Effectively, this means that a Badge can still be present in someone’s wallet while being inactive. In these cases, the Badge should no longer act as a key to access the resource.

You can check whether a Badge is expired by looking at the `expiresAt` date in the Badge spec metadata. All Badges minted from the same spec have the same expiration date.


# Metadata schemas

There are 2 main schemas that you need to be aware of in otterspace.

* Rafts (latest version: [1.0.0](https://beta.otterspace.xyz/api/schemas/raft/1.0.0.json))
* Badges Specs (latest version: [1.0.](https://beta.otterspace.xyz/api/schemas/badge/1.0.1.json)[1](https://otterspace-api-staging.herokuapp.com/schemas/badge/1.0.1.json))

#### Rafts <a href="#block-d6ac8b5fb0044918ae3af480e890b6d0" id="block-d6ac8b5fb0044918ae3af480e890b6d0"></a>

Communities are expressed as Rafts in Otterspace. They are essentially ERC721 tokens or NFTs. A Raft’s metadta is expressed via the following hosted schema

```json
{
   "$schema":"http://json-schema.org/draft-04/schema#",
   "$id":"https://api.otterspace.xyz/schemas/raft/1.0.0.json",
   "type":"object",
   "properties":{
      "name":{
         "type":"string",
         "description":"The organization name of the Raft"
      },
      "description":{
         "type":"string",
         "description":"Describes the asset to which this Raft NFT represents"
      },
      "image":{
         "type":"string",
         "description":"A URI pointing to a resource with mime type image/* representing the asset to which this Raft NFT represents. Consider making any images at a width between 320 and 1080 pixels and aspect ratio between 1.91:1 and 4:5 inclusive."
      },
      "properties":{
         "type":"object",
         "properties":{
            "parentRaftTokenId":{
               "type":[
                  "integer",
                  "null"
               ],
               "description":"Identifies the parent organization with a Raft token ID."
            },
            "generation":{
               "type":"integer",
               "description":"Identifies the current generation of the Raft."
            }
         },
         "required":[
            "parentRaftTokenId",
            "generation"
         ]
      }
   },
   "required":[
      "name",
      "description",
      "image",
      "properties"
   ]
}
```

#### Badge Specs <a href="#block-3ac479edc73c42289f56c4bf6d62c38f" id="block-3ac479edc73c42289f56c4bf6d62c38f"></a>

A badge spec entity is essentially the design of the badge. Without a badge spec, badges cannot be issued. A badge spec must belong to a Raft and is stored on-chain. The following is the hosted schema that expressed a badge spec

```json
{
   "$schema":"http://json-schema.org/draft-04/schema#",
   "$id":"https://api.otterspace.xyz/schemas/badge/1.0.0.json",
   "type":"object",
   "properties":{
      "name":{
         "type":"string",
         "description":"Identifies the asset to which this Badge represents"
      },
      "description":{
         "type":"string",
         "description":"Describes the asset to which this Badge represents"
      },
      "image":{
         "type":"string",
         "description":"A URI pointing to a resource with mime type image/* representing the asset to which this Badge represents. Consider making any images at a width between 320 and 1080 pixels and aspect ratio between 1.91:1 and 4:5 inclusive."
      },
      "properties":{
         "type":"object",
         "properties":{
            "daoName":{
               "type":"string"
            },
            "raftTokenId":{
               "type":"string",
               "description":"The token ID of the Raft (a community, DAO, etc) that this Badge is associated with."
            },
            "raftContractAddress":{
               "type":"string",
               "description":"The contract address of the associated Raft token."
            },
            "createdByAddress":{
               "type":"string",
               "description":"A timestamp of when this badge was created."
            },
            "expiresAt":{
               "type":[
                  "string",
                  "null"
               ],
               "description":"A timestamp of when this badge would expire. This would be null if this is non-expiring"
            }
         },
         "required":[
            "daoName",
            "raftTokenId",
            "raftContractAddress",
            "createdByAddress",
            "expiresAt"
         ]
      }
   },
   "required":[
      "name",
      "description",
      "image",
      "properties"
   ]
}
```


# F.A.Q

#### How do I get access Otterspace?

In order to use Otterspace, you will need a Raft NFT. To request access, please complete [this form](https://forms.otterspace.xyz/get-started).

#### What networks do you support?

Please see our contracts section to find an up-to-date list of [supported networks](/documentation/contracts#supported-networks)

#### How can I burn my badge?

Please head over to an [admin tool](https://otterspace-utils.vercel.app/) from our community to perform this action

#### How can I revoke or reinstate a revoked badge?

Please head over to an [admin tool](https://otterspace-utils.vercel.app/) from our community to perform this action

#### How can I leave feedback to make a feature request?

If you have any questions or feedback, you can use [this form](https://airtable.com/shrBwX41lqmnDKn8C) or post in the #🤔\_ask\_away channel in our [Discord server](https://discord.com/invite/qqwEUgQGKw)

#### How can I get API access for my integration?

If you're looking to build a server-side integration, see [these instructions](/documentation/api/authentication#generating-an-api-key) to generate an API key. If you're building a cliend-side application, please get in touch with us via [Discord](https://discord.gg/6EVRFeBv)


# API

## API Servers

* **Staging:** <https://staging.otterspace.xyz/api>
* **Production:** <https://beta.otterspace.xyz/api>

## API reference

Our entire API reference can be found at the following link and it fully documented using Open API and with Swagger UI

* **Staging:** <https://staging.otterspace.xyz/api/docs/>
* **Production:** <https://beta.otterspace.xyz/api/docs/>

## Subgraphs

Subgraphs are our read-only APIs that subscribe to our on-chain events and construct easy-to-consume entities for clients. Checkout the [Subgraph](#subgraphs) section for more details


# Authentication

## Overview

While our protocol is fully open, all communications with our API will require authentication. If you're more interested in just reading the data to build something, you can use our subgraphs.&#x20;

> A Raft token (NFT) is the authorization token needed to create badges withing your account. Please fill out [this](https://forms.otterspace.xyz/get-started) form to apply for a Raft token and one of our team members will contact you ASAP and help you get setup.&#x20;

## Integration types

### Server-side integrations

Once you have obtained a Raft Token, you can generate an API key via the settings page of your Raft.&#x20;

#### Generating an API Key

* Sign in to <https://beta.otterspace.xyz/> and navigate to your Raft's settings page via the drop-down menu.&#x20;
* Click the edit icon to access Raft settings.
* Go to "API" tab
* Enter a name for your app and then click "Generate key"
* Note that this key is only viewable/copy-able only once i.e., upon generation. If you lose it, you would need to generate a new one and delete the old one

> **IMPORTANT:** you should do everything to secure your API key and it should be easily accessible to exposed unauthorized parties

<figure><img src="https://2226074966-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FAzd5KglFXWJXBKKKNfoX%2Fuploads%2FeWjVvGV59XqtzsNfk9qQ%2Fimage.png?alt=media&amp;token=9d9c3a26-d920-45eb-a0cc-8fc3d06d53df" alt=""><figcaption><p>Your raft's API settings page</p></figcaption></figure>

Note that only the API routes under `/external` are accessible with this API key for server side integrations. You will need to provide a header ‘***Authorization***’ that contains an API key as a Base64 string. Using the raw string of the API key from the UI will not work, unless it is base64 encoded. You can use this [tool](https://base64.guru/converter/encode) to help convert it.&#x20;

```bash
curl "https://staging.otterspace.xyz/api" \
		 -H "Authorization: <API key as base64 encoded string>"
```

### Client-side integrations

If you're building a client-side integration i.e., a web application without a server-side componenet for instance, you will need to use a different authentication flow called SIWE or [Sign-in With Ethereum](https://eips.ethereum.org/EIPS/eip-4361).&#x20;

> Note: API access for client-side integrations not fully open. Please contact us via email or discord to discuss your requirements and your access.

#### Step 1: Retrieve a nonce

Request

```bash
$ curl -X GET "https://staging.otterspace.xyz/api/auth/nonce" \
       -H "Content-Type: application/json"
```

Response

```json
{ "nonce": "<random nonce>" }
```

#### Step 2: Sign-in

Request

{% code fullWidth="false" %}

```bash
$ curl -X POST "https://staging.otterspace.xyz/api/auth/sign_in" \
			 -H "Content-Type: application/json" \
       -H "Accept: application/json" \
			 -d '{ "signature": "<signed message>", "message": "<message object>" }'
```

{% endcode %}

*Response*

```bash
{ "<siweMessage>" }
HTTP/1.1 200 OK
Date: Mon, 18 Aug 2022 13:08:53 GMT
...
Set-Cookie: "<created cookie for this specific user>"
```

***message*** field in the request is composed standardised off-chain authentication message proposed in [EIP-4361](https://eips.ethereum.org/EIPS/eip-4361). It is an object that have certain fields like `address`, `chainId`, `nonce`, `domain` etc. This standardised message is of type `SiweMessage` from the [`siwe`](https://github.com/spruceid/siwe) library.

```typescript
const siweMessage = new siwe.SiweMessage({
  domain: "<string>",
  address: "<string>",
  statement: "<string>",
  uri: "<string>",
  version: "<string>",
  nonce: '<received nonce from previous step>',
  issuedAt: "<YYYY-MM-DDTHH:MM:SS.000Z>",
  chainId: "<number>",
  ...
});
```

***signature*** field in the request body is signed version of the `message` created by the wallet of the user. Simply put a `message` is signed by the user's private key and then `signature` is verified on the API side using user's public key. Concept is called [elliptic curve cryptography](https://en.wikipedia.org/wiki/Elliptic-curve_cryptography). ***For a programmatic message signing please check the section*** [***below***](https://docs.otterspace.xyz/developer-docs/otterspace-platform-api-docs#d2229317fcb847698a7a2243c76520bd)***.***

> **IMPORTANT:** For authentication of further requests to API please provide **`Cookie`** HTTP Header. You can extract the cookie from response’s header **`Set-Cookie`**.

#### ✍🏼 Programmatic message generation and signing with siwe/ethers.js

```javascript
// import necessary dependencies
import {
	Wallet
} from "ethers";
import {
	SiweMessage
} from "siwe";

async function main() {
	// provide a private key for your existing wallet (you can also create a random one: Wallet.createRandom())
	const wallet = new Wallet(privateKey);

	// generate a Siwe message
	const siweMsg = new SiweMessage({
		domain: "<>", // RFC 4501 dns authority that is requesting the signing.
		wallet.address, // wallet address of the user
		statement: "<>", // Human-readable ASCII assertion that the user will sign,
		uri: "<>", // RFC 3986 URI referring to the resource that is the subject of the signing
		version: "1", // Current version of the message.
		chainId: 10, // EIP-155 Chain ID to which the session is bound, and the network where Contract Accounts must be resolved.
		nonce, // the nonce you acquired
		issuedAt: new Date().toISOString(),
	});

	// parse all the fields in the object and creates a sign message according with the type defined
	const message = siweMsg.prepareMessage();

	// sign the message with your wallet
	const signature = await wallet.signMessage(message.toString());

	return {
		signature: signature,
		message: message
	};
}
```


# Subgraph

Subgraphs are our read-only APIs that subscribe to our on-chain events and construct easy-to-consume entities for clients.&#x20;

The subgraphs urls are network specific and following the following template

* **API:** <https://api.thegraph.com/subgraphs/name/otterspace-xyz/badges-\\[network-name>]
* **Interactive:** <https://thegraph.com/hosted-service/subgraph/otterspace-xyz/badges-\\[network-name>]

<table data-full-width="false"><thead><tr><th width="179">Network</th><th>Subgraph</th></tr></thead><tbody><tr><td>Optimism</td><td><a href="https://thegraph.com/hosted-service/subgraph/otterspace-xyz/badges-optimism">https://thegraph.com/hosted-service/subgraph/otterspace-xyz/badges-optimism</a></td></tr><tr><td>Mainnet</td><td><a href="https://thegraph.com/hosted-service/subgraph/otterspace-xyz/badges-mainnet">https://thegraph.com/hosted-service/subgraph/otterspace-xyz/badges-mainnet</a></td></tr><tr><td>Polygon</td><td><a href="https://thegraph.com/hosted-service/subgraph/otterspace-xyz/badges-polygon">https://thegraph.com/hosted-service/subgraph/otterspace-xyz/badges-polygon</a></td></tr><tr><td>Goerli</td><td><a href="https://thegraph.com/hosted-service/subgraph/otterspace-xyz/badges-goerli">https://thegraph.com/hosted-service/subgraph/otterspace-xyz/badges-goerli</a></td></tr><tr><td>Optimism Goerli</td><td><a href="https://thegraph.com/hosted-service/subgraph/otterspace-xyz/badges-optimism-goerli">https://thegraph.com/hosted-service/subgraph/otterspace-xyz/badges-optimism-goerli</a></td></tr></tbody></table>

### Get a list of communities

```graphql
{
  rafts(where: {totalSpecsCount_gt: 0}) {
    id
    metadata {
      name
    }
    totalSpecsCount
    totalBadgesCount
    specs {
      metadata {
        name
      }
      totalBadgesCount
    }
  }
}
```

### Get active badges of a community

```graphql
{
  badges(
    where: { 
      spec_: { 
        raft: "rafts:1"
      } 
      status_in: ["MINTED", "REINSTATED"]
    } 
  ) {
    id
    owner
    status
    createdAt
    spec {
      metadata { 
        name
        expiresAt
      }
    }
  }
}
```

### Get all the badge specs of a community

```graphql
{
  raft(id: "rafts:1") {
    id
    metadata {
      name
    }
    totalSpecsCount
    totalBadgesCount
    specs {
      uri
      totalBadgesCount
      metadata {
        name
      }
    }
  }
}
```

### Get all the owners of a badge

```graphql
{
  badgeSpec(id: "bafyreicl3unvw6tvzjfduvrhxbfi74gsob6mpf6ekn3s2nkopqz2phtx7e") {
    id
    metadata {
      name
      description
      image
      expiresAt
    }
    totalBadgesCount
    badges {
      id
      owner
      status
      createdAt
    }
  }
}
```

### Get badges owned by an address

```graphql
{
  badges(where: {owner: "0x77B476429826C5ba77885D08F272d89D8F1Ed0e4"}) {
    id
    createdAt
    status
    spec {
      id
      metadata {
        name
        description
        expiresAt
        image
      }
      raft {
        id
        metadata {
          name
          image
        }
      }
    }
  }
}
```

### Check if an address owns a certain badge

```graphql
{
  badges(
    where: {owner: "0x77B476429826C5ba77885D08F272d89D8F1Ed0e4", spec_in: ["bafyreicl3unvw6tvzjfduvrhxbfi74gsob6mpf6ekn3s2nkopqz2phtx7e", "bafyreia2lnu2jmr6sqqijzd3xt6fw2qriyy2vbq57zikzrkeyxfvlpqp3i"]}
  ) {
    id
    owner
    status
    createdAt
  }
}
```


# Contracts

Otterspace's contracts are open sourced and we welcome contributions. Please go to our github repository for more details

* <https://github.com/otterspace-xyz/otterspace-contracts/>

We essentially have 3 upgradable contracts, predominantly using OpenZeppelin libraries

* Raft.sol
* Badges.sol
* SpecDataHolder.sol

For all minting interactions, you only need to use the `Badges.sol` contract

### Supported networks

<table><thead><tr><th width="162">Netrwork</th><th>Address</th><th data-hidden>Contract</th></tr></thead><tbody><tr><td>Optimism</td><td>Raft: <a href="https://optimistic.etherscan.io/address/0xa6773847d3D2c8012C9cF62818b320eE278Ff722">0xa6773847d3D2c8012C9cF62818b320eE278Ff722</a><br>Badges: <a href="https://optimistic.etherscan.io/address/0x7F9279B24D1c36Fa3E517041fdb4E8788dc63D25">0x7F9279B24D1c36Fa3E517041fdb4E8788dc63D25</a><br>SpecDataHolder: <a href="https://optimistic.etherscan.io/address/0x5c0B0B9c94f297f208375212AA70e5F86df6cb1B">0x5c0B0B9c94f297f208375212AA70e5F86df6cb1B</a></td><td>Raft</td></tr><tr><td>Polygon</td><td>Raft: <a href="https://polygonscan.com/address/0xa74caa864A2562999faf38280A3aA3d09c248daA">0xa74caa864A2562999faf38280A3aA3d09c248daA</a><br>Badges: <a href="https://polygonscan.com/address/0x147e0dF40fdD1340C604726c670329c08176F208">0x147e0dF40fdD1340C604726c670329c08176F208</a><br>SpecDataHolder: <a href="https://polygonscan.com/address/0xdb8346eaf8c4a7ef82b17ce7843df8a9d00dc524">0xdB8346EAF8C4A7eF82B17Ce7843dF8A9d00dC524</a></td><td></td></tr><tr><td>Mainnet</td><td>Raft: <a href="https://etherscan.io/address/0x7465dA7E01A5FF3b2b1699EDa9E617A1329C14b8">0x7465dA7E01A5FF3b2b1699EDa9E617A1329C14b8</a><br>Badges: <a href="https://etherscan.io/address/0x4537e34d5044626d72b3da203e7ffe997245947c">0x4537e34D5044626d72b3da203e7ffE997245947C</a><br>SpecDataHolder: <a href="https://etherscan.io/address/0x39DfCa12FCf403aa027aa64C04bCfB5eFF95d402">0x39DfCa12FCf403aa027aa64C04bCfB5eFF95d402</a></td><td></td></tr><tr><td>Goerli</td><td><p>Raft: <a href="https://goerli.etherscan.io/address/0xBb8997048e5F0bFe6C9D6BEe63Ede53BD0236Bb2">0xBb8997048e5F0bFe6C9D6BEe63Ede53BD0236Bb2</a> </p><p>Badges: <a href="https://goerli.etherscan.io/address/0xa6773847d3D2c8012C9cF62818b320eE278Ff722">0xa6773847d3D2c8012C9cF62818b320eE278Ff722</a></p><p>SpecDataHolder: <a href="https://goerli.etherscan.io/address/0xA3716e7794F756e7a22145516FcB87C962576ce4">0xA3716e7794F756e7a22145516FcB87C962576ce4</a></p></td><td></td></tr><tr><td>Optimism Goerli</td><td><p>Raft: <a href="https://goerli-optimism.etherscan.io/address/0xcd31CFCd7b784C5F4f51D4EaC45376bA30F9C3Eb">0xcd31CFCd7b784C5F4f51D4EaC45376bA30F9C3Eb</a></p><p>Badges: <a href="https://goerli-optimism.etherscan.io/address/0x940f3b56fd53028f5d76a9ca335b1a9a6135528a">0x940f3B56FD53028f5d76a9cA335b1a9a6135528A</a></p><p>SpecDataHolder: <a href="https://goerli-optimism.etherscan.io/address/0xbdBF9157BCF6a3f7cE9F7BdcFCa3067727F515F2">0xbdBF9157BCF6a3f7cE9F7BdcFCa3067727F515F2</a></p></td><td></td></tr><tr><td>Sepolia</td><td><p>Raft: <a href="https://sepolia.etherscan.io/address/0xa74caa864A2562999faf38280A3aA3d09c248daA">0xa74caa864A2562999faf38280A3aA3d09c248daA</a></p><p>Badges: <a href="https://sepolia.etherscan.io/address/0x147e0dF40fdD1340C604726c670329c08176F208">0x147e0dF40fdD1340C604726c670329c08176F208</a></p><p>SpecDataHolder: <a href="https://sepolia.etherscan.io/address/0xdB8346EAF8C4A7eF82B17Ce7843dF8A9d00dC524">0xdB8346EAF8C4A7eF82B17Ce7843dF8A9d00dC524</a></p></td><td></td></tr></tbody></table>

### Authorization with a Raft NFT

A Raft token (NFT) is the authorization token needed to create badges withing your account. Please fill out [this](https://forms.otterspace.xyz/get-started) form to apply for a Raft token and one of our team members will contact you ASAP and help you get setup.&#x20;


# Create a Badge Spec

Design a Badge Spec & upload to IPFS

```json
{
   "schema":"<https://api.otterspace.xyz/schemas/badge/1.0.1.json>",
   "name":"First Badge",
   "description":"Otterspace Badge",
   "properties":{
      "raftTokenId":"90",
      "createdByAddress":"0xeD40624Deb1202e63D0729b6411FfA0Efb333aD9",
    "expiresAt": "2023-07-21T13:57:28.882Z"
   },
   "image":"ipfs://bafybeifqjf35xulfl46uauwbsqbrjgxa4d3iybjvdq7bo6xzdlaq6mpr6u/image"
}
```

Badges are maximally backward compatible with ERC-721 and hence we use NFT metadata to represent the Badge Spec.&#x20;

The example Badge Spec above is hosted on IPFS at

{% embed url="<https://ipfs.io/ipfs/bafyreigrhoupt3dcjuadq7i34cetwla2axfwayyszffoixfrrmr2ttthoe/metadata.json>" %}

Before issuing Badges to Ethereum Accounts, you need to create a Spec like the one above and upload it to IPFS.


# Airdrop a Badge

Install the contracts

```bash
npm -i @otterspace-xyz/otterspace-contracts
```

Call the airdrop function on the contracts to mint an non-consented Badge

```tsx
import { Contract, Signer } from 'ethers'
import Badges from '@otterspace-xyz/contracts/out/Badges.sol/Badges.json' assert { type: 'json' }

const BADGES_CONTRACT_ADDRESS = '0x7F9279B24D1c36Fa3E517041fdb4E8788dc63D25'

const mintBadge = async (
    toAddress: string,
		fromAddress: Signer,
    badgeSpecURI: string
): Promise<ContractCallResult> => {
    const contract = new Contract(BADGES_CONTRACT_ADDRESS, Badges.abi, fromAddress)
    const doAirdrop = contract['airdrop']
    return await doAirdrop([toAddress], badgeSpecURI)
}
```


# Adding to allowlist

Approve someone to mint this Badge using EIP-712

In order to approve someone to mint a Badge, a signature using EIP-712 is necessary

```tsx
import { utils } from "ethers"

const typedData = {
    domain: {
      name: 'BADGES',
      version: '1.0.0',
      chainId: 10, // optimism chainId
      verifyingContract: '0x7F9279B24D1c36Fa3E517041fdb4E8788dc63D25',
    },
    types: {
      Agreement: [
        { name: 'active', type: 'address' },
        { name: 'passive', type: 'address' },
        { name: 'tokenURI', type: 'string' },
      ],
    },
    value: {
      active: claimant.address, // issuer of badge 
      passive: issuer.address, // receiver of badge
      tokenURI: specUri, // uri of badge
    },
  }

// See: <https://docs.ethers.io/v5/api/signer/#Signer-signTypedData> for more detailed instructions.
const signature = await signer._signTypedData(typedData.domain, typedData.types, typedData.value)
const { compactSignature } = utils.splitSignature(signature)
```


# Minting allowlisted Badges

Claim and mint the Badge using the signature

Call `take(address _from, string calldata _uri, bytes calldata _signature)` on the Badges [contract](https://github.com/otterspace-xyz/otterspace-contracts/blob/dev/src/Badges.sol#L86)

```tsx
import { Contract, Signer } from 'ethers'
import Badges from '@otterspace-xyz/contracts/out/Badges.sol/Badges.json' assert { type: 'json' }

const BADGES_CONTRACT_ADDRESS = '0x7F9279B24D1c36Fa3E517041fdb4E8788dc63D25'

const mintBadge = async (
    badgeReceiver: Signer,
		fromAddress: string,
    badgeSpecURI: string,
    compactSignature: string
): Promise<ContractCallResult> => {
    const contract = new Contract(BADGES_CONTRACT_ADDRESS, Badges.abi, badgeReceiver)
    const doTake = contract['take']
    return await doTake(fromAddress, badgeSpecURI, compactSignature)
}
```


# Add/Remove Admins

The Super Admin is the holder of the Raft Token and has full control over Badge Spec creation, airdrops, allowlisting, and badge revocation. Other users or addresses can be granted admin rights, including the ability to create and issue Badges, thus enabling a more flexible system with distributed administrative privileges. However, it's important to note that only Super Admins have the authority to add or remove other admins.

On the `Raft` contract you can call `setAdmins(uint256 tokenId, address[] memory admins, bool[] memory isActive`

The purpose of this function is to modify the **`isAdmin`** value of a list of administrators. It provides the ability to add or remove multiple administrators at once or perform a combination of both actions.

```tsx
import { Contract, Signer } from 'ethers'
import Raft from '@otterspace-xyz/contracts/out/Raft.sol/Raft.json' assert { type: 'json' }

const RAFT_CONTRACT_ADDRESS = '0xBb8997048e5F0bFe6C9D6BEe63Ede53BD0236Bb2'

const mintBadge = async (
    raftReceiver: Signer,
		raftTokenId: string,
    adminList: string[],
    isActiveList: string[]
): Promise<ContractCallResult> => {
    const contract = new Contract(RAFT_CONTRACT_ADDRESS, Raft.abi, raftReceiver)
    const callSetAdmins = contract['setAdmins']
    return await callSetAdmins(raftTokenId, adminList, isActiveList)
}
```


# Token-gating using badges

Token gating by Badge spec implies that only holders of Badges belonging to one or more specs are able to get through the token gate.

## Finding the badge spec id

First, you need to get the id of the Badge Spec that you used to issue badges to different addresses.

You can find the Badge spec id in the url of the Badge page.

```json
https://beta.otterspace.xyz/badges/bafyreifcjs56sk5gseb75e45rjebh4kwln3trwi6aphhacf727lkshq74e 
```

## Fetching all the holders of a badge spec <a href="#block-dfc5e417412245708e1cb8c33c14d822" id="block-dfc5e417412245708e1cb8c33c14d822"></a>

You can use our [subgraph](https://thegraph.com/hosted-service/subgraph/otterspace-xyz/badges-optimism) to fetch all the badge owners of that spec

```graphql
{
  badgeSpec(id: "bafyreicl3unvw6tvzjfduvrhxbfi74gsob6mpf6ekn3s2nkopqz2phtx7e") {
    id
    metadata {
      name
      description
      image
      expiresAt
    }
    totalBadgesCount
    badges {
      id
      owner
      createdAt
    }
  }
}
```

## Does an address hold a Badge belonging to this spec? <a href="#block-af7faa94cb834da3afcea2d6599fc198" id="block-af7faa94cb834da3afcea2d6599fc198"></a>

If you already know the address of a user, you can simply check if this address owns a badge with the spec that you intend to gate. For example, see the query below. Here we’re checking if the address `0x77B476429826C5ba77885D08F272d89D8F1Ed0e4` owns a **Pioneer badge** issued by the **Otterspace** Raft.&#x20;

```graphql
{
  badges(where: {owner: "0x77B476429826C5ba77885D08F272d89D8F1Ed0e4", spec: "bafyreicl3unvw6tvzjfduvrhxbfi74gsob6mpf6ekn3s2nkopqz2phtx7e"}) {
    id
    createdAt
    owner
    createdAt
    spec {
      id
      metadata {
        name
      }
      raft {
        id
        metadata {
          name
        }
      }
    }
  }
}
```

And if you’d like to check if an address owns one of the badges, simply use `spec_in` filter

```graphql
{
  badges(
    where: {owner: "0x77B476429826C5ba77885D08F272d89D8F1Ed0e4", spec_in: ["bafyreicl3unvw6tvzjfduvrhxbfi74gsob6mpf6ekn3s2nkopqz2phtx7e","bafyreia2lnu2jmr6sqqijzd3xt6fw2qriyy2vbq57zikzrkeyxfvlpqp3i"]}
  ) {
    id
    createdAt
    owner
    createdAt
    spec {
      id
      metadata {
				name
			}
      raft {
        id
        metadata {
					name 
				}
      }
    }
  }
}
```

## Filtering out expired and revoked Badges <a href="#block-f21deb7ed2d247ceab04e0b51a74151d" id="block-f21deb7ed2d247ceab04e0b51a74151d"></a>

One thing that makes Badges different from other NFTs is that they can expire. Expired Badges shouldn’t be able to be used to access spaces and resources. You can check if a Badge is expired by looking at the expiry date in the metadata.

## Filtering by community <a href="#block-83f3750341364940a1f101cea52ef4e4" id="block-83f3750341364940a1f101cea52ef4e4"></a>

If you are building a token-gating UI, you probably want to allow an account admin to select from the Badge Specs belonging to that account.

The unique identifier of a Raft is the Token Id of an ERC721 token which is airdropped to the community during its formation. The Raft Id can be found in the community’s profile url.

```json
https://beta.otterspace.xyz/communities/1
```


# Using badges with Snapshot

You can use Otterspace Badges for governance in Snapshot using the **Otterspace Badges Snapshot strategy**. A Snapshot strategy is a function for calculating a member’s voting power based on their tokens. You can [learn more about strategies in Snapshot’s docs](https://docs.snapshot.org/strategies/what-is-a-strategy).

> 💡 When you set a Snapshot strategy you are making this change for all proposals in your whole Snapshot space. If you want to use different strategies for different proposals, you need to change the space settings between proposals. Keep in mind that changing the strategy only changes it for proposals moving forward, not retroactively.

### Setting up your Badges strategy in Snapshot <a href="#block-452bcba0229a45c5b545521f13bf02b6" id="block-452bcba0229a45c5b545521f13bf02b6"></a>

To add the Otterspace Badges strategy to Snapshot, first navigate to your space’s settings.

![](data:image/svg+xml,%3csvg%20xmlns=%27http://www.w3.org/2000/svg%27%20version=%271.1%27%20width=%27528%27%20height=%27317.70773638968484%27/%3e)![image](https://docs.otterspace.xyz/_next/image?url=https%3A%2F%2Fassets.super.so%2F5e10f36d-c96f-402d-8656-67f77cc28c6d%2Fimages%2F7edef13b-6d3a-4be5-a7b0-66061b5778ca%2Fsnapshot_space.png\&w=1080\&q=80)

Scroll down to the ‘strategies’ section and click ‘add strategy’

![](data:image/svg+xml,%3csvg%20xmlns=%27http://www.w3.org/2000/svg%27%20version=%271.1%27%20width=%27432%27%20height=%27302.4%27/%3e)![image](https://docs.otterspace.xyz/_next/image?url=https%3A%2F%2Fassets.super.so%2F5e10f36d-c96f-402d-8656-67f77cc28c6d%2Fimages%2Fdf9300ea-1a97-4764-b891-9d2d1b2ece41%2FScreenshot_2022-09-13_at_11.36.35.png\&w=1080\&q=80)💬Check out our video walkthrough of how to set up the Badges Snapshot strategy [here](https://www.loom.com/share/728a0178b8fb48aca1aac522be1fb361).

#### Editing Strategy Details <a href="#block-0d2fd398ec60449a8863402c3b7b1db2" id="block-0d2fd398ec60449a8863402c3b7b1db2"></a>

When adding the otterspace-badges strategy, you will be prompted to edit the strategy details. You need to do this in order to specify which badges can be used in voting and how much voting power they have.

There are 3 variables you need to edit in the strategy (see A, B and C below). You can add badges by adding another badge object following the format below (see the curly brackets in bold - that is a badge object).

```json
{
   "symbol":"BADGES",
   "raftTokenId":"A",
   "specs":[
      {
         "id":"B",
         "weight":"C"
      },
      {
         "id":"B",
         "weight":"C"
      }
   ]
}
```

`A`- This is the token id of your Raft token. You can find it by navigating to the asset on Etherscan or finding your Raft in the [collection on Quixotic](https://qx.app/collection/0xa6773847d3D2c8012C9cF62818b320eE278Ff722) and navigating to the details section on the token.

`B` - This is the id of the badge, which you can find as part of the url on the badge page. Navigate to the badge page for the badge you want to use in the strategy, and copy the final section of the url (example highlighted in yellow below)

<https://beta.otterspace.xyz/badges/bafyreicl3unvw6tvzjfduvrhxbfi74gsob6mpf6ekn3s2nkopqz2phtx7e>

`C` - This is the weight of the badge in the governance strategy. You can think of a weight of 1 as one vote, and a weight of 2 having two votes.

> 💡 We will soon be releasing a page in the Otterspace app that allows you to easily configure these settings and copy the resulting code to Snapshot.

### What if someone has multiple Badges, how does this affect their voting power? <a href="#block-6b8c60f358bd4f81ad08de4ea96bd294" id="block-6b8c60f358bd4f81ad08de4ea96bd294"></a>

If a DAO member has multiple Badges in their wallet when they vote, the strategy will use the weight of their most powerful Badge.

We are considering building another strategy that adds up the votes from multiple Badges - let us know [here](https://airtable.com/shrBwX41lqmnDKn8C) if that would be useful to you.

### Using Badges and your DAO token for voting at the same time <a href="#block-6d37c6af798a4386a0a6e4876d1f46a6" id="block-6d37c6af798a4386a0a6e4876d1f46a6"></a>

> 💡 Snapshot allows you to use multiple strategies at the same time, meaning that Badges and your DAO token can be both used for governance in the same vote.

If you are using multiple strategies in Snapshot, voting power is cumulative across strategies. In other words, if you use the Badges strategy and an ERC20 ‘balance of’ strategy, then someone who has a badge and ERC20 tokens will get voting power from both.

When using multiple strategies, you need to think about how you set the weights of each token. If you set the weight of an ERC20 token as “1”, and the weight of a badge as “1”, then they have the same voting power. A weight of 2 has twice as much voting power as a weight of 1.

#### Example <a href="#block-044c906eef934d5e86e788fc4dcca808" id="block-044c906eef934d5e86e788fc4dcca808"></a>

The OtterDAO Snapshot space has 2 strategies (this means they are both running at the same time).

**Strategy 1: ERC20 Balance of**

Holders of $OTR get one vote for each token they hold. \[Token voting weight is 1].

**Strategy 2: Otterspace Badges**

Holders of the ‘Alpha Otter’ Badge get 10,000 votes. \[Badge voting weight is 10,000]

Holders of the ‘Rock Holder’ Badge get 1,000 votes. \[Badge voting weight is 1,000]

### How the strategies work together <a href="#block-e31de6eb985e4073b7e3591d23ba1ff7" id="block-e31de6eb985e4073b7e3591d23ba1ff7"></a>

**Oliver**

Holds 20,000 $OTR = 20,000 votes

Holds 1 Alpha Otter Badge = 10,000 votes

⇒ Oliver has 30,000 votes

**Ophelia**

Holds 10,000 $OTR = 10,000 votes

Holds 1 Alpha Otter Badge and 1 Rock Holder Badge = 10,000 votes \[only the more powerful badge is counted]

⇒ Ophelia has 20,000 votes

### Using Badges for governance on Snapshot in a sub-DAO <a href="#block-913a11301cfb407197d1e39949fec814" id="block-913a11301cfb407197d1e39949fec814"></a>

By setting up sub-space in Snapshot, you can use different Badges for governance in different teams/guilds/pods/sub-DAOs. For example, you might want to use only Engineering Guild badges for governance over the Engineering Guild budget.

To do this, first set up a sub-space in Snapshot and then configure the strategy for the space based on the Badges you want to use in governance.

> 💬 Check out our video walkthrough of how to set up a sub-DAO in Snapshot [here](https://www.loom.com/share/f58ef152c8b44211a744df9731e18ce8).


# Guild.xyz for token gating

With Guild, you can use your Badges to distribute permissions in Discord channels, Telegram groups, GitHub repos, and Google Docs. 🔑

Guild allows you to build complex logic around which tokens members have to hold in order to access spaces and resources across the apps mentioned above. You can create and / or logic to include multiple tokens in your gate.

### Adding a Badge to a token-gate on Guild <a href="#block-0c3075e8de13480c9fbb9f4d8efd840a" id="block-0c3075e8de13480c9fbb9f4d8efd840a"></a>

If Guild is already set up and you want to add a Badge to the token-gate, simply edit the role and select ‘Otterspace’ from the list of integrations.

This will open a drop-down list where you can search and choose the Badge you want to use in the token-gate. If a holder has an expired Badge, it will be ignored.

![image](https://docs.otterspace.xyz/_next/image?url=https%3A%2F%2Fassets.super.so%2F5e10f36d-c96f-402d-8656-67f77cc28c6d%2Fimages%2F442e9d75-a452-4e90-a409-ba707bd0c09b%2FScreenshot_2022-10-13_at_14.03.55.png\&w=3840\&q=80)

### Setting up Guild for the first time <a href="#block-da06910b4eb841568d528e8b7d983b35" id="block-da06910b4eb841568d528e8b7d983b35"></a>

Guild works by setting requirements to get roles, which have rewards attached to them. A requirement might be “has the Core Contributor Badge” a role might be “Core Contributor” and a reward might be “gets access to the Discord role ‘core\_team’”.

First, set up your community and roles, then attach Badge requirements to the roles (see above). Finally, select which rewards are associated with each role.

Guild has a great explanation [here](https://docs.guild.xyz/guild/guides/readme#making-your-first-guild).


# Using with Gnosis Safe

As part of setting up your community in Otterspace, you’ll mint a [Raft Token](https://docs.otterspace.xyz/your-guide-to-otterspace/how-communities-are-represented-within-otterspace), which is a transferable NFT that you can think of as the admin ‘key’ to Otterspace.

The wallet holding the Raft Token is the admin of the community on Otterspace, and can take actions like creating a new Badge spec and issuing Badge vouchers to community members. Because this NFT is transferable, you can move it to different wallets depending on your community’s current needs.

#### Holding your Raft Token in a multisig vs. EOA <a href="#block-02507487cc2a4a4099455432c4641664" id="block-02507487cc2a4a4099455432c4641664"></a>

If you have one community manager who is going to be managing Badges, it might be easiest for them to hold the Raft Token in a wallet they control. This is likely to be the easiest (but not very decentralized) way to manage Badges.

Alternatively, you can hold the Raft Token in a multisig wallet like a [Gnosis Safe](https://app.safe.global/). This is a less centralized alternative, as a Gnosis Safe can act as a shared wallet for the community.

If you choose to use a Gnosis Safe for holding your Raft Token, we highly recommend enabling a **1 of n** signing policy, meaning that individual signers can take actions without requiring approval from a second signer. If you have a policy requiring multiple signers, you will need to wait for approval every time you create a new Badge spec or add a member to an allowlist to a Badge.

> 💡The Otterspace app is not yet optimized for waiting for multiple signatures. If you do want to use a Safe with this policy, make sure to collect signatures while you keep the app open in your browser.

Keep in mind that the **Raft Token is on Optimism,** so you will likely need a new Gnosis Safe anyway - you won’t need to change the policy on your treasury multisig.

> 💡Gnosis Safe is a smart contract wallet, which means that even signatures will cost gas. Keep in mind that you will need funds on both your Safe and your signing wallet to complete transactions. Costs are low on Optimism, but you will have to [bridge](https://app.optimism.io/bridge/deposit) a few dollars to be able to use the app.>&#x20;


# On OpenSea, Metamask etc

Since Badges are maximally compatible with ERC-721 and they actually implement the `IERC721Metadata` interface, Badges will look and feel exactly like NFTs (minus the transferability).

<table><thead><tr><th width="164">Network</th><th>Url</th></tr></thead><tbody><tr><td>Optimism</td><td><a href="https://opensea.io/collection/otterspace-badges-optimism">https://opensea.io/collection/otterspace-badges-optimism</a></td></tr><tr><td>Polygon</td><td><a href="https://opensea.io/collection/otterspace-badges-polygon">https://opensea.io/collection/otterspace-badges-polygon</a></td></tr><tr><td>Mainnet</td><td>Coming soon</td></tr></tbody></table>


# Discord/Twitter

Come ask question in our Discord! <https://discord.gg/6EVRFeBv>

Or hit us up on Twitter: <https://twitter.com/otterspace_xyz?lang=en>


