Aftermath
  • Aftermath
    • About Aftermath Finance
      • What are we building?
  • Getting Started
    • Creating an account
      • zkLogin
        • Removing a zkLogin account
      • Sui Metamask Snap
      • Native Sui wallets
    • Dynamic Gas
    • Navigating Aftermath
      • Interacting with your Wallet
      • Viewing your Portfolio
      • Changing your Settings
      • Bridge
      • Referrals
  • Trade
    • Smart-Order Router
      • Agg of Aggs
      • Making a trade
      • Exact Out
      • Fees
    • DCA
      • Why should I use DCA
      • How does DCA work
      • Tutorials
        • Creating a DCA order
        • Monitoring DCA progress
        • Advanced Features
      • Fees
      • Contracts
  • Limit Orders
    • Contracts
    • Fees
  • Pools
    • Constant Function Market Maker
      • Tutorials
        • Depositing
        • Withdrawing
        • Creating a Pool
      • Fees
      • Contracts
      • Audit
  • Farms
    • Afterburner Vaults
      • Tutorials
        • Staking into a Farm
        • Claiming Rewards
        • Unstaking
        • Creating a Farm
      • Architecture
        • Vault
        • Stake Position
      • Fees
      • FAQs
  • Liquid Staking
    • afSUI
      • Tutorials
        • Staking
        • Unstaking
      • Architecture
        • Packages & Modules
        • Entry Points
      • Fees
      • FAQs
      • Contracts
      • Audit
  • Perpetuals
    • Aftermath Perpetuals
      • Tutorials
        • Creating an Account
        • Selecting a Market
        • Creating a Market Order
        • Creating a Limit Order
        • Maintaining your Positions
      • Architecture
        • Oracle Prices
        • Margin
        • Account
        • Trading
        • Funding
        • Liquidations
        • Fees
  • GameFi
    • NFT AMM
      • Architecture
        • Fission Vaults
        • AMM Pools
      • Tutorials
        • Buy
        • Sell
        • Deposit
        • Withdraw
      • Sui Overflow
  • Our validator
    • About us
  • Developers
    • Aftermath TS SDK
      • Utils
        • Coin
        • Users Data
        • Authorization
      • Products
        • Prices
        • Router
        • DCA
        • Limit Orders
        • Liquid Staking
        • Pools
        • Farms
    • Aftermath REST API
  • Egg
    • About Egg
  • Legal
    • Terms of Service
    • Privacy Policy
  • Languages
    • 中文
    • 한국어
  • Links
    • X
    • Telegram
    • Discord
    • Github
    • Medium
    • Aftermath Validator
Powered by GitBook
On this page
  • Users Data
  • Initialization
  • Get Users Public Key
  • Create User Public Key
  • Complete Example
  1. Developers
  2. Aftermath TS SDK
  3. Utils

Users Data

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

Users Data

Initialization

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

const userData = afSdk.UserData();

Get Users Public Key

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

Create User Public Key

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

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();
PreviousCoinNextAuthorization

Last updated 1 month ago