Join our
Discord!
LogoLogo
SupraScan ExplorerStarKey WalletDiscord
MoveVM
  • Network
  • Oracles
  • Automation
  • Guides
MoveVM
  • Overview
  • Getting Started
    • Install Supra CLI with Docker
    • Create a Supra Account
    • Create a Move Package
      • Initialize a Package
      • Write a Module
      • Compile and Publish
      • Interact with a Package
    • Create a dApp with StarKey
  • Network Information
  • Token Standards
  • Learn Move 101
    • Getting Started with Move
    • Unsigned Integers in Move
    • Math Operations in Move
    • Using Vectors in Move
    • Reading Resource Data with borrow_global
    • Passing Data in Move: Value vs. Reference
    • Adding Elements with vector::push_back
    • Emitting Events with event::emit
  • Move Book
    • Getting Started
      • Modules and Scripts
      • Move Tutorial
    • Primitive Types
      • Integers
      • Bool
      • Address
      • Vector
      • Signer
      • References
      • Tuples and Unit
    • Basic Concepts
      • Local Variables and Scope
      • Equality
      • Abort and Assert
      • Conditionals
      • While, For, and Loop
      • Functions
      • Structs and Resources
      • Constants
      • Generics
      • Type Abilities
      • Uses and Aliases
      • Friends
      • Packages
      • Package Upgrades
      • Unit Tests
    • Global Storage
      • Structure
      • Operators
    • Reference
      • Standard Library
      • Coding Conventions
  • TypeScript SDK
    • Guides
      • Create Supra Accounts
      • Publish a Package
    • Documentation
    • Repository
  • Rest API
    • Mainnet
      • Accounts
      • Faucet
      • Transactions
      • Block
      • View
      • Consensus
      • Events
      • Tables
    • Testnet
      • Accounts
      • Faucet
      • Transactions
      • Block
      • View
      • Events
      • Tables
  • Developer Resources
    • Supra Dapp Templates
    • Supra Move VS Code Extension
  • Links
    • Supra DevHub
    • SupraScan Block Explorer
    • StarKey Wallet
    • Live Data Feeds
    • Whitepapers
    • Security Audits
    • Supra's Official GitHub
Powered by GitBook
On this page
  • SupraAccount class constructor
  • fromDerivePath function
  • Example
Edit on GitHub
  1. TypeScript SDK
  2. Guides

Create Supra Accounts

How to create new and import existing accounts.

PreviousGuidesNextPublish a Package

class constructor

new SupraAccount();
new SupraAccount(Buffer.from("YOUR_PRIVATE_KEY","hex"));

Create a new supra account or create one from the provided private key. If no privateKeyBytes parameter is provided, a new account will be generated.

Parameters

Name
Type
Optional

privateKeyBytes

Uint8Array

address

MaybeHexString

Returns


function

Create a new SupraAccount from mnemonic.

SupraAccount.fromDerivePath(path, mnemonic);

Parameters

Name
Type
Optional

path

string

mnemonics

string

Returns


Example

The SupraAccount class allows you to generate new accounts, import private key, or derive from mnemonics.

1

Initialize a new project

npm init && npm add -D typescript @types/node ts-node && npx tsc --init
2

Install Supra's TypeScript SDK

npm install supra-l1-sdk
3

Create supra_account_example.ts and import dependencies

supra_account_example.ts
import { SupraAccount} from "supra-l1-sdk";
4

Generate a new account

const newAccount = new SupraAccount();
5

Generate an account from private key

const accountFromPk = new SupraAccount(
    Buffer.from("YOUR_PRIVATE_KEY", "hex")
);
6

Generate an account from mnemonics

const path = "m/44'/637'/0'/0'/0'";
const mnemonic = "";
const accountFromMnemonics = SupraAccount.fromDerivePath(path, mnemonic);
7

Complete code

supra_account_example.ts
import { SupraAccount } from "supra-l1-sdk";

async function main(){

    const newAccount = new SupraAccount();
    console.log("newAccount: ", newAccount.address());

    const accountFromPk = new SupraAccount(Buffer.from("YOUR_PRIVATE_KEY", "hex"));
    console.log("accountFromPk Address: ", accountFromPk.address());

    const path = "m/44'/637'/0'/0'/0'";
    const mnemonic = "";
    const accountFromMnemonics = SupraAccount.fromDerivePath(path, mnemonic);
    console.log("accountFromMnemonics: ", accountFromMnemonics.address());

}

main();
8

Execute code npx ts-node supra_account_example.ts

SupraAccount
SupraAccount
fromDerivePath
SupraAccount