
Security News
PEP 810 Proposes Explicit Lazy Imports for Python 3.15
An opt-in lazy import keyword aims to speed up Python startups, especially CLIs, without the ecosystem-wide risks that sank PEP 690.
@substrate/calc
Advanced tools
This package is generated from the calc
Rust crate using wasm-bindgen
and was initially developed
solely to use as a dependency for substrate-api-sidecar
. We are now offering this package as a
standalone through the npm registry.
Example usage for the package can be found in Sidecar's staking payout service and Sidecar's block service.
Tool to calculate an extrinsics' partial_fee
(i.e. the total fee minus any tip).
It uses the following formula:
partial_fee = base_fee + len_fee + ((adjusted_weight_fee/estimated_weight)*actual_weight)
Where:
base_fee
is a fixed base fee to include some transaction in a block. It accounts
for the work needed to verify the signature and the computing work common to any tx.
It is constant for any tx.len_fee
is a fee paid based on the size (length in bytes) of the transaction.
Longer transactions require more storage, and therefore are more expensive.adjusted_weight_fee
is a fee that is itself estimated_weight * targeted_fee_adjustment
:
targeted_fee_adjustment
is some adjustment made based on the network load and
other circumstantial factors, and is an opaque internal value we have no access to.estimated_weight
is the "pre-dispatch" weight of the transaction. It's set
based on the cost of processing the transaction on reference hardware.actual_weight
is the weight that is found in the ExtrinsicSuccess
event for
the extrinsic in a block (it's just called weight
in the event), and it's
value is often close to estimated_weight
, but the node has the opportunity
to change it depending on the actual computing work necessary to process the tx.The RPC endpoint payment_queryFeeDetails
returns base_fee
, len_fee
and
adjusted_weight_fee
. The RPC endpoint payment_queryInfo
returns estimated_weight
(called weight
in the response), and a partialFee
value, which is our best
guess at the inclusion fee for the tx without actually submitting it and seeing
whether the node changes the weight or decides not to take a fee at all.
To get the correct values for some extrinsic from both endpoints, provide the extrinsic bytes, and the number of the block before the block it is included in (e.g. if the extrinsic was in block 100, you'd use block 99 as an argument). This is very important.
Once you've called these endpoints, access the ExtrinsicSuccess
event to find
the actual_weight
, but also a paysFee
value which signals whether the extrinsic
actually incurred a fee at all or not (a node has the opportunity to refund the
fee entirely).
With all of those values at hand, the equation above calculates the correct Fee. Why? Well, the basic way to calculate a pre-dispatch fee is:
partial_fee = base_fee + len_fee + adjusted_weight_fee
We can do this from just the RPC methods. But then once it's in a block, we need
to swap out the weight used to calculate that adjusted_weight_fee
with the
actual weight that was used from the ExtrinsicSuccess
event. In the end, the
calculation itself is simple, but gathering the details needed is the main difficulty.
We do this all in Rust simply to limit any precision loss.
This is a tool to calculate the payout of a staking era, either for a validator or a nominator. This is not a predictive estimation, instead it intakes data from a concluded era to arrive to the final amount. For this it takes the following parameters:
total_reward_points
are the total era points
for a determined era.era_payout
is the payout
for a determined era.validator_reward_points
are the era points
earned by the validator in a determined era.validator_commission
is the commission that the validator takes of its assigned
payout before distribituing the remainder between itself and it's nominators.nominator_exposure
is the amount staked by the nominator or validator,
depending on who we are inquiring about.total_exposure
the total amount staked.is_validator
is a bool
that states whether the inquired account is a validator.We welcome contributions for documentation and code. If you have any questions you can reach the maintainers by filing an issue on github.
20.4.0 (2025-07-24)
/rc/runtime/code
, /rc/runtime/metadata
, and /rc/runtime/spec
endpoints/rc/node/network
, /rc/node/transaction-pool
, and /rc/node/version
endpointsuseRcBlock
, remove rcAt
in favor of useRcBlock
(#1709)
(1c97088)
useRcBlock
parameter across all endpoints/rc
prefix (#1704) (1376c35)
/rc/accounts/:address/balance-info
and /rc/accounts/:address/proxy-info
endpointsrcAt
for /pallets/*
endpoints (#1703) (00f8311)
rcAt
parameteruseRcBlock
for /blocks/*
endpoints (#1702) (c350c7e)
rcAt
for all applicable /accounts/*
endpoints (#1701) (9fcddc9)
rcAt
query parameter support for Asset Hub Migration (#1700) (9febf6e)
/pallets/staking/progress
using local BABE calculations (#1695)
(e3948b7)
/rc/accounts/:accountId/balance-info
endpoint (#1692) (a90ec1e)
rcBlockNumber
is always a number (#1714) (02f4788)
rcBlockNumber
returns actual block numbers instead of hashes or "latest"Tested against the following node releases:
Tested against the following runtime releases:
This release introduces comprehensive Relay Chain (RC) endpoint support for Asset Hub instances. For detailed documentation on the useRcBlock
parameter and RC endpoints, see: https://hackmd.io/bsNiDWbMRROB4olHbUtuaA
useRcBlock
Query ParameterAccount Endpoints:
/accounts/:address/balance-info
/accounts/:address/asset-balances
/accounts/:address/asset-approvals
/accounts/:address/pool-asset-balances
/accounts/:address/pool-asset-approvals
/accounts/:address/proxy-info
/accounts/:address/staking-info
/accounts/:address/staking-payouts
/accounts/:address/vesting-info
Block Endpoints:
/blocks
/blocks/head
/blocks/:number
/blocks/head/header
/blocks/:number/header
/blocks/:blockId/extrinsics/:extrinsicIndex
/blocks/:blockId/extrinsics-raw
Pallet Endpoints:
/pallets/:palletId/storage
/pallets/:palletId/storage/:storageItemId
/pallets/:palletId/consts
/pallets/:palletId/consts/:constantItemId
/pallets/:palletId/events
/pallets/:palletId/events/:eventItemId
/pallets/:palletId/errors
/pallets/:palletId/errors/:errorItemId
/pallets/:palletId/dispatchables
/pallets/:palletId/dispatchables/:dispatchableItemId
/pallets/assets/:assetId/asset-info
/pallets/pool-assets/:assetId/asset-info
/pallets/asset-conversion/*
/pallets/on-going-referenda
/rc
PrefixRC Account Endpoints:
/rc/accounts/:address/balance-info
/rc/accounts/:address/proxy-info
RC Block Endpoints:
/rc/blocks
/rc/blocks/head
/rc/blocks/:number
/rc/blocks/head/header
/rc/blocks/:number/header
/rc/blocks/:blockId/extrinsics/:extrinsicIndex
/rc/blocks/:blockId/extrinsics-raw
RC Pallet Endpoints:
/rc/pallets/:palletId/storage
/rc/pallets/:palletId/storage/:storageItemId
/rc/pallets/:palletId/consts
/rc/pallets/:palletId/consts/:constantItemId
/rc/pallets/:palletId/events
/rc/pallets/:palletId/events/:eventItemId
/rc/pallets/:palletId/errors
/rc/pallets/:palletId/errors/:errorItemId
/rc/pallets/:palletId/dispatchables
/rc/pallets/:palletId/dispatchables/:dispatchableItemId
/rc/pallets/on-going-referenda
RC Runtime Endpoints:
/rc/runtime/code
/rc/runtime/metadata
/rc/runtime/spec
RC Node Endpoints:
/rc/node/network
/rc/node/transaction-pool
/rc/node/version
FAQs
Off-chain calculations for @substrate/api-sidecar.
The npm package @substrate/calc receives a total of 848 weekly downloads. As such, @substrate/calc popularity was classified as not popular.
We found that @substrate/calc demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 4 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
An opt-in lazy import keyword aims to speed up Python startups, especially CLIs, without the ecosystem-wide risks that sank PEP 690.
Security News
Socket CEO Feross Aboukhadijeh discusses the recent npm supply chain attacks on PodRocket, covering novel attack vectors and how developers can protect themselves.
Security News
Maintainers back GitHub’s npm security overhaul but raise concerns about CI/CD workflows, enterprise support, and token management.