Contract Called
- The contract calls in three ways
IPC方式
- Usually by way of the console
- Ethernet nodes After running, you can open a console
- In the console inside it by means of input commands can be retrieved some of the smart contract method
- IPC may also be the way the pipe communication
- A call between the main way process
HTTP的方式
- This is more common in some way
- Usually do JSON format data serialization and deserialization
- That is the way of HTTP JSON RPC
websocket的方式
- Square supports the use of internal Ethernet protocol websocket directly interfaces to the internal nodes of some contracts call
- In these three ways, if we are to adjust the latter two by the client, HTTP JSON RPC of the way and manner websocket
- And more IPC first way is to do some debugging in the machine access node, a pipeline of communication between processes
RPC / IPC calls
![](http://raw.githubusercontent.com/Every-Chain/b-c-learning-material/master/contents/screenshot/28.jpg)
- Go language versions of the above is a full-node Ethernet Square
- A version of the highest priority of a node is also the official maintenance of Ethernet Square called geth, that is, eth node Go language
- After it runs, you can command $
geth console
, so bring a sub-command, after so run full node, will enter into a console, the console will be able to enter into - In the console which it will print some information associated with the connection, here we can see that it has
IPC endpoint
, that is a connection address of IPC - This is used to run the MAC system, which is in the
/Users/mac/Library/Ethereum/geth.ipc
generation of such a file a default locationgeth.ipc
- The IPC communication connection is to connect through a shared document that
- You can also open another console just to point to the file can ipc
- The other is the HTTP link address, we are locally, so it is 127.0.0.1, port number 8545
- After entering the console node can be a lot of commands to access the ether
- Console type exit to exit
Common RPC Invocation Framework
- For an Ethernet node is concerned, it is an internal support RPC server node
- For the client is concerned, at present has supported many languages versions, such as support for language versions of Javascript called web3.js, this version is the most commonly used version
- In addition, there are Java-oriented language web3j
- For C # Nethereum
- Ruby language support ethereum-ruby
- With the development and may also support other language versions go
- Of course, you can own to encapsulate, this may be because the RPC supports Ethernet interfaces are open source, we can come to do their own packages as needed
Library | Language | Project Page |
---|---|---|
web3.js | JavaScript | https://github.com/ethereum/web3.js |
web3j | Java | https://github.com/web3j/web3j |
Nethereum | C# .NET | https://github.com/Nethereum/Nethereum |
ethereum-ruby | Ruby | https://github.com/DigixGlobal/ethereum-ruby |
About web3 objects
- web3.js objects
- Ethernet Square JavaScript API
- This can be seen in web3 github repository, https://github.com/ethereum/web3.js/tree/1.x/packages this directory
- That contains a set of library calls have been packaged client, it is Js Ethernet version of the SDK Square
- Once imported, there is a class called Web3, call the library at the top of each sub web3 this library to implement a package so you can view network example Officer
- Ordinary JSON RPC
- Parameters and return values are serialized by json and deserialization
- Need to meet the Ethernet nodes Square
- Main network node can be formal, but also to test the deployment of private or simulated node
- Ethernet Square JavaScript API
- Call test code web3 object
var Web3 = require('web3'); if(typeof web3 !== 'undefined') { web3 = new Web3(web3.currentProvider); } else { // set the provider you want from Web3.providers web3 = new Web3(new Web3.providers.HttpProvider("http://localhost:8545")); } var Version = web3.version; console.log("client version: " + version);
Based Nodejs example
var Web3 = require('web3');
if(typeof web3 !== 'undefined') {
web3 = new Web3(web3.currentProvider);
} else {
// set the provider you want from Web3.providers
web3 = new Web3(new Web3.providers.HttpProvider("http://localhost:8545"));
}
web3.eth.getAccounts(console.log);
10 outputs the generated address
null [
'0x437615686191efF890C7cCa136cfbf21Cb6451E6',
'0xe4a56746DAfDf247BF125d5809B2D6168722Eb37',
'0x23604b6563d63D5f3b4C9a09ADe681F5f2811DB6',
'0x4900AEeA7CC7F76E473805c50E8F0e49c1F99D8E',
'0x1A32509bC3DAA2AC5493AE212064e59ebeaED34c',
'0x7c0c971814dBA35D5c53E5650b71E91ecb8C31fa',
'0x2DB7594e84DC79EE782f3962C1ea9cC2912c3EF1',
'0x9D86096d38B4460Be319dA56265499D863ccB5c4',
'0xD03cbC188201EB3AB61aC465Dc1e3A2fa517245C',
'0x77238F0407aF96Fd26Fe22A9996B2349F1ebb91f'
]