New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

idl-parser-core

Package Overview
Dependencies
Maintainers
1
Versions
40
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

idl-parser-core

> Support converting IDL files to `transaction instruction`. Useful for smart contract test run, time-saving for writing test case.

latest
Source
npmnpm
Version
0.4.40
Version published
Weekly downloads
9
80%
Maintainers
1
Weekly downloads
 
Created
Source

IDL Parser

Support converting IDL files to transaction instruction. Useful for smart contract test run, time-saving for writing test case.

Install

yarn add idl-parser-core

Usage

import { ParserProvider } from 'idl-parser-core'

const RPC: 'https://api.devnet.solana.com'

const App = () => {
  return (
    <ParserProvider
      rpc={RPC}
      walletAddress={walletAddress}
      programAddresses={{ provider }}
    >
      <View />
    </ParserProvider>
  )
}

rpc: rpc api url address
walletAddress: user wallet address
programAddresses: địa chỉ chương trình smartcontract
appId: id html element hiển thị modal.

Component

Giao diện mặc định của thư viện idl-parser-core

IDLParserWrapper

import { IDLParserWrapper } from 'idl-parser-core'

<IDLParserWrapper />
  • Giao diện mặc định của thư viện idl-parser-core: upload file idl, form accounts và arguments

TemplateView, InstructionView

import { TemplateView, InstructionView } from 'idl-parser-core'

<TemplateView />

<InstructionView />
  • TemplateView: Giao diện cấu trúc file IDL được tải lên.
  • InstructionView: Giao diện mặc định form accounts và arguments của file IDL được tải lên.

UploadIdl, ViewUploadedIdl

import { UploadIdl, ViewUploadedIdl } from 'idl-parser-core'

<UploadIdl />

<ViewUploadedIdl />
  • UploadIdl: Giao diện mặc định để tải lên file IDL.
  • ViewUploadedIdl: Giao diện mặc định hiển thị file IDL được tải lên._

Hooks

Cung cấp các function để thao tác với dữ liệu, thêm, sửa, xoá với file IDL được tải lên. Lấy thông tin được điền vào từ form accounts, arguments, hoặc dữ liệu file IDL sau khi chuyển đổi.

  • useParser

    • uploadIdl: function tải lên file IDL

    • removeIdl: function xoá file IDL được tải lên

    • parser: dữ liệu của file IDL được tải lên

      const {
        parser: { idl, ixSelected, accountsMetas, argsMetas, remainingAccounts },
      } = useParser()
      
      • idl: file IDL được tải lên
      • accountsMetas: dữ liệu accounts.
      • argsMetas: dữ liệu argsMetas.
      • ixSelected: instruction đang được chọn.
      • remainingAccounts: dữ liệu remainingAccounts.
    • rpc: địa chỉ rpc blockchain.

    • walletAddress: địa chỉ ví của người dùng.

    • programAddresses: địa chỉ chương trình smartcontract.
      programAddress.idl địa chỉ program được lấy từ file IDL tải lên.
      programAddress.custom địa chỉ program được người dùng thêm, sửa , xoá.
      programAddress.provider địa chỉ program bắt buộc thêm vào khi khởi tạo providerParser để thư viện xác định địa chỉ chương trình mà fileIDL đang tương tác.

      const {
        programAddress: {
          custom: customProgramAddress,
          idl: idlProgramAddress,
          provider: providerProgramAddress,
        },
      } = useParser()
      
    • setProgramAddress(programAddress: string): function cài địa chỉ cho chương trình IDL. Địa chỉ chương trình sẽ được thêm vào programAddress.custom

      const {
        programAddress: { custom: customProgramAddress },
      } = useParser()
      
    • setAccountsMeta({ name: string, data: KeypairMeta }): function thêm dữ liệu cho trường accounts. Dữ liệu sẽ được thêm vào parser.accountsMetas.

      const {
        parser: { accountsMetas },
      } = useParser()
      
    • setArgsMeta({ name: string, val: string }): function thêm dữ liệu cho trường arguments. Dữ liệu sẽ được thêm vào parser.argsMetas.

      const {
        parser: { argsMetas },
      } = useParser()
      
    • setInstruction(val: string): function chọn instruction để thao tác. Instruction được chọn sẽ thêm vào parser.ixSelected.

      const {
        parser: { ixSelected },
      } = useParser()
      
    • txInstructions: transaction instruction được chuyển đổi sau khi điền đầy đủ thông tin accounts, argument và remainning accounts nếu có.

      const { txInstructions } = useParser()
      
    • setTxInstructions: function thêm dữ liệu cho txInstructions.

      const { setTxInstructions } = useParser()
      
      function () {
        ...
        setTxInstructions(instruction)
        ...
      }
      

Guideline


Upload file idl

  • Button Choose IDL file: select to upload file idl.


IDL instructions

  • Program Address: địa chỉ chương trình idl đang tương tác.
  • File details:
    • File name.
    • Icon : click to remove idl file.
  • Group button instructions: Select instruction wana parse to transaction.
  • Accounts: Bao gồm những địa chỉ account cần để tạo và thực hiện transaction.
  • Arguments: Là những giá trị được truyền vào tương ứng với giá trị được yêu cầu của transaction.

  • Remaining accounts: Là tham số được dùng trong một số transaction đặc biệt như tạo account, deposit .v.v .Có dạng như sau:

      {
        isSigner: boolean,
        isWriter: boolean,
        publicKey: PublicKey
      }
    

    Bấm nút Add để tạo thêm và bấm nút để xoá remaining account.

Auto complete

Coming soon

Selection

Hỗ trợ người dùng điền nhanh chóng những trường của accounts, arguments và remaining.

  • Wallet Address: địa chỉ ví được cung cấp từ parserProvider
  • New Keypaire: tạo 1 keypair mới.
  • Program Account Data: lấy dữ liệu của account từ địa chỉ account. Ví dụ nhập địa chỉ pool để lấy thông tin của pool.
  • PDA - Token Account: derive địa chỉ token acount từ địa chỉ mint và địa chỉ owner.
  • PDA - Orther: tạo một địa chỉ bằng cách hash 2 chuổi ký tự với nhau.
  • Recents: Tất cả những địa chỉ đã nhập trước đó.
  • System: những địa chỉ chương trình mặc định được cung cấp bởi Solana

Review

Xem lại Transaction được tạo ra khi điền đầy đủ accounts và arguments của instruction.

Project example: https://github.com/DescartesNetwork/idl-parser

Keywords

idl

FAQs

Package last updated on 26 Jul 2022

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts