-
Notifications
You must be signed in to change notification settings - Fork 75
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
docs: Add On-chain tracking page #671
base: main
Are you sure you want to change the base?
Changes from all commits
ff328b3
330c672
c98a5c9
6ab7fcf
c711a0c
e271cde
75c1449
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"getOnchainIdentifier": "getOnchainIdentifier" | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import { Tabs } from 'nextra/components' | ||
|
||
# `getOnchainIdentifier` | ||
|
||
Returns the on-chain identifier generated internally. This identifier is appended to the `data` field of transactions to enable on-chain tracking. | ||
|
||
## Usage | ||
|
||
{/* <!-- vale off --> */} | ||
|
||
<Tabs items={['example.ts', 'setup.ts']}> | ||
<Tabs.Tab> | ||
```typescript | ||
import { protocolKit } from './setup.ts' | ||
|
||
const onchainIdentifier = await protocolKit.getOnchainIdentifier() | ||
|
||
console.log(onchainIdentifier) // e.g., '5afe006562303761323539616336346466346135306537646561393238383963' | ||
``` | ||
</Tabs.Tab> | ||
<Tabs.Tab> | ||
```typescript | ||
import Safe from '@safe-global/protocol-kit' | ||
|
||
export const protocolKit = Safe.init({ | ||
// ... | ||
onchainAnalytics: { | ||
project: 'Cow Swap', // Specify your project name | ||
platform: 'Web' // Optional platform | ||
} | ||
}) | ||
``` | ||
</Tabs.Tab> | ||
</Tabs> | ||
|
||
{/* <!-- vale on --> */} | ||
|
||
## Returns | ||
|
||
`string` | ||
|
||
The on-chain identifier in hexadecimal format (`5afe00...`), which includes hashed metadata such as project name, platform, tool, and tool version. | ||
|
||
For more details about the identifier format, please refer to the [On-chain identifier](../../sdk/onchain-tracking.mdx#on-chain-identifier-format) section. |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,5 +22,6 @@ | |
"title": "Integrations" | ||
}, | ||
"signers": "Signers", | ||
"onchain-tracking": "On-chain Tracking", | ||
"onramp": "Onramp" | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,186 @@ | ||
import { Tabs, Steps } from 'nextra/components' | ||
|
||
# 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. | ||
|
||
## 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> | ||
|
||
### Track Safe deployments | ||
|
||
Safe deployments can be tracked by assigning an on-chain identifier to the [`paymentReceiver`](../reference-smart-account/setup/setup.mdx#paymentreceiver) or [`saltNonce`](https://github.com/safe-global/safe-smart-account/blob/main/contracts/proxies/SafeProxyFactory.sol#L55) properties during the Safe configuration and deployment. | ||
|
||
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. The deployment transaction will include the identifier. | ||
|
||
{/* <!-- vale off --> */} | ||
|
||
<Tabs items={['Protocol Kit', 'Relay Kit']}> | ||
<Tabs.Tab> | ||
```typescript | ||
import Safe, { OnchainAnalyticsProps } from '@safe-global/protocol-kit' | ||
|
||
const onchainAnalytics: OnchainAnalyticsProps = { | ||
project: 'YOUR_PROJECT_NAME' | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. How about we add a comment like this to help developers better understand? It clarifies that the project field is mandatory and should remain consistent for each project:
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sounds good. I will make a reference that this field is linked to the |
||
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' | ||
platform: 'CURRENT_PLATFORM' // Optional | ||
} | ||
|
||
const safe4337Pack = await Safe4337Pack.init({ | ||
// ... | ||
onchainAnalytics | ||
}) | ||
|
||
// Execute the deployment | ||
``` | ||
</Tabs.Tab> | ||
</Tabs> | ||
|
||
{/* <!-- vale on --> */} | ||
|
||
### 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. | ||
|
||
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. The Safe transactions will include the identifier. | ||
|
||
{/* <!-- vale off --> */} | ||
|
||
<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> | ||
|
||
{/* <!-- vale on --> */} | ||
|
||
### Get the on-chain identifier | ||
|
||
To get the current safe on-chain identifier, you can use the `getOnchainIdentifier` method from an initialized instance of the Protocol Kit. | ||
|
||
{/* <!-- vale off --> */} | ||
|
||
```typescript | ||
const onchainIdentifier = protocolKit.getOnchainIdentifier() | ||
``` | ||
|
||
{/* <!-- vale on --> */} | ||
|
||
</Steps> | ||
|
||
## Submission Form | ||
|
||
<br/> | ||
|
||
<iframe | ||
src="https://docs.google.com/forms/d/e/1FAIpQLSfHWSPbSQwmo0mbtuFFewfLvDEOvTxfuvEl7AHOyrFE_dqpwQ/viewform?embedded=true" | ||
width="100%" | ||
height="1750" | ||
frameborder="0" | ||
>Loading…</iframe> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The on-chain identifier will always be appended to the end of the
data
field of the deployment transaction, both for Safe deployments and Safe transactions. Using thepaymentReceiver
orsaltNonce
was an initial idea, but it's not part of the final implementation.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, I know that is how the SDK works, but here it refers about the different options that exist for people using onchain tracking without the SDK. This sections has two paragrap: the initial one that shows the different options and the second one that shows how the SDK works. I will make it more explicit that the SDK only uses
data
.