In general, there are two objects that are used to interact with a blockchain via
JsonRpc object, and the
The requests made by the
JsonRpc object will either use a built-in
fetch library, or the
fetch library passed in by the user to issue requests to the endpoint specified when instantiating the
JsonRpc object. When the various methods (get_abi, get_account, get_block_header_state, etc) of the
JsonRpc object are invoked, the calls are delegated to the
JsonRpc object's fetch function, which in turn, delegate the requests to the
The typical use of the
Api object is to call its
transact method. This method performs a number of steps depending on the input passed to it:
transactmethod first checks if the chainId was set in the
Apiconstructor, and if not, uses the
get_infomethod to retrieve the chainId.
transactmethod then checks if the
useLastIrreversiblefields are set and well-formed in the optional configuration object, as specified in How to Submit a Transaction.
- If so, either the last_irreversible_block_num or the block blocksBehind the head block retrieved from
get_infois set as the reference block and the transaction header is serialized using this reference block and the
transactmethod then checks if the appropriate TAPOS fields are present in the transaction (they can either be specified directly in the transaction or in the optional configuration object) and throws an Error if not.
- The necessary
abis for a transaction are then retrieved for the case when
transactis expected to sign the transaction.
actionsare serialized using the
- The entire transaction is then serialized, also using the
- The transaction is then optionally signed, using the
signatureProvider, the previously retrieved
abis, the private keys of the
signatureProvider, and the
- The transaction is then optionally compressed, using the
- The transaction is then optionally broadcasted using