Version: next
This documentation is for an unreleased version of Taquito. Features and APIs may change before the final release. View the latest stable version.
RPC
Written by Claude Barde
You can use the RPC client package to query the RPC API of your chosen node. The higher-level @taquito/taquito package builds on this RPC package.
In general, you won’t need to use this package directly, but it is available for use should you want specific data and need to bypass the higher-level abstractions in Taquito.
Methods in the RPC package map one-to-one to the corresponding Tezos RPC API endpoints. All responses from the RPC are returned with TypeScript types. No other parsing or compositions are done at this level.
Examples
The RpcClient constructor takes the URL of the node you want to use and the chain ID.
// Initializing the RPC client
import { RpcClient } from '@taquito/rpc';
const client = new RpcClient(' https://tezos-shadownet.octez.io/', 'NetXLH1uAxK7CCh');
The balance is returned as a BigNumber and must be converted to a number to output it. Please note that the returned value is in mutez (micro ꜩ), so if you need the balance in ꜩ, you can divide it by 1000000.
/* Fetching the spendable balance of an account
* using the client set up above */
const balance = await client.getBalance('tz1VSUr8wwNhLAzempoch5d6hLRiTh8Cjcjb');
console.log('Balance:', balance.toNumber());
You can use the RPC client to get the head block information.
// gets head block
const block = await client.getBlock();
console.log('Head block:', block);
If it’s the head block hash you are looking for, you can easily get it with the getBlockHash method.
// gets head block hash
const blockHash = await client.getBlockHash();
console.log('Head block hash:', blockHash);
This method returns some blockchain constants pertaining for example to the gas limits or the block information.
// gets constants
const constants = await client.getConstants();
console.log('Constants:', constants);
This method returns the balance of the contract, the code, and the storage.
// gets contract
const contractExample = 'KT1J4E79F1qL6kGBSQ3yXBdXmuq5j4FNThK2';
const contract = await client.getContract(contractExample);
console.log('Contract:', contract);
You can also get a list of the contract entry points as an object whose keys are the entry point names and whose values are the expected parameters in JSON format.
// gets contract entrypoints
const entrypoints = await client.getEntrypoints(contractExample);
console.log('Entrypoints:', entrypoints);
The getScript method returns the contract’s script as a 3 key/value pair object: a key for the parameter, a key for the storage, and a key for the code.
// gets contract script
const script = await client.getScript(contractExample);
console.log('Contract script:', script);
You also have access to the storage of the contract using the getStorage method.
// gets contract storage
const storage = await client.getStorage(contractExample);
console.log('Contract storage:', storage);
You can simulate the PACK instruction from Michelson with the packData method.
// packs data
const packedData = await client.packData({ data: { string: 'test' }, type: { prim: 'string' } });
console.log('Packed data:', packedData);
This function will execute TZIP-4 views normally referred to as ‘Lambda Views’. You can learn more about TZIP-4 here
// runs view
const view = await client.runView({
contract: 'contractAddress',
entrypoint: 'contractEntrypoint',
chain_id: 'chainId',
input: {
string: 'testInput'
}
});
Full documentation
Typedoc information is available here.
BLS operations
The BLS methods call the node’s root /bls endpoints. They do not require a chain
or block path, a signer, or an operation. Use an Octez node that exposes these
endpoints.
| Method | POST endpoint | Result |
|---|---|---|
aggregatePublicKeys | /bls/aggregate_public_keys | An object with public_key and public_key_hash, or null |
aggregateProofs | /bls/aggregate_proofs | A proof signature string, or null |
checkProof | /bls/check_proof | A boolean |
aggregateSignatures | /bls/aggregate_signatures | A signature string, or null |
thresholdSignatures | /bls/threshold_signatures | A signature string, or null |
checkProof takes a public key and its proof of possession. aggregatePublicKeys
takes an array of those objects. aggregateProofs takes an object with public_key
(the aggregate BLpk... key) and proofs (an array of each participant’s proof of
possession over that aggregate key, produced via signer.provePossession(aggregatePk)).
Keys, proofs, and signatures use Base58Check encoding. The following example uses
fixed public test values:
import { RpcClient } from '@taquito/rpc';
const client = new RpcClient('https://rpc.shadownet.teztnets.com');
const key = {
public_key: 'BLpk1wMU34nS7N96D2owyejLxQtwZwLARLg6tdTFMP5N8fz6yCiLogfFXkYo9ZHnZ95Kba3D3cvt',
proof: 'BLsig9cW2ffM82s8cZWNDQTmecxHPHmJcTUh5DF2dVP7GV7oUmmptd4JpxBvSyE1VDeLtGyV68KaTuaEM1qiSUELMqkdwCLJFDQYGL6ZZLZDEUAfyu3Vu3ivs66jhV8ANwt3tKg6qABoqx',
};
const valid = await client.checkProof(key);
console.log(valid); // true
const aggregate = await client.aggregatePublicKeys([key]);
if (aggregate !== null) {
console.log(aggregate.public_key_hash); // 'tz4AQcKaQU1sUzsmPTX43qnK4ddkCeeknJnf'
}
aggregateSignatures takes an object with public_key, message, and
signature_shares. The message is hexadecimal without a 0x prefix. Its
signature_shares value is an array of signature strings.
thresholdSignatures takes the same fields, but each signature share is an
object with id and signature. The node validates share IDs as signed 8-bit
integers, from -128 through 127.
A failed proof check can return false, and failed aggregation can return
null. HTTP and transport failures still reject the promise. Malformed input can
also cause an HTTP error. Handle these rejections separately from false and
null results.
RpcClientCache forwards these five methods without caching their results.
If you implement RpcClientInterface yourself, the original four methods are
required and aggregateProofs is optional (RpcClientCache throws
UnsupportedActionError when the underlying client omits aggregateProofs).
Existing RPC methods and cache policies are unchanged.