@bnb-chain/greenfield-chain-sdk v0.2.2
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:
9 months ago
9 months ago
9 months ago
9 months ago
9 months ago
9 months ago
10 months ago
9 months ago
9 months ago
9 months ago
9 months ago
10 months ago
10 months ago
9 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
9 months ago
10 months ago
11 months ago
11 months ago
11 months ago
11 months ago
11 months ago
11 months ago
11 months ago
11 months ago
11 months ago
11 months ago
11 months ago
11 months ago
11 months ago
11 months ago
11 months ago
10 months ago
11 months ago
12 months ago
12 months ago
12 months ago
12 months ago
12 months ago
12 months ago
12 months ago
11 months ago
11 months ago
11 months ago
11 months ago
11 months ago
11 months ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago