Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to parse the intelligent contract of web3.js call

2025-02-23 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/01 Report--

How to analyze the web3.js call intelligent contract, many novices are not very clear about this, in order to help you solve this problem, the following editor will explain for you in detail, people with this need can come to learn, I hope you can gain something.

The editor will use web3.js to follow a simple process of calling intelligent contracts.

1 using truffleinit command to generate intelligent contract framework

Code reference. The simple modifications to the automatically generated framework are as follows:

Contracts\ Migrations0.solpragma solidity ^ 0.4.23 position contract Migrations0 {/ / write a function to complete the addition operation function aAndb (uint a dint b) public constant returns (uint) {return astatb;}} migrations\ 1_initial_migration0.jsvar Migrations = artifacts.require (". / Migrations0.sol"); module.exports = function (deployer) {deployer.deploy (Migrations);}; 2 compilation

Compile it on truffle develop

Generate the json file in the. / build/contracts file

Where:

"abi": [{"constant": true, "inputs": [{"name": "a", "type": "uint256"}, {"name": "b", "type": "uint256"}], "name": "aAndb" "outputs": [{"name": "," type ":" uint256 "}]," payable ": false," stateMutability ":" view "," type ":" function "}]

Compressed abi:

[{"constant": true, "inputs": [{"name": "a", "type": "uint256"}, {"name": "b", "type": "uint256"}], "name": "aAndb", "outputs": [{"name": "type": "uint256"}], "payable": false, "stateMutability": "view", "type": "function"}] 3 deployment

Contract address of Migrations0: 0x345ca3e014aaf5dca488057592ee47305d9b3e10

4 call

Web3.eth.contract:

Web3.eth.contract (abiArray)

Create a contract object for Solidity to initialize the contract at an address.

Parameters:

Array-one or more functions that describe contracts, ABI objects for events.

Return value:

Object-A contract object.

Is it helpful for you to read the above content? If you want to know more about the relevant knowledge or read more related articles, please follow the industry information channel, thank you for your support.

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.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report