> For the complete documentation index, see [llms.txt](https://docs.aftermath.finance/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.aftermath.finance/for-developers/typescript-sdk/utils/users-data.md).

# Users Data

Provider that allows to interact with users data. (E.g. Public key)

## Users Data

### Initialization

```typescript
const afSdk = await Aftermath.create({ network: "MAINNET" });

const userData = afSdk.UserData();
```

### Get Users Public Key

```typescript
const publicKey = userData.getUserPublicKey({
	walletAddress: "0x.."
});
```

### Create User Public Key

```typescript
const messageToSign = userData.createUserAccountMessageToSign();

const signedMessage = await signPersonalMessage({
	message: new TextEncoder().encode(JSON.stringify(messageToSign)),
});

const publicKey = userData.createUserPublicKey({
	walletAddress: "0x..",
	bytes: signedMessage.bytes,
  	signature: signedMessage.signature
});
```

### Create Reusable Terms Message

Use the canonical terms message for current DCA and limit-order cancellation, GasPool sponsorship, referral/rewards actions, and authenticated perpetuals reads:

```typescript
const message = userData.createTermsAndConditionsMessage();
// "Aftermath Terms and Conditions"

const signedMessage = await signPersonalMessage({
	message: new TextEncoder().encode(message),
});
```

Send `signedMessage.bytes` and `signedMessage.signature` with the wallet address. Request-specific order IDs, filters, and referral codes remain plain request fields. `createSignTermsAndConditionsMessageToSign()` is deprecated and returns the old action-specific payload; do not use it for these routes.

### Complete Example

```typescript
import { Aftermath } from "aftermath-ts-sdk";
import { Ed25519Keypair } from "@mysten/sui/keypairs/ed25519";
import dotenv from "dotenv";

dotenv.config();

const privateKeyHex = String(process.env.SECRET); // Use your own secret key
const keyPair = Ed25519Keypair.fromSecretKey(privateKeyHex);
const walletAddress = keyPair.getPublicKey().toSuiAddress();

const aftermath = await Aftermath.create({ network: "MAINNET" });
const userData = aftermath.UserData();

const test = async () => {
	const messageToSign = userData.createUserAccountMessageToSign();
	const message = new TextEncoder().encode(JSON.stringify(messageToSign));

	const signedMessage = await keyPair.signPersonalMessage(message);

	const success = await userData.createUserPublicKey({
		...signedMessage,
		walletAddress,
	});

	const userPk = await userData.getUserPublicKey({
		walletAddress,
	});

	console.log({ success, userPk });
};

test();
```
