Creating an Account

What is an Account?

Account๋ž€ Aptos ๋„คํŠธ์›Œํฌ์—์„œ ๋ณด์œ ํ•œ ์ž์‚ฐ๊ณผ NFT์— ๋Œ€ํ•œ ์ ‘๊ทผ ๊ถŒํ•œ์„ ๋‚˜ํƒ€๋‚ด๋Š” ๊ฐ์ฒด์ž…๋‹ˆ๋‹ค. ์‚ฌ์šฉ์ž๋Š” Account๋ฅผ ์ƒ์„ฑํ•˜์—ฌ ์ž”๊ณ ๋ฅผ ์ €์žฅ, ์ „์†กํ•  ์ˆ˜ ์žˆ์œผ๋ฉฐ ๋ชจ๋“ˆ์„ ๋ฐฐํฌ ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

Aptos TypeScript SDK๋ฅผ ์ด์šฉํ•˜์—ฌ ๊ณ„์ •์„ ์ƒ์„ฑํ•˜๋ฉด ๋‹ค์Œ๊ณผ ๊ฐ™์€ ๋‹จ๊ณ„๋ฅผ ์‹คํ–‰ํ•ฉ๋‹ˆ๋‹ค.

  1. ์‚ฌ์šฉ์ž ๊ณ„์ •์„ ๊ด€๋ฆฌํ•˜๊ธฐ ์œ„ํ•œ ์ธ์ฆ ์ฒด๊ณ„ ์„ ํƒ(Ed25519 ๋˜๋Š” Secp256K1 ECDSA)
  2. ์ƒˆ๋กœ์šด ๊ณต๊ฐœ ํ‚ค, ๊ฐœ์ธ ํ‚ค ์Œ ์ƒ์„ฑ
  3. ๊ณต๊ฐœ ํ‚ค์™€ ์ธ์ฆ ์ฒด๊ณ„๋ฅผ ๊ฒฐํ•ฉํ•˜์—ฌ 32๋ฐ”์ดํŠธ ํฌ๊ธฐ์˜ ์ธ์ฆ ํ‚ค์™€ ๊ณ„์ • ์ฃผ์†Œ ์ƒ์„ฑ

How to generate Accounts in Aptos?

๐Ÿ“˜

์ด ํŠœํ† ๋ฆฌ์–ผ์„ ํ†ตํ•ด ์•„๋ž˜ ๋‚ด์šฉ์„ ๋ฐฐ์šธ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค!

  • Account๋ฅผ ์ƒ์„ฑํ•˜๋Š” ๋ฐฉ๋ฒ•์„ ๋ฐฐ์šธ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.
  • Private Key๋ฅผ ์ด์šฉํ•˜์—ฌ ์ด์šฉ ์ค‘์ธ Account ๋ถˆ๋Ÿฌ์˜ค๋Š” ๋ฐฉ๋ฒ•์„ ๋ฐฐ์šธ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.
  • Mnemonic๊ณผ HD Wallet์˜ Path๋ฅผ ์ด์šฉํ•˜์—ฌ ์‹ ๊ทœ Account๋ฅผ ์ƒ์„ฑํ•˜๋Š” ๋ฐฉ๋ฒ•์„ ๋ฐฐ์šธ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.
  • ์ „์ฒด ํŠœํ† ๋ฆฌ์–ผ ์ฝ”๋“œ๋Š” ์•„๋ž˜ ๋งํฌ๋ฅผ ํ†ตํ•ด ํ™•์ธํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

1. generate

์ƒˆ ๊ณ„์ •์„ ์ƒ์„ฑํ•˜๊ธฐ ์œ„ํ•ด ๊ฐ€์žฅ ๋งŽ์ด ์‚ฌ์šฉํ•˜๋Š” ๋ฉ”์„œ๋“œ ์ž…๋‹ˆ๋‹ค. Aptos์˜ ์„œ๋ช… ์ฒด๊ณ„๋Š” Ed25519 ์ธ์ฝ”๋”ฉ์„ ๊ธฐ๋ณธ์œผ๋กœ ํ•˜๋ฉฐ ์‚ฌ์šฉ์ž์˜ ํ•„์š”์„ฑ์— ๋”ฐ๋ผ Secp256k1ECDSA ์„œ๋ช… ์ฒด๊ณ„๋ฅผ ์ง€์ •ํ•ด ๊ณ„์ •์„ ์ƒ์„ฑํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

