# On-chain Tracking

We aim to understand better and recognise our key contributors who are driving the adoption of smart accounts within our ecosystem.

Implementing a Safe on-chain identifier enables tracking of complex data, such as whether a Safe transaction is executed via our SDK or another, whether it originates from a platform like a Safe App or widget (for example, the CoW Swap widget in our Safe interface), the tool version, the project, and more.

By submitting your on-chain identifier through the form provided at the end of this page, you will help us accurately attribute activity and allow us to return value to our Ecosystem Partners in the future.

<Callout type='info' emoji='ℹ️'>
  On-chain tracking is supported starting from [Protocol Kit](../sdk/protocol-kit.mdx) `v5.2.0` and [Relay Kit](../sdk/relay-kit.mdx) `v3.4.0`.
</Callout>

## On-chain identifier format

The identifiers used to track Safe deployments and transactions are 50 bytes in length and follow the format below:

`5afe` `00` `6363643438383836663461336661366162653539` `646561` `393238` `653366`

Check the last 50 bytes of the `data` field in this [example transaction](https://sepolia.etherscan.io/tx/0xe0192eedd1fc2d06be0561d57380d610dd6d162af0f3cfbd6c08f9062d738761) to see how the identifier appears after the transaction is executed.

### Prefix hash

- **Type:** `2 bytes`
- **Example:** `5afe`

Static prefix to identify the Safe on-chain identifier.

### Version hash

- **Type:** `1 byte`
- **Example:** `00`

Version number of the Safe on-chain identifier format.

### Project hash

- **Type:** `20 bytes`
- **Example:** `6363643438383836663461336661366162653539`

Truncated hash of the project's name (for example, "Gnosis", "CoW Swap").

### Platform hash

- **Type:** `3 bytes`
- **Example:** `646561`

Truncated hash of the platform's name (for example, "Web", "Mobile", "Safe App", "Widget").

### Tool hash

- **Type:** `3 bytes`
- **Example:** `393238`

Truncated hash of the tool's name (for example, "protocol-kit", "relay-kit", or any custom tool built by projects).

### Tool version hash

- **Type:** `3 bytes`
- **Example:** `653366`

Truncated hash of the tool's version (for example, "1.0.0", "1.0.1").

## Steps

The on-chain identifier allows tracking the deployment of Safe accounts, the execution of Safe transactions, and the execution of Safe user operations:

<Steps>

  ### Generate an on-chain identifier

  Feel free to skip this section if you use the Protocol Kit or Relay Kit from the Safe\{Core\} SDK, as this is handled internally.

  To create an on-chain identifier with the format described above, you need to implement a function that receives the `project`, `platform`, `tool`, and `toolVersion` used; and returns the correct identifier after hashing, truncating, and concatenating all these parameters.


  ```typescript
  function generateOnChainIdentifier({
    project,
    platform = 'Web',
    tool,
    toolVersion
  }: OnChainIdentifierParamsType): string {
    const identifierPrefix = '5afe' // Safe identifier prefix
    const identifierVersion = '00' // First version
    const projectHash = generateHash(project, 20) // Take the last 20 bytes
    const platformHash = generateHash(platform, 3) // Take the last 3 bytes
    const toolHash = generateHash(tool, 3) // Take the last 3 bytes
    const toolVersionHash = generateHash(toolVersion, 3) // Take the last 3 bytes

    return `${identifierPrefix}${identifierVersion}${projectHash}${platformHash}${toolHash}${toolVersionHash}`
  }

  function generateHash(input: string, size: number): string {
    const fullHash = keccak256(toHex(input))
    return toHex(fullHash.slice(-size)).replace('0x', '') // Take the last X bytes
  }
  ```


  This identifier will be added to all your Safe transactions and become searchable on-chain.

  ### Track Safe deployments
  
  Safe deployments can be tracked by concatenating the on-chain identifier at the end of the deployment transaction `data`. This way Safe deployment transactions will include the identifier.
  
  If you use the [Protocol Kit](../sdk/protocol-kit.mdx) or the [Relay Kit](../sdk/relay-kit.mdx) to deploy a Safe, adding the `onchainAnalytics` property to the initialization method will automatically handle this.
  
  If you use a custom implementation, remember to manually add the on-chain identifier at the end of the deployment transaction `data`.


  <Tabs items={['Protocol Kit', 'Relay Kit']}>
    <Tabs.Tab>
      ```typescript
      import Safe, { OnchainAnalyticsProps } from '@safe-global/protocol-kit'

      const onchainAnalytics: OnchainAnalyticsProps = {
        project: 'YOUR_PROJECT_NAME' // Required. Always use the same value for your project.
        platform: 'CURRENT_PLATFORM' // Optional
      }

      const protocolKit = await Safe.init({
        // ...
        onchainAnalytics
      })

      // Execute the deployment
      ```
    </Tabs.Tab>
    <Tabs.Tab>
      ```typescript
      import { Safe4337Pack } from '@safe-global/relay-kit'
      import { OnchainAnalyticsProps } from '@safe-global/protocol-kit'

      const onchainAnalytics: OnchainAnalyticsProps = {
        project: 'YOUR_PROJECT_NAME' // Required. Always use the same value for your project.
        platform: 'CURRENT_PLATFORM' // Optional
      }
      
      const safe4337Pack = await Safe4337Pack.init({
        // ...
        onchainAnalytics
      })

      // Execute the deployment
      ```
    </Tabs.Tab>
  </Tabs>


  ### Track Safe transactions

  Safe transactions can be tracked by concatenating the on-chain identifier at the end of the transaction `data` or user operation `callData` properties. This way Safe transactions will include the identifier.

  If you use the [Protocol Kit](../sdk/protocol-kit.mdx) or the [Relay Kit](../sdk/relay-kit.mdx) to execute the Safe transactions, adding the `onchainAnalytics` property to the initialization method will automatically handle this.

  If you use a custom implementation, remember to manually add the on-chain identifier at the end of the transaction `data`/`callData`.


  <Tabs items={['Protocol Kit', 'Relay Kit']}>
    <Tabs.Tab>
      ```typescript
      import Safe, { OnchainAnalyticsProps } from '@safe-global/protocol-kit'

      const onchainAnalytics: OnchainAnalyticsProps = {
        project: 'YOUR_PROJECT_NAME'
        platform: 'CURRENT_PLATFORM' // Optional
      }

      const protocolKit = await Safe.init({
        // ...
        onchainAnalytics
      })

      // Execute the transaction
      ```
    </Tabs.Tab>
    <Tabs.Tab>
      ```typescript
      import { Safe4337Pack } from '@safe-global/relay-kit'
      import { OnchainAnalyticsProps } from '@safe-global/protocol-kit'

      const onchainAnalytics: OnchainAnalyticsProps = {
        project: 'YOUR_PROJECT_NAME'
        platform: 'CURRENT_PLATFORM' // Optional
      }
      
      const safe4337Pack = await Safe4337Pack.init({
        // ...
        onchainAnalytics
      })

      // Execute the transaction
      ```
    </Tabs.Tab>
  </Tabs>


  ### Get the on-chain identifier

  If you use the Protocol Kit or the Relay Kit, call the `getOnchainIdentifier` method from an initialized instance of the Protocol Kit to get the current Safe on-chain identifier.


  ```typescript
  const onchainIdentifier = protocolKit.getOnchainIdentifier()
  ```


</Steps>

## Submission Form

You can fill out the form by clicking [this link](https://forms.gle/NYkorYebc6Fz1fMW6) or using the form below:

<br/>

<iframe
  src="https://docs.google.com/forms/d/e/1FAIpQLSfHWSPbSQwmo0mbtuFFewfLvDEOvTxfuvEl7AHOyrFE_dqpwQ/viewform?embedded=true"
  width="100%"
  height="1750"
  frameborder="0"
>Loading…</iframe>
