5.144.0 • Published 5 months ago

@partisiablockchain/blockchain-api-transaction-client v5.144.0

Weekly downloads
-
License
AGPL-3.0
Repository
-
Last release
5 months ago

Blockchain Clients

This library contains three different clients for interaction with the Partisia Blockchain. These are

  • ChainControllerApi - Used to get information of contracts and accounts from the blockchain
  • ShardControllerApi - Used to get information of blocks and transaction from the blockchain
  • BlockchainTransactionClient - Client used to help build, sign, and send transactions to the blockchain

The ChainControllerApi and ShardControllerApi clients are generated from the OpenAPI spec found here. The BlockchainTransactionClient is instead built on top of the other clients and uses them to build, sign and send transactions.

ChainControllerApi

You can create a ChainControllerApi targeting a specific reader url as follows

const chainController = new ChainControllerApi(
  new Configuration({basePath: "https://node1.testnet.partisiablockchain.com"})
);

Get generic chain information

const chain = await chainController.getChain();

Get the latest state of a contract

const state = await chainController.getContract({
  address: "02e1e09358e543e8b1cf97d5e19d5b287983cee8f6",
});

Get an AvlTreeMap value from a contract

const avlValue = await chainController.getContractAvlValue({
  address: "02e1e09358e543e8b1cf97d5e19d5b287983cee8f6",
  treeId: 0,
  key: "00e72e44eab933faaf1fd4ce94bb57e08bff98a1ed"
});

Get account data

const account = await chainController.getAccount({
  address: "02e1e09358e543e8b1cf97d5e19d5b287983cee8f6",
});

ShardControllerApi

A ShardControllerApi is created the same way as a ChainControllerApi

const shardController = new ShardControllerApi(
  new Configuration({basePath: "https://node1.testnet.partisiablockchain.com"})
);

Get latest block for a specific shard

const block = await shardController.getLatestBlock({shardId: "Shard0"});

Get transaction information

const transaction = await shardController.getTransaction({
  shardId: "Shard0",
  transactionId: "9356779565b80548a1cd07800d2e2508e530f39cbd7eb71e057acf7bcb18ce0b",
});

BlockchainTransactionClient

When creating a transaction client you have to provide a way to generate signature. This is done through the interface SenderAuthentication. The most basic implementation of this is the SenderAuthenticationKeyPair which uses a private key to sign with. Other ways to sign includes wallets such as Metamask Snap, or Parti Wallet.

const senderAuthentication = SenderAuthenticationKeyPair.fromString(privateKey);
const transactionSender = BlockchainTransactionClient.create(
  "https://node1.testnet.partisiablockchain.com",
  senderAuthentication
);

Sign and send a transaction

const transaction: Transaction = {address: contractAddress, rpc: actionRpc};
const sentTransaction = await transactionSender.signAndSend(transaction, gasCost);

Wait for spawned events of a transaction

const transactionTree = await transactionSender.waitForSpawnedEvents(sentTransaction);
5.106.0

7 months ago

5.114.0

7 months ago

5.79.0

9 months ago

5.113.0

7 months ago

5.59.0

11 months ago

5.57.0

11 months ago

5.96.0

8 months ago

5.75.0

10 months ago

5.55.0

12 months ago

5.52.0

12 months ago

5.134.0

5 months ago

5.71.0

10 months ago

5.130.0

6 months ago

5.72.0

10 months ago

5.117.0

7 months ago

5.124.0

6 months ago

5.68.0

11 months ago

5.144.0

5 months ago

5.125.0

6 months ago

5.102.0

8 months ago

5.105.0

8 months ago

5.121.0

6 months ago

5.87.0

8 months ago

5.81.0

9 months ago

5.61.0

11 months ago

5.140.0

5 months ago

5.50.0

12 months ago

5.40.0

1 year ago

5.38.0

1 year ago

5.26.0

1 year ago

5.35.0

1 year ago

5.31.0

1 year ago

5.21.0

1 year ago

5.18.0

1 year ago

5.16.0

1 year ago

5.7.0

1 year ago

5.1.0

1 year ago

4.146.0

1 year ago

4.140.0

1 year ago

4.136.0

1 year ago

4.125.0

1 year ago

4.120.0

1 year ago

4.111.0

1 year ago

0.0.0

1 year ago