Get the App
SLTechnology News&Howtos  ›  Internet Technology  › 

How to use Solidity interface

Shulou Source: shulou.com Published: 2022-06-01 16:51:02 10月06日 Update

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!

Tags: Data contracts code content web learning different practical deeper two interests addresses scenarios practicality practical tools easy to operate methods more friends Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Redmi Apple Shulou Information NVidia macOS