BDB Chain 公链接口对接说明

BDB Chain 为 EVM 兼容 公链,可使用标准 Ethereum JSON-RPC、Web3.js / Ethers.js 及 EIP-1193 钱包 Provider 进行转账、合约调用与签名。本文档供 DApp、交易所、区块浏览器与第三方钱包对接使用。

1. 网络参数

项值
链名称BDB Chain
Chain ID(十进制)20240606
Chain ID(十六进制)0x134d8de
原生代币BDB(Gas 费)
精度18
RPC URL(主)https://chain.bdbweb3.us
区块浏览器https://scan.bdbweb3.us
交易详情页https://scan.bdbweb3.us/tx/{txHash}
地址详情页https://scan.bdbweb3.us/address/{address}
DApp 首页http://www.bdbweb3.site/
DEX 前端https://dex.bdbweb3.site

添加到 MetaMask / 其他 EVM 钱包

{
  "chainId": "0x134d8de",
  "chainName": "BDB Chain",
  "nativeCurrency": {
    "name": "BDB",
    "symbol": "BDB",
    "decimals": 18
  },
  "rpcUrls": ["https://chain.bdbweb3.us"],
  "blockExplorerUrls": ["https://scan.bdbweb3.us"]
}

2. JSON-RPC 接口

POST https://chain.bdbweb3.us · Content-Type: application/json

常用方法

方法说明
eth_chainId返回 0x134d8de
eth_blockNumber最新区块高度
eth_getBalance查询 BDB 余额(参数:address, block)
eth_getTransactionCount查询 nonce
eth_gasPrice建议 Gas Price(legacy)
eth_estimateGas估算 Gas Limit
eth_call只读合约调用
eth_sendRawTransaction广播已签名交易
eth_getTransactionReceipt查询交易回执
eth_getLogs查询事件日志

示例:查询 BDB 余额

curl -X POST https://chain.bdbweb3.us \
  -H "Content-Type: application/json" \
  -d '{
    "jsonrpc":"2.0",
    "method":"eth_getBalance",
    "params":["0xYourAddress", "latest"],
    "id":1
  }'
说明:BDB Chain 与 Ethereum 一样使用 secp256k1 + Keccak-256 签名。 交易需带正确 chainId(EIP-155 防重放),签名后通过 eth_sendRawTransaction 上链。

3. BDBKEY 钱包内 DApp Provider(EIP-1193)

在 BDBKEY App 内置浏览器(Discover / DApp)中打开页面时,会注入 window.ethereum 与 window.web3, 兼容 MetaMask 类 DApp 的常见调用方式。

支持的钱包方法

方法说明
eth_requestAccounts / requestAccounts获取当前钱包地址
eth_accounts已连接账户列表
eth_chainId当前链 ID
eth_sendTransaction发起转账 / 合约交易(App 内弹窗确认)
personal_sign个人消息签名(EIP-191)
eth_sign原始消息签名
eth_signTypedData_v4结构化数据签名(EIP-712)
eth_call通过钱包代理的只读调用
wallet_addEthereumChain添加自定义链(若链已内置则匹配切换)
wallet_switchEthereumChain切换链
wallet_requestPermissions兼容映射到 eth_accounts

连接钱包(Ethers v6)

const provider = new ethers.BrowserProvider(window.ethereum);
await provider.send("eth_requestAccounts", []);
const signer = await provider.getSigner();
const address = await signer.getAddress();
const network = await provider.getNetwork();
console.log("address:", address, "chainId:", network.chainId);

切换到 BDB Chain

try {
  await window.ethereum.request({
    method: "wallet_switchEthereumChain",
    params: [{ chainId: "0x134d8de" }]
  });
} catch (e) {
  if (e.code === 4902) {
    await window.ethereum.request({
      method: "wallet_addEthereumChain",
      params: [{
        chainId: "0x134d8de",
        chainName: "BDB Chain",
        nativeCurrency: { name: "BDB", symbol: "BDB", decimals: 18 },
        rpcUrls: ["https://chain.bdbweb3.us"],
        blockExplorerUrls: ["https://scan.bdbweb3.us"]
      }]
    });
  }
}
BDBKEY 默认主网即为 BDB Chain;在 App 内打开 bdbweb3.site / dex.bdbweb3.site 等站点时通常无需手动切链。

4. 原生 BDB 转账

通过钱包 Provider(推荐 DApp)

const tx = await signer.sendTransaction({
  to: "0xRecipientAddress",
  value: ethers.parseEther("1.0")   // 1 BDB
});
await tx.wait();

离线签名 + RPC 广播

// 1. 获取 nonce、gasPrice、estimateGas
// 2. 构造 legacy 交易(type 0)或 EIP-1559(若链支持)
// 3. signTransaction + eth_sendRawTransaction

const rawTx = await wallet.signTransaction({
  to: recipient,
  value: amountWei,
  gasLimit,
  gasPrice,
  nonce,
  chainId: 20240606
});
// eth_sendRawTransaction(rawTx)
Gas:手续费以 BDB 支付。账户需保留足够 BDB 作为 Gas,否则交易失败。

5. ERC20 代币操作

BDB Chain 上常用代币为标准 ERC20(18 位小数,USDT 同为 18 位)。

查询余额

const erc20Abi = [
  "function balanceOf(address) view returns (uint256)",
  "function decimals() view returns (uint8)",
  "function symbol() view returns (string)"
];
const token = new ethers.Contract(tokenAddress, erc20Abi, provider);
const bal = await token.balanceOf(userAddress);

转账 transfer

