Using a Public Testnet
Instead of setting up your own Devnet you can use a public Testnet. As explained earlier, while it is very easy to get started with this approach, there are two key limitations when using a public Testnet:
- You can create accounts on virtual nodes to simulate a participant but not actual nodes for each participant as it would be in a real solution.
- You need to find ways to add ether to your account, it may require a small investment of real money.
We will be using Sepolia, one of the most popular Ethereum Testnets on the cloud.
Web3 Providers
A web3 provider is a crucial component in the blockchain ecosystem that allows decentralized applications (DApps) to communicate with blockchain networks, including the Mainnet or Testnets like Sepolia. They act as a bridge between the application and the network, enabling seamless interaction with smart contracts and other blockchain functions.
In Sepolia, we don’t initialize our blockchain, instead we use virtual nodes provided by services like Alchemy or Infura. These services give us Endpoints and API Keys so that we can access these virtual nodes which are running on their own system. We will be using Infura for our implementation.
-
First, sign up on the Infura website (https://www.infura.io/ (opens in a new tab))
-
Second, generate an API key and select Sepolia.
-
Finally, go to the active endpoints section. Here you will find your API Key (redacted in the image below, since you should never disclose your API keys to anyone) which will be used once we are done with the development of smart contracts.
MetaMask
To create accounts on the Testnet we will use a provider known as Metamask. This is available as an extension to the Chrome and Edge (two of the more commonly used) browsers.
Install the Metamask extension and complete the guided setup. Open the extension and select Sepolia under the test networks (you may need to toggle a switch that says Show test Networks). Create three accounts representing the Buyer, Seller, and Transporter.
For each of the accounts note the Public Key and the Private Key both accessible from Metamask. These will be required in various other components to interact with the Blockchain network and the Smart Contract.
Executing any transaction on the Blockchain requires a small fee known as gas. The accounts will therefore need to be pre-funded with some Ether. To get ether you need to use a solution known as a faucet for the network you are using (the Sepolia Faucet for the Sepolia Network).
The Sepolia faucet provided by Alchemy is no longer free and now requires that the account purchase some ether on the Ethereum MainNet which requires an actual monetary transaction. There are several other faucets, please validate the genuineness and security of these faucets before you transact with them.
Deploying a Smart Contract
You can deploy a Smart Contract to the Sepolia Testnet from the Remix IDE, which has this as an in-built option.
Interacting with Sepolia
You can now connect and interact with your Testnet and Smart Contract using the web app, configured with the specific URL details as required (this will be explained in the web app user guide).