Article directory
foreword
Ganache is a test network for DApps, providing a graphical interface, log logs, etc.; when deploying smart contracts, it is necessary to connect to the test network.
Ganache is a network running locally for testing. By combining cpolar intranet penetration software, it is relatively simple to realize remote or different LAN connection access. The following briefly summarizes the settings and connection methods
1. Install Ganache
Enter the official website: https://trufflesuite.com/ganache/, we download the version of the corresponding computer system, after downloading the installation package, install it directly
After the installation is complete, we open Ganache, and we can see that many test addresses are generated for us by default. These addresses are all false. At the top, we can see the RPC service local connection address, and the port is:7545
2. Install cpolar
cpolar official website: https://www.cpolar.com/
Visit the cpolar official website, register an account, and then download and install the client. For specific installation tutorials, please refer to the official website documentation tutorial.
- Windows system: After downloading the installation package from the official website, double-click the installation package and install it by default.
- Linux system: supports one-click automatic installation scripts, please refer to the official website documentation for details - Getting Started Guide
After cpolar is successfully installed, visit the local port 9200 [ http://localhost:9200 ] on the browser , and log in with the cpolar account.
3. Create a public address
Click Tunnel Management on the left dashboard - Create Tunnel to create a 7545 tunnel for our RPC SERVER on Ganache
- Tunnel name: you can customize the name, be careful not to duplicate the existing tunnel name
- Protocol: select http
- Local address: 7545
- Domain name type: choose a random domain name for free
- Region: Select China VIP
click创建
After the tunnel is successfully created, click on the status on the left - online tunnel list to view the generated public network address. There are two access methods, one is http and https
4. Public network access connection
When we make a remote connection, we only need to replace the local connection address with the public http address generated by cpolar
const provide = new ethers.providers
.JsonRpcProvider("http://73e047ba.r10.vip.cpolar.cn");
This example demonstrates the nodejs version, and the settings of other versions are similar. Then run our js file, and you can see that the connection is successful. This method is very helpful for us to test our functions remotely or in different networks
Similarly, if you open Ganache's transaction, you can see the new block we just created after running it. This method realizes different networks on different computers with different people, and you can also connect to the local test network for testing through the public network address.
5. Fixed public network address
Since the above tunnel created by using cpolar uses a random public network address, it will change randomly within 24 hours, which is not conducive to long-term remote access. Therefore, we can configure a second-level subdomain name for it, which is a fixed address and will not change randomly [ps: cpolar.cn has been filed]
Note that the cpolar package needs to be upgraded to the basic package or above, and the bandwidth corresponding to each package is different. [cpolar.cn has been filed]
Log in to the cpolar official website, click Reserve on the left, choose to reserve the second-level subdomain name, set a second-level subdomain name, click Reserve, copy the reserved second-level subdomain name after the reservation is successful, and copy the reserved second-level subdomain name address
Log in to the cpolar web UI management interface, click Tunnel Management on the left dashboard - Tunnel List, find the tunnel to be configured, and click Edit on the right
Modify the tunnel information, and configure the successfully reserved second-level subdomain name into the tunnel
- Domain name type: select a second-level subdomain name
- Sub Domain: Fill in the reserved sub-domain name
click更新
After the update is complete, open the online tunnel list, and you can see that the public network address has changed, and the address name has also become a reserved and fixed second-level subdomain name
Finally, we use a fixed public network address for connection access, no error or connection exception, you can see that the connection is successful, and a fixed address access is set up
Finally, we use a fixed public network address for connection access, no error or connection exception, you can see that the connection is successful, and a fixed address access is set up