Magician-Web3 Update: Load Balancing, Retry Strategy, and Detailed Adjustments
The Magician-Web3 toolkit now supports load‑balanced RPC endpoints, a configurable retry strategy for skipped blocks, and several fine‑tuned adjustments such as a reduced minimum scan period and simplified chain detection, with code examples illustrating the new features.
Magician-Web3 is a blockchain development toolkit that provides two main capabilities: scanning blockchains with transaction monitoring and a secondary packaging of web3j to reduce developer effort. It targets three chains: Ethereum‑compatible networks (BSC, Polygon, etc.), Solana, and TRON.
Update Highlights
1. Load Balancing – By configuring multiple RPC URLs, the scanner automatically round‑robin requests across nodes, distributing traffic and avoiding reliance on a single endpoint.
2. Retry Strategy – When a block is empty (no transactions) and its height is less than the latest chain height, the scanner skips the block and passes its height to a user‑defined retry strategy for custom handling.
3. Minor detail adjustments.
Load Balancing
Simply set several RPC addresses; the toolkit will poll them automatically.
MagicianBlockchainScan.create()
.setRpcUrl(
// You can set 1 to n RPC URLs; more than one will be auto‑polled
EthRpcInit.create()
.addRpcUrl("https://data-seed-prebsc-1-s1.binance.org:8545")
.addRpcUrl("https://data-seed-prebsc-2-s1.binance.org:8545")
.addRpcUrl("https://data-seed-prebsc-1-s2.binance.org:8545")
)
.setScanPeriod(1000)
.setBeginBlockNumber(BlockEnums.LAST_BLOCK_NUMBER.getValue())
.addEthMonitorEvent(new EventOne())
.addEthMonitorEvent(new EventThree())
.setRetryStrategy(new EthRetry())
.start();Retry Strategy
The strategy is triggered only when both conditions are met: the current block being scanned is empty (no block or no transactions) and its number is lower than the latest block number on the chain. In that case the scanner skips the block, continues with the next one, and forwards the skipped block number to the retry strategy for user‑defined processing.
Create a Retry Strategy
public class EthRetry implements RetryStrategy {
@Override
public void retry(BigInteger blockNumber) {
// custom retry logic here
}
}Add the Retry Strategy to the Scan Task
MagicianBlockchainScan.create()
.setRetryStrategy(new EthRetry()) // call this method to add the strategy
.start();Thread Count Configuration
If you run a scan task together with a retry strategy, two threads are required; therefore the thread‑pool size must be at least the sum of scan tasks and retry strategies.
// Initialize thread pool; core threads must be >= number of scan tasks + retry strategies
EventThreadPool.init(2);Detail Adjustments
1. The minimum scan period can now be set to 500 ms.
2. The parameter type for RPC address configuration has changed.
3. Because of the RPC‑type optimization, the toolkit can infer the target chain from the RPC URL, so the explicit ChainType setting has been removed.
MagicianBlockchainScan.create()
.setRpcUrl(
// changed usage
EthRpcInit.create()
.addRpcUrl("https://data-seed-prebsc-1-s1.binance.org:8545")
.addRpcUrl("https://data-seed-prebsc-2-s1.binance.org:8545")
.addRpcUrl("https://data-seed-prebsc-1-s2.binance.org:8545")
)
.setScanPeriod(1000) // can be as low as 500 now
.setBeginBlockNumber(BlockEnums.LAST_BLOCK_NUMBER.getValue())
.addEthMonitorEvent(new EventOne())
.addEthMonitorEvent(new EventThree())
.setRetryStrategy(new EthRetry())
.start();Feel free to like and share if you found this article helpful.
Laravel Tech Community
Specializing in Laravel development, we continuously publish fresh content and grow alongside the elegant, stable Laravel framework.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.