typescript@solana.web3사용

김병훈·2022년 6월 14일
0

blockchain

목록 보기
2/13

reference

https://yihau.github.io/solana-web3-demo/zh/

solscan 주소

https://solscan.io/token/JS3FiJxtv5CYURf7oC9eMPzq21uz1PpsvW9MFfzZDsi?cluster=devnet#holders
npm install --save @solana/web3.js
npm install @solana/spl-token

https://solana-labs.github.io/solana-web3.js/#npm

https://snyk.io/advisor/npm-package/@solana/spl-token

https://solanacookbook.com/references/token.html#how-to-create-a-new-token

https://github.com/mharj/minecraft-ping/issues/5

https://www.quicknode.com/docs/solana/getTokenAccountBalance

6번 결과

{
  address: PublicKey {
    _bn: <BN: 4772f6e75b5b18a56eb8d6ab630c0d7d66c1202a2d487636ad243af3217a3fd> 
  },                                                                                                                                                                                                  16:19:17   
  mintAuthority: PublicKey {
    _bn: <BN: 3231cdeade17bd5f7f24f9e54ac221d75bad2bc585a75093a558ab6b29ad0834>
  },
  supply: 0n,
  decimals: 9,
  isInitialized: true,
  freezeAuthority: null
}

7번 결과

   /mnt/c/Users/PC/Desktop/typechain/src  ts-node 7_makeTokenAccount.ts                                                                                              1 ✘  5s   16:59:34   
bigint: Failed to load bindings, pure JS will be used (try npm run rebuild?)
ata: LarSVMB2UGLkgmHkkjM8jyKeKCRPdJCvvotJtyKMDSp
create ata txhash: hSJYKH9iyayddqt3MGF6cU68G93VXAXjwqjzTAh9kwAY4kmsS2JCpxGPGpDaEF49XtMZdaTYGukTqYZs2j4Xytz

8번 결과 토큰 account 조회

  • 주소는 다르지만 LarSVMB2UGLkgmHkkjM8jyKeKCRPdJCvvotJtyKMDSp
  • spl-token accounts 를 했을 땐 처음 발행한 토큰의 주소가 나온다
{
  address: PublicKey {
    _bn: <BN: 5044ff9fc56443afe10b383a54e986ab6294e2f8ff7cd4e9920968d6fe89109>
  },
  mint: PublicKey {
    _bn: <BN: 4772f6e75b5b18a56eb8d6ab630c0d7d66c1202a2d487636ad243af3217a3fd>
  },
  owner: PublicKey {
    _bn: <BN: 3231cdeade17bd5f7f24f9e54ac221d75bad2bc585a75093a558ab6b29ad0834>
  },
  amount: 0n,
  delegate: null,
  delegatedAmount: 0n,
  isInitialized: true,
  isFrozen: false,
  isNative: false,
  rentExemptReserve: null,
  closeAuthority: null
}

9번 결과 - 토큰 추가 발행

   /mnt/c/Users/PC/Desktop/typechain/src  ts-node 9_extraTokenMint.ts                                                                                                 ✔  19s   17:52:21   
bigint: Failed to load bindings, pure JS will be used (try npm run rebuild?)
txhash: PwSqLvceZQm8kVNVbHE9Jdw8RCDw6NuMwNn3zmDewznSxcXSfAqu36y2gmGohmFEgaStetER538NxvcdGcHNxG1

10번 결과 - 토큰 잔액 조회

  • python 처럼 txLamport2Sol = round(transfer_parameters.lamports*10**(-9),9) 을 해서 sol 단위로 변경해볼라 했지만, 실패했다
   /mnt/c/Users/PC/Desktop/typechain/src  ts-node 10_tokenGetBalance.ts                                                                                              1 ✘  5s   18:03:19   
\bigint: Failed to load bindings, pure JS will be used (try npm run rebuild?)
decimals: 9, amount: 1000100000100

11번 결과 - 유저 간 토큰 전송

   /mnt/c/Users/PC/Desktop/typechain/src  ts-node 11_transferSplToken.ts                                                                                              ✔  18s   18:15:56   
bigint: Failed to load bindings, pure JS will be used (try npm run rebuild?)
txhash: 3MNAww45Ato5rbPRv2czKJyCzRcW4r3KrH7BsoYzsb4bTN1uzmRn3RW8M43riPXEAJostBByjrPb4phZHz8ZRPGk
profile
블록체인 개발자의 꿈을 위하여

0개의 댓글