How to use web3.js to invoke an Ethernet Square contract
In this issue, the editor will bring you about how to use web3.js to call the Ethernet Square contract. The article is rich in content and analyzes and narrates it from a professional point of view. I hope you can get something after reading this article.
Environment
Solidity 0.5.0
Ubuntu16.04
First, how to import web3j
There are many ways to introduce it, and so far I've been exposed to it.
1. Introduce the local web3j document or https://cdn.jsdelivr.net/gh/ethereum/web3.js/dist/web3.min.js into the script in the html file.
2. Use require ('web3') in the js file to introduce the web3 installed under the current path.
II.
If metamask is already installed in chrome, the current currentProvider is probably the default metamask.
When using the pits encountered in metamask, be sure to put security & privacy in the settings. Turn it off before you can operate. Otherwise, the calling account of the contract cannot be found when performing an operation that requires a call fee gas.
Third, how to locate the contract
Need contract address contractAddress, contract ABI,contractAbi
Var contract = web3.eth.contract (contractAbi) var address = contractaddress
4. Call the contract method with no parameters and return value
Contract.method (function (error, result) {if (! error) {console.log (result)}})
5. Call the contract method with or without parameters
Contract.setInfo (par1, par2, function (error, result) {if (! error) {console.log ("set ok");}}) the above is how to use web3.js to call Ethernet Square contract. If you happen to have similar doubts, please refer to the above analysis to understand. If you want to know more about it, you are welcome to follow the industry information channel.