# Users Data

## Users Data

### Initialization

```typescript
const afSdk = new Aftermath("MAINNET");
await afSdk.init(); // initialize provider

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
});
```

### 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 = new Aftermath("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();
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.aftermath.finance/for-developers/typescript-sdk/utils/users-data.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
