In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly introduces "how to deploy the intelligent contract of Ethernet Square to infura". In the daily operation, I believe many people have doubts about how to deploy the intelligent contract of Ethernet Square to infura. The editor has consulted all kinds of materials and sorted out simple and easy-to-use methods of operation. I hope it will be helpful to answer the doubts of "how to deploy the intelligent contract of Ethernet Square to infura". Next, please follow the editor to study!
In this particular example, we will migrate to the Ropsten test network. Let's assume that you already have a dapp. If you need a test dapp, you can use the pet store dapp provided by Truffle.
Install HDWalletProvider
Infura's HDWalletProvider is a stand-alone npm package, installed as follows:
Npm install truffle-hdwallet-provider
Note: if you install on Windows and encounter MSBUILD errors, you may need to install the Windows build tool. In the console with administrator privileges, run npm install-g windows-build-tools and then try the installation again.
Register for Infura
Before you can use Infura, you need to register an Infura access token.
You can receive an access token after filling out and submitting the form. The relevant information will be displayed on the screen and sent to the email you provided. You need to record this access token and make sure it is not seen by others!
Configure the Truffle project
The next step is to edit your truffle.js file to enable HDWalletProvider and make the necessary configuration for deployment to Ropsten.
STEP 1: first, define the HDWalletProvider object in the configuration file. Add the following code at the top of the truffle.js file:
Var HDWalletProvider = require ("truffle-hdwallet-provider")
STEP 2: next, provide mnemonic words (mnemonic) to generate your account.
Var mnemonic = "orange apple banana..."
Warning: during this process, we strongly recommend that mnemonics be stored in another (secret) file to reduce the risk of mnemonic leakage. If someone knows your mnemonic, they will have all your addresses and private keys!
STEP 3: add Ropsten network definition:
Module.exports = {networks: {ropsten: {provider: function () {return new HDWalletProvider (mnemonic, "https://ropsten.infura.io/")}, network_id: 3})
Note:
Although this example only defines a single network, you can define multiple networks as usual.
Provider in the ropsten network definition will use the instantiated HDWalletProvider.
HDWalletProvider takes mnemonics and the desired network as parameters. A list of networks supported by Infura on the Infura home page.
Be sure to replace it with the Infura access token you got earlier.
The provider value is encapsulated in a function, which ensures that it is not initialized before it is needed. This is especially important if you are connected to multiple networks. For more information on this topic, see the Network configuration section of the Truffle documentation.
By default, the first account generated by the mnemonic will be responsible for performing the contract migration task. But if necessary, you can pass in parameters to specify the account to use. For example, to use a third account:
New HDWalletProvider (mnemonic, "https://ropsten.infura.io/", 2)
The account index starts from zero, so 2 represents the third address.
Use Faucet to get ether
Make sure your account has enough balance to deploy. Ether can be obtained on the Ropsten network through a service called Faucet. Although there are several Faucet sites there, one of the services we recommend is hosted on EthTools.
Navigate to the Ether Faucet of EthTools.
Enter your mnemonic and select how many ether you want (up to 5).
Faucet will link to your first account. Click "Request Ether" to submit the request.
Soon, your account will get the requested ether.
Note: you can also apply for ether through MetaMask. Connect to your account on Ropsten, and then click the "Buy" button, which will provide a link to MetaMask's Ropsten test Faucet, which works similar to the above.
We can now start deploying contracts to Ropsten!
Deployment contract
STEP 1: compile the project:
Truffle compile
STEP 2: deploy to the Ropsten network:
Truffle migrate-network ropsten
If all goes well, you should see output similar to the following:
Using network 'ropsten'. Running migration: 1_initial_migration.js Deploying Migrations... ... 0xd79bc3c5a7d338a7f85db9f86febbee738ebdec9494f49bda8f9f4c90b649db7 Migrations: 0x0c6c4fc8831755595eda4b5724a61ff989e2f8b9 Saving successful migration to network... ... 0xc37320561d0004dc149ea42d839375c3fc53752bae5776e4e7543ad16c1b06f0 Saving artifacts... Running migration: 2_deploy_contracts.js Deploying MyContract... ... 0x7efbb3e4f028aa8834d0078293e0db7ff8aff88e72f33960fc806a618a6ce4d3 MyContract: 0xda05d7bfa5b6af7feab7bd156e812b4e564ef2b1 Saving successful migration to network... ... 0x6257dd237eb8b120c8038b066e257baee03b9c447c3ba43f843d1856de1fe132 Saving artifacts...
It should be reminded that your trading ID will be different from the above.
Note: if you receive the error Error: Exceeds block gas limit, you may need to manually set the fuel limit (gas limit) for the contract. For more information, see the Truffle configuration documentation.
STEP 3: if you want to verify that the contract has been successfully deployed, you can check it in the Ropsten section of Etherscan. "in the search field, enter the deployment deal ID." In the above example, the transaction ID is:
0x7efbb3e4f028aa8834d0078293e0db7ff8aff88e72f33960fc806a618a6ce4d3
You should be able to see detailed information about the transaction, including the block number where the transaction is protected.
At this point, the study on "how to deploy the Ethernet Square intelligent contract to infura" is over. I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.