import { Account } from "@aptos-labs/ts-sdk";
const account = Account.generate();

Step 1. account.ts ํŒŒ์ผ์„ ์ƒ์„ฑํ•˜๊ณ  ์•„๋ž˜์™€ ๊ฐ™์ด ์ฝ”๋“œ๋ฅผ ์ž‘์„ฑํ•˜์—ฌ ๊ณ„์ •๊ณผ Key ๊ฐ’์„ ํ™•์ธํ•ด ๋ณด์„ธ์š”!

import { Account } from "@aptos-labs/ts-sdk";

const account = Account.generate();

console.log("your account :", account);
console.log("your privateKey :", account.privateKey.toString());
console.log("your publicKey :", account.publicKey.toString());
console.log("your address :", account.accountAddress.toString());

2. fromPrivateKey

์‚ฌ์šฉ์ž๊ฐ€ ๋ณด์œ ํ•˜๊ณ  ์žˆ๋Š” Private Key๋ฅผ ์ด์šฉํ•ด Account๋ฅผ ์ƒ์„ฑํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. ์‚ฌ์šฉ์ž์˜ privateKey๋ฅผ ์ด์šฉํ•˜์—ฌ PrivateKey ์ธ์Šคํ„ด์Šค๋ฅผ ๋งŒ๋“ค๊ณ  ์ด๋ฅผ ์ด์šฉํ•˜์—ฌ Account๋ฅผ ์ƒ์„ฑํ•ฉ๋‹ˆ๋‹ค.

const privateKey = "0x123..."
const ed25519Scheme = new Ed25519PrivateKey(privateKey);
const account = Account.fromPrivateKey({ privateKey : Ed25519Scheme });

Step 2. ๊ฐœ์ธ ํ‚ค๋ฅผ ์ด์šฉํ•ด Account๋ฅผ ์ƒ์„ฑํ•ด ๋ณด์„ธ์š”!

  • ์ž์‹ ์ด ์†Œ์œ ํ•œ Aptos Wallet์˜ Private Key๋ฅผ ์ด์šฉํ•ด ๊ณ„์ •์„ ๋งŒ๋“ค์–ด ๋ณด์„ธ์š”. ๊ทธ๋ฆฌ๊ณ  ์ƒ์„ฑ๋˜๋Š” ๊ณ„์ •์˜ ์ฃผ์†Œ๊ฐ€ Aptos Wallet์—์„œ ํ™•์ธ ๊ฐ€๋Šฅํ•œ ์ฃผ์†Œ์™€ ๋™์ผํ•œ์ง€ ํ™•์ธํ•ด ๋ณด์„ธ์š”.
  • Aptos ์ง€๊ฐ‘์ด ์—†๋‹ค๋ฉด generate ๋ฉ”์„œ๋“œ๋ฅผ ์ด์šฉํ•˜์—ฌ Account๋ฅผ ์ƒ์„ฑํ•œ ํ›„ ํŠœํ† ๋ฆฌ์–ผ์„ ์ง„ํ–‰ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.
import { Account, Ed25519PrivateKey } from "@aptos-labs/ts-sdk";

const privateKey = "input_your_private_key"; // 0x12345...
const ed25519Scheme = new Ed25519PrivateKey(privateKey);
const account = Account.fromPrivateKey({ privateKey: ed25519Scheme });

console.log("your account :", account);
console.log("your privateKey :", account.privateKey.toString());
console.log("your publicKey :", account.publicKey.toString());
console.log("your address :", account.accountAddress.toString());

3 . fromDerivationPath

mnemonic๊ณผ HD Wallet์˜ Path๋ฅผ ์ด์šฉํ•˜์—ฌ Account๋ฅผ ์ƒ์„ฑํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. path๋Š” ์ง€๊ฐ‘์˜ ๊ฒฝ๋กœ ๊ตฌ์กฐ๋กœ BIP44์— ํ˜•์‹์ด ์ •์˜๋˜์–ด ์žˆ์œผ๋ฉฐ Aptos๋Š” BIP44 ํ˜•์‹์— ๋งž์ถฐ 637๋ฒˆ์œผ๋กœ ๋“ฑ๋ก๋˜์–ด ์žˆ์Šต๋‹ˆ๋‹ค. ์ž์„ธํ•œ ๋‚ด์šฉ์€ ์•„๋ž˜ ๋งํฌ๋ฅผ ํด๋ฆญํ•˜์—ฌ ํ™•์ธํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

