This library contains three different clients for interaction with the Partisia Blockchain. These are
npm install @partisiablockchain/blockchain-api-transaction-clientThis 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.
You can create a ChainControllerApi targeting a specific reader url as follows
``ts`
const chainController = new ChainControllerApi(
new Configuration({basePath: "https://node1.testnet.partisiablockchain.com"})
);
`ts`
const chain = await chainController.getChain();
`ts`
const state = await chainController.getContract({
address: "02e1e09358e543e8b1cf97d5e19d5b287983cee8f6",
});
`ts`
const avlValue = await chainController.getContractAvlValue({
address: "02e1e09358e543e8b1cf97d5e19d5b287983cee8f6",
treeId: 0,
key: "00e72e44eab933faaf1fd4ce94bb57e08bff98a1ed"
});
`ts`
const account = await chainController.getAccount({
address: "02e1e09358e543e8b1cf97d5e19d5b287983cee8f6",
});
A ShardControllerApi is created the same way as a ChainControllerApi
`ts`
const shardController = new ShardControllerApi(
new Configuration({basePath: "https://node1.testnet.partisiablockchain.com"})
);
`ts`
const block = await shardController.getLatestBlock({shardId: "Shard0"});
`ts`
const transaction = await shardController.getTransaction({
shardId: "Shard0",
transactionId: "9356779565b80548a1cd07800d2e2508e530f39cbd7eb71e057acf7bcb18ce0b",
});
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.
`ts`
const senderAuthentication = SenderAuthenticationKeyPair.fromString(privateKey);
const transactionSender = BlockchainTransactionClient.create(
"https://node1.testnet.partisiablockchain.com",
senderAuthentication
);
`ts`
const transaction: Transaction = {address: contractAddress, rpc: actionRpc};
const sentTransaction = await transactionSender.signAndSend(transaction, gasCost);
`ts``
const transactionTree = await transactionSender.waitForSpawnedEvents(sentTransaction);