const erc20Abi = [
  "function transfer(address to, uint256 amount) returns (bool)"
];
const token = new ethers.Contract(tokenAddress, erc20Abi, signer);
const tx = await token.transfer(recipient, ethers.parseUnits("100", 18));
await tx.wait();

授权 approve(DEX / 第三方合约)

const erc20Abi = [
  "function approve(address spender, uint256 amount) returns (bool)",
  "function allowance(address owner, address spender) view returns (uint256)"
];
const token = new ethers.Contract(tokenAddress, erc20Abi, signer);
await token.approve(spenderAddress, ethers.MaxUint256);

消息签名

// personal_sign
const sig = await signer.signMessage("Hello BDB");

// EIP-712 typed data
const sig712 = await signer.signTypedData(domain, types, value);

6. 链上 DEX 合约(BCT/USDT)

BDB Chain 内置 AMM 合约为 BCT ↔ USDT 交易对。 方法名中 BNB 为历史命名,实际对应池内 BCT 储备,并非原生 BDB。

合约地址
Swap / Pool0x1F60aaF98D89e0d59d87ACDD15498FAA27099eD2
Token Factory0xf98032d0ABC50EE27C9eEc63a530fcdb9DF14918

主要 ABI 方法

方法说明
reserveBNB()BCT 储备量(uint256,18 decimals)
reserveUSDT()USDT 储备量
getAmountOut(amountIn, reserveIn, reserveOut)按恒定乘积公式计算输出量
swapBNBForUSDT(bnbAmountIn, minUSDTOut)卖 BCT 换 USDT(需先 approve BCT)
swapUSDTForBNB(usdtAmountIn, minBNBOut)卖 USDT 换 BCT(需先 approve USDT)

Swap 流程

  1. 调用 getAmountOut 或读取 reserveBNB / reserveUSDT 计算预期输出
  2. 对输入代币 approve(SWAP, amount)
  3. 调用 swap*,minOut 建议留 0.5%~2% 滑点
const SWAP = "0x1F60aaF98D89e0d59d87ACDD15498FAA27099eD2";
const BCT  = "0x9A98A76D616d3dE697265374b49282683f0486C0";
const USDT = "0xC9Fd65481a41e1fA82Bdb8BFA7b43776c7033Fa0";

// 示例:USDT → BCT
const amountIn = ethers.parseUnits("10", 18);
await usdt.approve(SWAP, amountIn);
const swap = new ethers.Contract(SWAP, [
  "function swapUSDTForBNB(uint256 usdtAmountIn, uint256 minBNBOut)"
], signer);
await swap.swapUSDTForBNB(amountIn, minBctOut);
注意:原生主网币 BDB 不在该 DEX 池内,不能直接与 USDT swap。 如需 BDB 计价展示,请与运营方确认;链上成交价以池子储备为准。

7. 常用代币合约地址

符号名称地址精度链
BDB原生 Gas 代币—(无合约)18BDB
BCTBDB Chain Token0x9A98A76D616d3dE697265374b49282683f0486C018BDB
USDTBDB USDT0xC9Fd65481a41e1fA82Bdb8BFA7b43776c7033Fa018BDB
STCSTC Token0x8f94c7356aa03390e8bdcfd308c3287e1f7175f918BDB
STDSTD Token0x3ffa1a33756ad3ef3baeb6bdd8e058e13d35089718BDB
BTZBBTZB Token0xba8a6202ba93dd30dbcd80269b778cc9137bafb618BDB

8. 区块浏览器 API(Etherscan 兼容)

GET https://scan.bdbweb3.us/api?

查询参数与 Etherscan API 类似,例如:

模块示例
账户交易列表 ?module=account&action=txlist&address=0x...&startblock=0&endblock=99999999&sort=desc
ERC20 转账 ?module=account&action=tokentx&address=0x...&contractaddress=0x...
余额 ?module=account&action=balance&address=0x...&tag=latest
若 API Key 为可选项,请以浏览器站点实际要求为准。

9. 完整 DApp 对接检查清单

  1. RPC 指向 https://chain.bdbweb3.us,Chain ID = 20240606
  2. 页面加载后调用 eth_requestAccounts 连接钱包
  3. 确认 eth_chainId 为 0x134d8de,否则提示用户切链
  4. BDB 转账使用 sendTransaction;ERC20 走合约 transfer
  5. 与 DEX 交互前先 approve,再调用 Swap 合约
  6. 交易发出后轮询 eth_getTransactionReceipt 或浏览器链接
  7. 签名登录:优先 personal_sign 或 EIP-712,后端用 ecrecover 验签

Web3.js 连接示例

const web3 = new Web3(window.ethereum);
await window.ethereum.request({ method: "eth_requestAccounts" });
const accounts = await web3.eth.getAccounts();
const chainId = await web3.eth.getChainId();
console.log(accounts[0], chainId); // chainId 应为 20240606n

10. 常见问题

Q: BDB 与 BCT 有什么区别?

BDB 是链原生 Gas 代币;BCT 是链上 ERC20,并在 DEX 中与 USDT 组成交易对。 两者地址、用途、价格来源不同,对接时请区分。

Q: 能否在 RPC 直接用私钥发交易?

可以。使用任意 EVM 库本地签名后,调用 eth_sendRawTransaction 广播即可,无需经过钱包 App。

Q: DApp 在 BDBKEY 外如何对接?

任何支持自定义 EVM 链的钱包(MetaMask、WalletConnect 等)均可添加 BDB 网络参数。 WalletConnect 项目需配置 Chain ID eip155:20240606。

Q: 行情 / K 线 API?

BCT/USDT 现货可读取 Swap 合约储备计算;STC/STD/BTZB 等可通过运营方 K 线服务 (如 kapi.bdbweb3.site)获取,与链上 RPC 相互独立。