where YOUR_CHAINSTACK_ENDPOINT — your node HTTPS or WSS endpoint protected either with the key or password. See node access details.
Invoke any methods from Web3 JavaScript API.Example below demonstrates how to get the balance of an address in wei value and convert it to ether value:
Configure Hardhat to deploy contracts and interact through your BNB Smart Chain nodes.
Install Hardhat 2 with the ethers plugin by running npm install --save-dev hardhat@hh2 @nomicfoundation/hardhat-ethers@hh2 ethers, and create a project with npx hardhat init. The hh2 tag installs Hardhat 2, which this configuration uses.
In Remix IDE, navigate to the Deploy tab. Select Injected Provider - MetaMask in Environment.
This will engage MetaMask and make Remix IDE interact with the network through a Chainstack node.
web3.py
Build DApps using web3.py and BNB Smart Chain nodes deployed with Chainstack.
Use AsyncWeb3 with the WebSocketProvider object to connect to your node WSS endpoint and get the latest block number. The web3.py WebSocket provider is asynchronous, so the example runs in an asyncio event loop:
import asynciofrom web3 import AsyncWeb3, WebSocketProviderasync def main(): async with AsyncWeb3(WebSocketProvider('YOUR_CHAINSTACK_ENDPOINT')) as web3: print(await web3.eth.block_number)asyncio.run(main())
import asynciofrom web3 import AsyncWeb3, WebSocketProviderasync def main(): async with AsyncWeb3(WebSocketProvider('wss://%s:%s@%s'% ("USERNAME", "PASSWORD", "HOSTNAME"))) as web3: print(await web3.eth.block_number)asyncio.run(main())
where
YOUR_CHAINSTACK_ENDPOINT — your node WSS endpoint protected either with the key or password
HOSTNAME — your node WSS endpoint hostname
USERNAME — your node access username (for password-protected endpoints)
PASSWORD — your node access password (for password-protected endpoints)
Build DApps using web3j and BNB Smart Chain nodes deployed with Chainstack.Use the HttpService object to connect to your node endpoint.Example to get the latest block number: