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 use Solidity interface

2025-03-26 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

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

This article mainly explains "how to use Solidity interface". Friends who are interested might as well take a look. The method introduced in this paper is simple, fast and practical. Now let the editor take you to learn how to use Solidity interface.

Ethernet Network distinguishes between reading and writing data on the network. Writing data is called transaction and reading data is called call.

Use tools: remix IDE-browser-based scenario: two contracts are deployed at different addresses, and data interaction is called between each other.

The first contract: Doug.sol code is as follows:

Pragma solidity ^ 0.4.19 X contract Doug {mapping (bytes32 = > uint) public contracts; function Doug () {contracts ['hww'] = 1; contracts [' brian'] = 2; contracts ['zzy'] = 7;} function getDougName (string _ name) public view returns (string) {return _ name } function getDougAge (uint _ age) public pure returns (uint) {return 3 * * _ age;}}

The second contract myContract.sol code is as follows:

Pragma solidity ^ 0.4.19 X contract DogInterface {function getDougAge (uint _ age) returns (uint); function contracts (bytes32 name) returns (uint);} contract main {event FetchContract (address dogInterfaceAddress, address sender, bytes32 name); address DOUG; address dogInterfaceAddress = 0x3e6494333ae0e929ade0eb9a19fb02632b8e07cf; DogInterface dogContract = DogInterface (dogInterfaceAddress); function setDOUG (address _ doug) {DOUG = _ doug } function dougOfage (uint _ age) public view returns (uint) {uint num = dogContract.getDougAge (_ age); return _ age+num; / / return num;} function uintOfName (bytes32 _ name) returns (uint) {dogContract.contracts (_ name); FetchContract (dogInterfaceAddress, msg.sender, _ name) } / / function getTest (string _ name) public view returns (string) {/ / string memory newName = _ name; / / DogInterface (DOUG) .getDougName (newName); / / return newName; / /}}

Execution result:

At this point, I believe you have a deeper understanding of "how to use Solidity interface". You might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!

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