Complete Monad tooling guide for Chainstack nodes. Use MetaMask, Hardhat, ethers.js, viem, Foundry, Remix IDE, and more to build dApps on Monad blockchain.
Monad Mainnet143MONhttps://monvision.ioMonad Mainnet143MONhttps://monvision.io143.Monad Mainnet143MONhttps://monvision.iohardhat.config.js:require("@nomiclabs/hardhat-waffle");...module.exports = { solidity: "0.8.19", networks: { chainstack: { url: "YOUR_CHAINSTACK_ENDPOINT", accounts: ["YOUR_PRIVATE_KEY"] }, }};npx hardhat run scripts/deploy.js --network chainstack and Hardhat will deploy using Chainstack.HTTPProvider to connect to your node endpoint and get the latest block number:from web3import Web3web3= Web3(Web3.HTTPProvider('YOUR_CHAINSTACK_ENDPOINT'))print(web3.eth.block_number)from web3import Web3web3= Web3(Web3.HTTPProvider('https://%s:%s@%s'% ("USERNAME","PASSWORD","HOSTNAME")))print(web3.eth.block_number)WebsocketProvider object to connect to your node WSS endpoint and get the latest block number:from web3import Web3web3= Web3(Web3.WebsocketProvider('YOUR_CHAINSTACK_ENDPOINT'))print(web3.eth.block_number)from web3import Web3web3= Web3(Web3.WebsocketProvider('wss://%s:%s@%s'% ("USERNAME","PASSWORD","HOSTNAME")))print(web3.eth.block_number)<?phprequire_once "vendor/autoload.php";use Web3\Web3;use Web3\Providers\HttpProvider;use Web3\RequestManagers\HttpRequestManager;$web3 = new Web3(new HttpProvider(new HttpRequestManager("YOUR_CHAINSTACK_ENDPOINT",5)));?><?phprequire_once "vendor/autoload.php";use Web3\Web3;use Web3\Providers\HttpProvider;use Web3\RequestManagers\HttpRequestManager;$web3 = new Web3(new HttpProvider(new HttpRequestManager("YOUR_CHAINSTACK_ENDPOINT",5)));$eth = $web3->eth;$eth->blockNumber(function ($err,$data) { print "$data \n";});?>HttpService object to connect to your node endpoint.Example to get the latest block number:package getLatestBlock;import java.io.IOException;import java.util.logging.Level;import java.util.logging.Logger;import org.web3j.protocol.Web3j;import org.web3j.protocol.core.DefaultBlockParameterName;import org.web3j.protocol.core.methods.response.EthBlock;import org.web3j.protocol.exceptions.ClientConnectionException;import org.web3j.protocol.http.HttpService;import okhttp3.Authenticator;import okhttp3.Credentials;import okhttp3.OkHttpClient;import okhttp3.Request;import okhttp3.Response;import okhttp3.Route;public final class App { private static final String USERNAME = "USERNAME"; private static final String PASSWORD = "PASSWORD"; private static final String ENDPOINT = "ENDPOINT"; public static void main(String[]args) { try { OkHttpClient.Builder clientBuilder = new OkHttpClient.Builder(); clientBuilder.authenticator(new Authenticator() { @Override public Request authenticate(Route route,Response response)throws IOException { String credential = Credentials.basic(USERNAME, PASSWORD); return response.request().newBuilder().header("Authorization", credential).build(); } }); HttpService service = new HttpService(ENDPOINT,clientBuilder.build(),false); Web3j web3 = Web3j.build(service); EthBlock.Block latestBlock = web3.ethGetBlockByNumber(DefaultBlockParameterName.LATEST,false).send().getBlock(); System.out.println("Latest Block: #" + latestBlock.getNumber()); }catch (IOException |ClientConnectionException ex) { Logger.getLogger(App.class.getName()).log(Level.SEVERE,null, ex); } }}JsonRpcProvider object to connect to your node endpoint and get the latest block number:const {ethers }= require("ethers");var urlInfo = { url: "YOUR_CHAINSTACK_ENDPOINT",};var provider = new ethers.providers.JsonRpcProvider(urlInfo,NETWORK_ID);provider.getBlockNumber().then(console.log);const {ethers }= require("ethers");var urlInfo = { url: "YOUR_CHAINSTACK_ENDPOINT", user: "USERNAME", password: "PASSWORD",};var provider = new ethers.providers.JsonRpcProvider(urlInfo,NETWORK_ID);provider.getBlockNumber().then(console.log);14310143WebSocketProvider object to connect to your node WSS endpoint and get the latest block number:const {ethers }= require("ethers");const provider = new ethers.providers.WebSocketProvider( "YOUR_CHAINSTACK_ENDPOINT", NETWORK_ID);provider.getBlockNumber().then(console.log);14310143createPublicClient function to connect to your node endpoint and get the latest block number:import {createPublicClient,http }from 'viem'const client = createPublicClient({ transport: http('YOUR_CHAINSTACK_ENDPOINT')})const blockNumber = await client.getBlockNumber()console.log(blockNumber)createPublicClient function with WebSocket transport:import {createPublicClient,webSocket }from 'viem'const client = createPublicClient({ transport: webSocket('YOUR_CHAINSTACK_ENDPOINT')})const blockNumber = await client.getBlockNumber()console.log(blockNumber)brownie networks add command with the node endpoint. For example, Monad mainnet:brownie networks add Monad ID name="NETWORK_NAME" host=YOUR_CHAINSTACK_ENDPOINT chainid=NETWORK_IDchainstack-mainnet.14310143brownie run deploy.py --network chainstack-mainnet--rpc-url to run the operation through your Chainstack node.forge to develop, test, and deploy your smart contracts.To deploy a contract:forge create CONTRACT_NAME --contracts CONTRACT_PATH --private-key YOUR_PRIVATE_KEY --rpc-url YOUR_CHAINSTACK_ENDPOINTcast to interact with the network and the deployed contracts.To get the latest block number:cast block-number --rpc-url YOUR_CHAINSTACK_ENDPOINTforge verify-contract CONTRACT_ADDRESS CONTRACT_NAME \ --verifier sourcify \ --verifier-url https://sourcify-api-monad.blockvision.org \ --rpc-url YOUR_CHAINSTACK_ENDPOINTforge verify-contract CONTRACT_ADDRESS CONTRACT_NAME \ --verifier etherscan \ --verifier-url https://api.monadscan.com/api \ --etherscan-api-key YOUR_MONADSCAN_API_KEY \ --rpc-url YOUR_CHAINSTACK_ENDPOINTWas this page helpful?