0.2.2 • Published 9 months ago

@bnb-chain/greenfield-chain-sdk v0.2.2

Weekly downloads
-
License
GPLv3
Repository
-
Last release
9 months ago

Greenfield Chain JS SDK

Install

# QA
npm install @bnb-chain/greenfield-chain-sdk@alpha

# TESTNET
npm install @bnb-chain/greenfield-chain-sdk@beta

Usage

create client

import {Client} from '@bnb-chain/greenfield-chain-sdk'
const client = Client.create(GRPC_URL, GREEN_CHAIN_ID);

Apis include transactions and queries.

Tx

1. Tx construction

take transfer for example:

const transferTx = await client.account.transfer({
  fromAddress: address,
  toAddress: transferInfo.to,
  amount: [
    {
      denom: 'BNB',
      amount: ethers.utils.parseEther(transferInfo.amount).toString(),
    },
  ],
});

2. Simulate Tx

// simulate tx
const simulateInfo = await transferTx.simulate({
  denom: 'BNB',
});

3. Boradcast Tx

// broadcast tx
const broadcastRes = await transferTx.broadcast({
  denom: 'BNB',
  gasLimit: Number(simulateInfo.gasLimit),
  gasPrice: simulateInfo.gasPrice,
  payer: address,
  granter: '',
});

broadcast use window.ethereum as signature provider by default.

If you want to use others, you can set signTypedDataCallback:

// trustwallet
const broadcastRes = await transferTx.broadcast({
  //...
  signTypedDataCallback: async (addr: string, message: string) => {
    return await window.trustwallet.request({
      method: 'eth_signTypedData_v4',
      params: [addr, message],
    });
  }
});

If you broadcast in Nodejs, you can set privateKey:

const broadcastRes = await transferTx.broadcast({
  //...
  privateKey: '0x.......'
});

Query

// get account info
await client.account.getAccount(address);

more API:

0.2.2-alpha.18

9 months ago

0.2.2-alpha.14

9 months ago

0.2.2-alpha.15

9 months ago

0.2.2-alpha.16

9 months ago

0.2.2-alpha.17

9 months ago

0.2.2-alpha.10

9 months ago

0.2.2-alpha.11

9 months ago

0.2.2-alpha.12

9 months ago

0.2.2-alpha.13

9 months ago

0.2.2-alpha.5

10 months ago

0.2.2-alpha.6

10 months ago

0.2.2-alpha.7

10 months ago

0.2.2-alpha.8

10 months ago

0.2.2-alpha.9

10 months ago

0.2.2-alpha.1

10 months ago

0.2.2-alpha.2

10 months ago

0.2.2-alpha.3

10 months ago

0.2.2-alpha.4

10 months ago

0.2.2

9 months ago

0.2.2-alpha.0

10 months ago

0.2.1-alpha.11

11 months ago

0.2.1-alpha.12

11 months ago

0.2.1-alpha.10

11 months ago

0.2.1-alpha.7

11 months ago

0.2.1-alpha.8

11 months ago

0.2.1-alpha.9

11 months ago

0.2.1-alpha.15

11 months ago

0.2.1-alpha.13

11 months ago

0.2.1-alpha.14

11 months ago

0.0.0

11 months ago

0.2.1

10 months ago

0.2.1-alpha.6

11 months ago

0.1.0-alpha.5

12 months ago

0.1.0-alpha.4

12 months ago

0.2.0

12 months ago

0.1.0-alpha.6

12 months ago

0.1.0-alpha.1

12 months ago

0.1.0-alpha.3

12 months ago

0.1.0-alpha.2

12 months ago

0.2.1-alpha.2

11 months ago

0.2.1-alpha.3

11 months ago

0.2.1-alpha.4

11 months ago

0.2.1-alpha.5

11 months ago

0.2.1-alpha.0

11 months ago

0.2.1-alpha.1

11 months ago

0.1.0

1 year ago

0.1.0-alpha.0

1 year ago

0.0.1

1 year ago

1.0.0

1 year ago

1.0.0-alpha.2

1 year ago

1.0.0-alpha.1

1 year ago