const account = Account.fromDerivationPath({
  path,
  mnemonic
});

Step 3 : Mnemonic๊ณผ Path๋ฅผ ์ด์šฉํ•ด Account๋ฅผ ์ƒ์„ฑํ•ด ๋ณด์„ธ์š”!

  • mnemonic์€ Mnemonic Random Generator ์‚ฌ์ดํŠธ ํ˜น์€ ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ๋ฅผ ์ด์šฉํ•˜์—ฌ ์–ป์„ ์ˆ˜ ์žˆ์œผ๋ฉฐ 12๊ฐœ์˜ ๋‹จ์–ด๊ฐ€ ํ•„์š”ํ•ฉ๋‹ˆ๋‹ค.
  • Aptos๋Š” Ed25519 scheme์„ ์ด์šฉํ•  ๊ฒฝ์šฐ, Hardened path๋ฅผ ์ž…ํ•ด์•ผ ํ•ฉ๋‹ˆ๋‹ค. ๋ณธ ํŠœํ† ๋ฆฌ์–ผ์—์„œ๋Š” Ed25519 scheme์„ ์ด์šฉํ•˜์—ฌ Account๋ฅผ ๊ตฌํ˜„ํ•˜๊ฒ ์Šต๋‹ˆ๋‹ค.
import { Account } from "@aptos-labs/ts-sdk";

const mnemonic = "<input your mnemonic(12 words)>";
const path = "m/44'/637'/0'/0'/0'";

const account = Account.fromDerivationPath({
  path,
  mnemonic: mnemonic,
});

console.log("your account :", account);
console.log("your privateKey :", account.privateKey.toString());
console.log("your publicKey :", account.publicKey.toString());
console.log("your address :", account.accountAddress.toString());

์œ„์˜ ์ฝ”๋“œ๋ฅผ ์‹คํ–‰ํ•˜์—ฌ Account ๊ฐ์ฒด๋ฅผ ํ™•์ธํ•  ์ˆ˜ ์žˆ๋‚˜์š”?

  • ํ™•์ธ์ด ๋˜์ง€ ์•Š๋Š”๋‹ค๋ฉด ์œ„์˜ ์ฝ”๋“œ์™€ ๋‹ค๋ฅธ ๋ถ€๋ถ„์ด ์žˆ๋Š”์ง€ ํ™•์ธํ•ด ๋ณด์„ธ์š”.
  • ์œ„์˜ ์ฝ”๋“œ์™€ ์ฐจ์ด๊ฐ€ ์—†๋Š”๋ฐ ๋˜์ง€ ์•Š๋‚˜์š”? ์—ฌ๊ธฐ[QnA ๋งํฌ]๋ฅผ ํด๋ฆญํ•˜์—ฌ QnA๋กœ ๋‚จ๊ฒจ์ฃผ์„ธ์š”!

๐Ÿ“˜

Aptos๋Š” ๋งค์šฐ ๋น ๋ฅด๊ฒŒ ์—…๋ฐ์ดํŠธ ๋˜๊ณ  ์žˆ์Šต๋‹ˆ๋‹ค!

Aptos ์žฌ๋‹จ์—์„œ ๋ฐฐํฌํ•œ SDK ๋ฒ„์ „์— ๋”ฐ๋ผ ๋ณ€๊ฒฝ๋˜๋Š” ์ ์ด ์žˆ์„ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. Nodit์€ ํ•ญ์ƒ ์ด๋ฅผ ํ™•์ธํ•˜๊ณ  ์žˆ์œผ๋‚˜ ์‹œ์ ์— ๋”ฐ๋ผ ์ฝ”๋“œ ๋ณ€๊ฒฝ์œผ๋กœ ์ธํ•œ ์˜ค๋ฅ˜๊ฐ€ ๋ฐœ์ƒํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.