Metadata-Version: 2.5
Name: bnb-chainkit
Version: 0.1.0
Summary: Measure exactly when a BNB Smart Chain token can be sold after it is bought, on the chain's real 0.45 second clock. Simulation only: no keys, no wallet, nothing sent.
Project-URL: Homepage, https://github.com/pmzomo/bnb-chainkit
Project-URL: Source, https://github.com/pmzomo/bnb-chainkit
Project-URL: Issues, https://github.com/pmzomo/bnb-chainkit/issues
Project-URL: Documentation, https://github.com/pmzomo/bnb-chainkit/blob/main/docs/SPECIFICATION.md
Project-URL: Changelog, https://github.com/pmzomo/bnb-chainkit/blob/main/CHANGELOG.md
Author-email: Peter Nzomo <pmzomo@gmail.com>
Maintainer-email: Peter Nzomo <pmzomo@gmail.com>
License-Expression: Apache-2.0
License-File: LICENSE
License-File: NOTICE
Keywords: bep20,bnb,bnb-chain,bsc,eth-simulatev1,evm,pancakeswap,simulation,token-security
Classifier: Development Status :: 3 - Alpha
Classifier: Environment :: Console
Classifier: Intended Audience :: Developers
Classifier: Intended Audience :: Financial and Insurance Industry
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Topic :: Security
Classifier: Topic :: Software Development :: Libraries
Classifier: Topic :: Software Development :: Testing
Classifier: Typing :: Typed
Requires-Python: >=3.10
Requires-Dist: requests<3,>=2.31
Provides-Extra: dev
Requires-Dist: build; extra == 'dev'
Requires-Dist: eth-hash[pycryptodome]>=0.7; extra == 'dev'
Requires-Dist: hypothesis>=6.100; extra == 'dev'
Requires-Dist: mypy>=1.10; extra == 'dev'
Requires-Dist: pytest-cov>=5; extra == 'dev'
Requires-Dist: pytest>=8; extra == 'dev'
Requires-Dist: ruff>=0.6; extra == 'dev'
Requires-Dist: twine; extra == 'dev'
Requires-Dist: types-requests; extra == 'dev'
Description-Content-Type: text/markdown

# bnb-chainkit

