2.2.0 • Published 3 months ago

@bnb-chain/greenfield-js-sdk v2.2.0

Weekly downloads
-
License
GPLv3
Repository
github
Last release
3 months ago

Greenfield Chain JS SDK

Install

npm install @bnb-chain/greenfield-js-sdk

Create Client

import {Client} from '@bnb-chain/greenfield-js-sdk'

const client = Client.create(GRPC_URL, GREEN_CHAIN_ID);

Usage

The SDK consists of two parts:

Chain

Tx

1. Tx construction

transfer tx 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: '',
});

NOTICE: Signature mode for Broadcast

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 broadcast a tx by privateKey:

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

Query

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

Examples:

Storage Provider Client

https://docs.bnbchain.org/greenfield-docs/docs/api/storgae-provider-rest

SDK support two authentication type:

  • ECDSA: It is usually used on Node.js(Because it need to use a private key)
  • EDDSA: It is usually used in a browser

getBucketReadQuota as example:

// browser:

// generate seed:
const allSps = await getAllSps();
const offchainAuthRes = await client.offchainauth.genOffChainAuthKeyPairAndUpload(
  {
    sps: allSps,
    chainId: GREEN_CHAIN_ID,
    expirationMs: 5 * 24 * 60 * 60 * 1000,
    domain: window.location.origin,
    address: 'your address',
  },
  provider: 'wallet provider',
);

// request sp api
const bucketQuota = await client.bucket.getBucketReadQuota(
  {
    bucketName,
  },
  {
    type: 'EDDSA',
    seed: offchainAuthRes.seedString,
    domain: window.location.origin,
    address: 'your address',
  },
);
// Node.js:
// request sp api
const bucketQuota = await client.bucket.getBucketReadQuota(
  {
    bucketName,
  },
  {
    type: 'ECDSA',
    privateKey: '0x....'
  },
);

Support Custom Http Request

It's actually an HTTP request, we use fetch by default, and if you want to use another http library like axios, we'll construct it for you as well.

// custom upload object
const { PUT_OBJECT: getPutObjectMetaInfo } = client.spClient.getMetaInfo(endpoint, payload);
const {reqMeta, url} = await getPutObjectMetaInfo(endpoint, params);

axios.put(...)
2.2.0

3 months ago

2.2.0-alpha.0

3 months ago

2.0.1

7 months ago

2.1.1

6 months ago

2.1.0

6 months ago

2.1.0-alpha.2

7 months ago

2.1.0-alpha.1

7 months ago

2.1.0-alpha.0

8 months ago

2.0.0-alpha.9

8 months ago

2.0.0-alpha.10

8 months ago

2.0.0

8 months ago

1.2.4

8 months ago

2.0.0-alpha.8

8 months ago

2.0.0-alpha.7

8 months ago

2.0.0-alpha.6

9 months ago

2.0.0-alpha.5

9 months ago

2.0.0-alpha.4

9 months ago

1.2.3

9 months ago

1.3.0-alpha.3

9 months ago

1.3.0-alpha.2

9 months ago

1.3.0-alpha.0

10 months ago

1.3.0-alpha.1

10 months ago

1.2.2

10 months ago

1.2.0

12 months ago

1.2.1

10 months ago

1.1.3

12 months ago

1.2.0-alpha.2

12 months ago

1.2.0-alpha.1

12 months ago

1.1.1

1 year ago

1.1.2

1 year ago

1.1.0

1 year ago

1.1.0-alpha.2

1 year ago

1.1.0-alpha.3

1 year ago

1.1.0-alpha.1

1 year ago

1.1.0-alpha.0

1 year ago

1.0.6

1 year ago

1.0.5

1 year ago

1.0.4

1 year ago

1.0.3

1 year ago

1.0.2

1 year ago

1.0.1

1 year ago

1.0.1-alpha.0

1 year ago

1.0.0

1 year ago

1.0.0-alpha.3

1 year ago

0.2.7-alpha.2

1 year ago

0.2.7-alpha.1

1 year ago

0.2.7-alpha.0

1 year ago

0.2.6

1 year ago

0.2.6-alpha.0

1 year ago

0.2.5

1 year ago

0.2.5-alpha.9

1 year ago

0.2.5-alpha.8

1 year ago

0.2.5-alpha.7

1 year ago

0.2.5-alpha.6

1 year ago

0.2.5-alpha.5

1 year ago

0.2.5-alpha.4

1 year ago

0.2.5-alpha.3

1 year ago

0.2.5-alpha.2

1 year ago

0.2.5-alpha.1

1 year ago

0.2.4

1 year ago

0.2.4-alpha.28

1 year ago

0.2.4-alpha.27

1 year ago

0.2.4-alpha.26

1 year ago

0.2.4-alpha.25

1 year ago

0.2.4-alpha.24

1 year ago

0.2.4-alpha.23

1 year ago

0.2.4-alpha.22

1 year ago

0.2.4-alpha.21

1 year ago

0.2.4-alpha.20

1 year ago

0.2.4-alpha.19

1 year ago

0.2.4-alpha.18

1 year ago

0.2.4-alpha.17

1 year ago

0.2.4-alpha.16

1 year ago

0.2.4-alpha.15

1 year ago

0.2.4-alpha.14

1 year ago

0.2.4-alpha.13

1 year ago

0.2.4-alpha.12

1 year ago

0.2.4-alpha.11

1 year ago

0.2.4-alpha.10

1 year ago

0.2.4-alpha.9

1 year ago

0.2.4-alpha.8

1 year ago

0.2.4-alpha.7

1 year ago

0.2.4-alpha.6

1 year ago

0.2.4-alpha.5

1 year ago

0.2.4-beta.0

1 year ago

0.2.4-alpha.4

1 year ago

0.2.4-alpha.3

1 year ago

0.2.4-alpha.2

1 year ago

0.2.4-alpha.1

1 year ago

0.2.4-alpha.0

1 year ago

0.2.3

1 year ago