Connecting to the blockchain
How to connect to the Public Mint blockchain.
Last updated
How to connect to the Public Mint blockchain.
Last updated
Integrating or building solely on the blockchain doesn't require permission from Public Mint or anybody else. You can connect to the Public Mint blockchain by remotely connecting to it and only takes a few steps.
Developing blockchain-based applications usually requires work on two domains:
Smart contract development: code which gets deployed to the blockchain, written in Solidity in the case of Public Mint (and Ethereum);
Web or app development: code deployed on the web as an interface to read and write data from the blockchain/smart contracts.
Even though you can connect your web app directly to a client using JSON-RPC calls, you can use a wrapper to make your life easier when trying to connect the two domains and create a full-fledged interface.
Web3.js is a collection of Javascript libraries that allow you to easily perform transactions on the blockchain. This includes read/write data, send money, and even deploy smart contracts!
We use Node.js, publicmint-web3.js, and similar Javascript-based libraries throughout this documentation. However, you are free to use any language/wrapper you want.
Connecting to the blockchain takes just a few steps:
The Public Mint client is based on Hyperledger Besu, and likewise it includes a command line interface and JSON-RPC API for running and monitoring nodes.
Our client also supports smart contract deployment and operational tools (such as Remix, web3.js, or MyCrypto). Apart from a few key differences, the interface should be quite familiar to Ethereum developers.
In our examples we'll use publicmint-web3.js, this package is a umbrella class that is building above web3.js one of the most popular Javascript libraries for Ethereum. For installation instructions, go to publicmint-web3.js and web3.js .
Start by installing publicmint-web3.js. From the terminal, type:
Inside index.js
start by requiring web3:
This variable will now allow you to create a connection to a Public Mint node.
Next, it's time to connect. Depending on whether your are connecting to our TestNet (blockchain used by Public Mint Sandbox environment) or to our MainNet (Public Mint production environment), you should enter the following:
See more about providers here.
This step will create a normal web3 instance excluding modules not working for now (excluded modules), and create a new namespace web3.pm
that contains all contracts and basic features for interface with PublicMint client.
Learn more about .pm
modules.
You're almost done. Now it's time to test it.
To make sure everything went smoothly, let's query the blockchain for the latest block:
Congratulations! You are connected to the Public Mint blockchain. Read on to go through examples of some of the operations you can perform.