[졸과][NEAR] 테스트넷 계정 생성

2024. 3. 1. 02:55·프로젝트/졸업과제

배경

Near Protocol의 Testnet에서 Named Account를 생성하기 위해 고군분투했다. 그 결과, 로컬에서 Testnet 계정을 생성하기 위해서는 near를 보유한 기존 계정의 FAK(Full Access Key)가 반드시 필요한 줄 알았는데, 그렇지 않다는 걸 깨달았다!

 

계정 생성 흐름

메인넷

  1. Implicit Account 생성은 제한없이 가능
  2. near를 보유한 기존 계정에서 막 생성된 Implicit Account로 near를 송금한다.
  3. Account ID를 지정하여 Named Account로 전환한다.

 

테스트넷

  • 그냥 바로 일정 near를 보유한 Named Account를 생성하면 된다.
  • 메인넷의 생성 흐름을 따를 수도 있다.

near-cli

Near 공식 문서

 

NEAR CLI | NEAR Documentation

The NEAR Command Line Interface (CLI) is a tool that enables to interact with the NEAR network directly from the shell. Among other things,

docs.near.org

 

# near를 보유한 기존 계정의 near로 새 계정을 생성한다.
near create-account new-acc.testnet --useAccount example-acct.testnet

# Testnet의 faucet의 near를 사용해서 새 계정을 생성한다.
near create-account new-acc.testnet --useFaucet

 

 

near-api-js

import { utils, keyStores, KeyPair, connect, providers } from 'near-api-js';

const myKeyStore = new keyStores.BrowserLocalStorageKeyStore();

const config = {
  networkId: 'testnet',
  keyStore: myKeyStore,
  nodeUrl: 'https://rpc.testnet.near.org',
  walletUrl: 'https://testnet.mynearwallet.com/',
  helperUrl: 'https://helper.testnet.near.org',
};

export async function createNearAccount(creatorAccountId: string, newAccountId: string, amount: string) {
  const near = await connect(config);
  const creatorAccount = await near.account(creatorAccountId);
  const keyPair = KeyPair.fromRandom('ed25519');
  const publicKey = keyPair.getPublicKey().toString();

  await myKeyStore.setKey(config.networkId, newAccountId, keyPair);
  try {
  	// 계정 생성 함수
    await creatorAccount.createAccount(newAccountId, publicKey, utils.format.parseNearAmount(amount));
    console.log('Account creation successful');
    return true;
  } catch (error) {
    console.error('Account creation failed:', error);
    return false;
  }
}

 

- near-api-js에서 생성자 계정을 Account 객체로 불러와서 createAccount 메서드를 호출한다.

- 확실하게 새로운 Named Account를 생성할 수 있지만, 로컬에서 생성자 계정의 FAK(Full Access Key)를 보유하고 있어야 해서 키노출의 위험이 너무 큰 방식이다.

 

솔루션

다른 방식을 찾고자 Near 코리아 디스코드에도 물어보고, near-api-js Github에도 Issue를 남겼는데... 정답을 얻었다!

 

near-api-js Issue

 

[Error] createAccount don't work on testnet. · Issue #1290 · near/near-api-js

Prerequisites I'm using the latest version of near-api-js. I have tried to start with a fresh project and reproduce the defect with minimal code changes. I have read the console error messages care...

github.com

 

레포지토리의 Collaborator가 친절히 방법을 알려주었다. Testnet과 연결된 Near 객체에서 createAccount를 호출하면 끝이다! NearBlock(Testnet)에서 확인해본 결과 실제로, 잘 생성된 것을 볼 수 있었다.

 

NearBlock

 

 

2주일 동안 고민한 [계정 생성] 프로세스가 너무 간단하게 끝나서 조금 허탈하기도 하다. 그래도 아직 구현해야 할 게 많으니 힘내야겠다.

'프로젝트 > 졸업과제' 카테고리의 다른 글

[졸과] WASM 실행 테스트  (0) 2024.03.14
[졸과] VC 생성 테스트  (0) 2024.03.12
[졸과] 20240228 모각코  (1) 2024.02.29
[졸과][NEAR] 계정 생성 어떻게 할까?  (0) 2024.02.16
[졸과][NEAR] 계정 생성을 어떻게 처리할지 고민 중  (0) 2024.02.15
'프로젝트/졸업과제' 카테고리의 다른 글
  • [졸과] WASM 실행 테스트
  • [졸과] VC 생성 테스트
  • [졸과] 20240228 모각코
  • [졸과][NEAR] 계정 생성 어떻게 할까?
KimCookieYa
KimCookieYa
무엇이 나를 살아있게 만드는가
  • KimCookieYa
    쿠키의 주저리
    KimCookieYa
  • 전체
    오늘
    어제
    • 분류 전체보기 (574)
      • 혼잣말 (88)
      • TIL (2)
      • 커리어 (24)
        • Sendy (21)
        • 외부활동 기록 (2)
      • 프로젝트 (186)
        • 티스토리 API (5)
        • 코드프레소 체험단 (89)
        • Web3 (3)
        • Pint OS (16)
        • 나만무 (14)
        • 대회 (6)
        • 정글 FE 스터디 (16)
        • MailBadara (12)
        • github.io (1)
        • 인공지능 동아리, AID (5)
        • 졸업과제 (18)
        • OSSCA 2024 (1)
      • 크래프톤 정글 2기 (80)
      • IT (168)
        • 코딩 (4)
        • CS (18)
        • 에러 (5)
        • 블록체인 (23)
        • Front-End (39)
        • 알고리즘&자료구조 정리 (3)
        • 코딩테스트 (3)
        • BOJ 문제정리 (41)
        • WILT (12)
        • ML-Agents (4)
        • 강화학습 (1)
        • Android (0)
        • LLM (2)
      • 전공 (1)
        • 머신러닝 (1)
      • 자기계발 (20)
        • 빡공단X베어유 (2)
        • 독서 (15)
  • 블로그 메뉴

    • 홈
    • 방명록
    • Github
    • Velog
    • 관리
  • 링크

  • 공지사항

  • 인기 글

  • 태그

    MailBadara
    해커톤
    사이드프로젝트
    pintos
    딥러닝
    나만무
    센디
    자바스크립트
    핀토스
    파이썬
    프로그래머스
    블록체인
    numpy
    NEAR Protocol
    글리치해커톤
    리액트
    Pint OS
    부산대
    docker
    머신러닝
    RNN
    크래프톤정글
    JavaScript
    react
    코드프레소
    Flutter
    니어프로토콜
    졸업과제
    알고리즘
    OS
  • hELLO· Designed By정상우.v4.10.3
KimCookieYa
[졸과][NEAR] 테스트넷 계정 생성
상단으로

티스토리툴바