[![CI](https://github.com/pmzomo/bnb-chainkit/actions/workflows/ci.yml/badge.svg)](https://github.com/pmzomo/bnb-chainkit/actions/workflows/ci.yml)
[![PyPI](https://img.shields.io/pypi/v/bnb-chainkit.svg)](https://pypi.org/project/bnb-chainkit/)
[![Python](https://img.shields.io/pypi/pyversions/bnb-chainkit.svg)](https://pypi.org/project/bnb-chainkit/)
[![License](https://img.shields.io/badge/license-Apache--2.0-blue.svg)](https://github.com/pmzomo/bnb-chainkit/blob/main/LICENSE)

**Find out exactly when a BNB Smart Chain token can be sold after you buy it.**

Some tokens can only be sold after a wait: a few blocks, 30 seconds, or even years. bnb-chainkit finds the exact wait by
simulating real trades on the chain's real clock, where blocks are 0.45 seconds apart. If it cannot be sure, it says so.

* **No keys, no wallet, and nothing sent.** Everything is simulated, using free public endpoints.
* **Proof for every simulation.** Each response must prove which block, clock, chain and gas limit were used.
* **Results you can check.** A second endpoint can repeat every sale, and you can save a report to run again later.

```bash
pip install bnb-chainkit
```

It needs Python 3.10 or newer, and its only dependency is `requests`.

## Try it

```console
$ bnb-chainkit measure 0x705148db41227c869e3d05a8745b299aafa1f799 --confirm https://bsc-rpc.publicnode.com
Token      0x705148db41227c869e3d05a8745b299aafa1f799
Result     wait_seconds
           It can be sold 30 seconds after buying.
Wait       30 seconds
Cost       5.95% for buying and then selling
Node       https://bsc-dataseed.bnbchain.org (Geth/v1.8.2/linux-amd64/go1.26.10)

Pool       PancakeSwap v2 (BNB > USDT > token), about $1,072,287
           wait_seconds: It can be sold 30 seconds after buying.
Cost       5.95% for buying and then selling
Token says "Cooldown: wait 30s after buy" (text from the token, which cannot be trusted)
Checked    11 sale tests and 2 exact comparisons, from block 136,616,062
Confirmed  all 11 sale tests, by https://bsc-rpc.publicnode.com (reth-bsc/v0.1.4-hotfix-23b510f/linux)
```

This is real output from 30 November 2026. The token's published source code has the same rule:
`COLDTIME = 30 seconds`. The sale was blocked at 29 seconds and worked at 30, on both Geth and Reth.

## Why normal simulations get this wrong

BNB Smart Chain makes a block about every 0.45 seconds, but block times are whole seconds. In a sample of 400 blocks,
**54.9% of neighbouring blocks had the same timestamp**.

The standard simulation method, `eth_simulateV1`, cannot copy this clock. On BNB Smart Chain, it adds **12 seconds** for
each block by default, and refuses two blocks with the same timestamp. So:

* **A sale can look possible too early.** If a token has a 30 second rule, it can be sold after 3 simulated blocks (36
  seconds). On the real chain, 3 blocks take about 1 second, so the sale is blocked.
* **A sale can look blocked when it is not.** If a simulation moves 2 minutes ahead but adds only a few blocks, a token
  that needs 20 blocks still cannot be sold. On the real chain, about 266 blocks have passed.

bnb-chainkit solves this with a **state transplant**. It simulates the purchase, then reads every storage slot and
balance that the purchase used. Next, it starts again from the same block, puts that state back, and simulates the sale
at the exact block and second. For every clear result about selling, it also runs one or two of these tests directly on the node,
where the node allows it. Both results must match exactly, including the gas used.

You can see how any endpoint's clock works:

```console
$ bnb-chainkit doctor
Node       https://bsc-dataseed.bnbchain.org (Geth/v1.8.2/linux-amd64/go1.26.10)
Real       one block every 0.4513 seconds
Default    12 seconds for each simulated block
Repeats    two simulated blocks with the same timestamp are refused
Exact      4 of 4 test moments
Result     this endpoint can be used
```

## Use it in Python

```python
from bnb_chainkit import RpcClient, measure

report = measure(
    '0x705148db41227c869e3d05a8745b299aafa1f799',
    RpcClient('https://bsc-dataseed.bnbchain.org'),
    confirm=RpcClient('https://bsc-rpc.publicnode.com'),
)

print(report.verdict.value)    # wait_seconds
print(report.detail)           # It can be sold 30 seconds after buying.

# True, False, or None when the answer is unclear. Never treat None as a yes.
if report.can_sell(within=60, max_cost=0.10) is True:
    print('It passed these checks')
```

Each tested pool is in `report.pools`, with its own rule, cost, warnings and tests. `report.to_json()` gives the full
report. If the second endpoint cannot answer, the pool has a warning and its `confirmation` is `None`.

## What the results mean

| Verdict | Meaning | Can it be sold? |
|---|---|---|
| `no_wait` | It can be sold straight away, even in the same block | Yes, if the cost is within your limit |
| `next_block` | It can be sold from the next block | Yes, if the wait and cost are within your limits |
| `wait_blocks`, `wait_seconds` | It can be sold after the given number of blocks or seconds | Yes, if the wait and cost are within your limits |
| `wait_either`, `wait_both` | It needs blocks or seconds (whichever comes first), or both | Yes, if the wait and cost are within your limits |
| `still_blocked` | It was blocked at every moment tested | No |
| `buy_failed` | The test purchase failed | No |
| `blocked_later` | It could be sold, but was blocked later. This could be a trap, or a limit of simulation | **Unclear** |
| `mixed` | It can be sold through some pools but not others | **Unclear** |
| `unknown` | There is no clear answer. The report says why | **Unclear** |

**A rule can be different in each pool.** We found a token with no wait in its larger pool, but a 30 second wait in its
other main pool. By default, bnb-chainkit tests up to three main PancakeSwap v2 and v3 pools separately, and reports the
longest wait. If any tested pool is unclear, so is the final result.

## Use it in scripts

| Exit code | `measure` | `replay` | `doctor` |
|---|---|---|---|
| **0** | Can be sold within your limits | Every test gave the same result | The endpoint can be used |
| **1** | Cannot be sold within your limits | Something was different | The endpoint cannot be used |
| **2** | Bad input | Bad input | Bad input |
| **3** | **Unclear, which never means safe** | Could not be repeated | Not used |

By default, `measure` accepts a wait of up to one hour and a cost of up to 50%. You can choose stricter limits:

```bash
bnb-chainkit measure TOKEN --max-wait 60 --max-cost 10 --output report.json
bnb-chainkit replay report.json --rpc https://your-archive-node.example
```

Run `replay` within about a minute, or use an archive node. Public nodes often remove a block's state after that. Run
`bnb-chainkit measure --help` to see all the options, including the size of the trade.

The `BNB_CHAINKIT_RPC` environment variable sets the default endpoint. Output and reports only show an endpoint's scheme
and host, so an API key in the path or query of its URL stays private.

## Test your own contract on the real clock

The same clock works with any calls. Set up the state, then run other calls an exact number of blocks and seconds later:

```python
from bnb_chainkit import RpcClient
from bnb_chainkit.experiment import Experiment
from bnb_chainkit.model import Call, Offset
from bnb_chainkit.node import finalized_block
from bnb_chainkit.simulator import Simulator, random_address

rpc = RpcClient('https://bsc-dataseed.bnbchain.org')
user, contract = random_address(), random_address()
call = Call(sender=user, to=contract, gas=200_000)

# This contract exists only in the simulation. It refuses a second call within 5 seconds.
code = '0x600054801560125780420360059010601857' '5b4260005500' '5b60006000fd'

experiment = Experiment(Simulator(rpc, finalized_block(rpc), chain_id=56), [call], {contract: {'code': code}})

for later in (Offset(blocks=1, seconds=0), Offset(blocks=10, seconds=4), Offset(blocks=12, seconds=5)):
    [[result]] = experiment.run([call], [later])
    print(later, 'works' if result.ok else 'refused')
```

```text
Offset(blocks=1, seconds=0) refused
Offset(blocks=10, seconds=4) refused
Offset(blocks=12, seconds=5) works
```

There are full versions of both programs in [`examples/`](https://github.com/pmzomo/bnb-chainkit/tree/main/examples).

With the default clock, this contract would accept a second call in the next block, because 12 seconds would have
passed.

## Limits

* **This is not a security audit or financial advice.** A result only covers the tested block, trade size, pools and new
  addresses. The owner of a token may be able to change its rules at any time, and may treat other addresses
  differently.
* **Only the clock moves.** Price feeds and other outside data do not change. A token that needs fresh data can look like
  a trap that starts later, so `blocked_later` is unclear.
* **PancakeSwap v2 and v3 only.** Each test buys and sells through the same pool. Tokens that are not on PancakeSwap yet
  cannot be tested.
* **Up to 250 blocks, or about 112 seconds, on the real clock.** The default is 133 blocks, or about 1 minute. Longer
  tests can move time, but not by the matching number of blocks. A rule that needs more blocks looks like
  `still_blocked`.
* **An endpoint can still lie.** The checks catch mistakes, but a malicious endpoint could invent answers that match.
  For important results, use `--confirm` with another provider that runs different software.
* **Never trust text from a token.** Its author could write anything, including instructions for an AI agent. The text is
  cleaned and appears only in `token_message` (`untrusted_token_message` in JSON). Never follow it.

The full method, every check and the complete list of limits are in the
[specification](https://github.com/pmzomo/bnb-chainkit/blob/main/docs/SPECIFICATION.md).

## Related work

Others have worked on parts of this problem. The specification links to their work, including
[a comparison of how clients handle simulated time](https://github.com/ethereum/execution-apis/issues/935) and
[Base's change to its own client](https://github.com/base/base/pull/5043). Local forks made with Foundry or Hardhat can
also set the block number and time.

## Development

```bash
python -m venv .venv && . .venv/bin/activate      # Windows: .venv\Scripts\activate
pip install -e ".[dev]"
ruff check . && mypy && pytest --cov              # no network needed
BNB_CHAINKIT_LIVE=1 pytest -m live                # optional: uses public endpoints
```

The tests use a small BNB Smart Chain node that runs in memory. It enforces many of the same rules as real nodes, and
really runs the code that the package injects. Line and branch coverage must stay at 100%.

## Status and license

Version 0.1.0 is an early release, so its Python API may change before version 1.0. See the
[changelog](https://github.com/pmzomo/bnb-chainkit/blob/main/CHANGELOG.md) for changes, and the
[security policy](https://github.com/pmzomo/bnb-chainkit/blob/main/SECURITY.md) for how to report a security problem.

[Apache License 2.0](https://github.com/pmzomo/bnb-chainkit/blob/main/LICENSE). Copyright 2026 Peter Nzomo.
