8845
It is probably a huge reflex arc. The concept of blockchain has been popular for so long, and I have only recently started to learn blockchain-related technologies. I finished learning the basic concepts and was recommended by a friend. 宇宙第一链:Ethereum. After studying over the weekend, I finally completed the first goal: the first transfer. Share the learning process and results for reference only. The knowledge involved in the article comes from official documents, and the address can be searched by yourself. The documentation is available in Chinese, but the code practice part is mostly in English. It is recommended that beginners also read the conceptual documents and do not start coding directly. test chainFirst, we need to build a test chain locally, just like for HTTP interface testing, we need a local test server. Here’s an official reminder from this post: 您应该先理解以太坊堆栈和以太坊网络基础知识才能进入开发网络。Among the official development tools, I chose Ganache, nothing else, because it ranks first. Test chains can be deployed and smart contracts can be deployed, which fully meets my needs. Install the same software as other software, and then start the interface: ![]() For newbies, choose QUICKSTARTThat's it, you can see the main page. I won’t take up space by putting pictures here. After successful startup, you will get the IP and port of a local service. This is what is in the code. hostvalue. Query on how to obtain the mainnet hostI suggest that beginners skip this part first. There is no need to build one locally.Ethereumclient.Create Java projectSince I am used to using Java, I will start with Java. Of course, I will try to use Groovy to implement it later when I become proficient. Later, I plan to write it again in Golang, so I won’t go into details here. I used Java dependency Web3j, as far as I have seen there is a lot of informationjsonrpcThe implementation is essentially an HTTP request. I was thinking of using it FunTesterFramework implementation. But the current scenario does not allow me, a blockchain novice, to do this. Dependency configuration: <dependency>Then you need a class and mainmethod, nothing else.Verify DemoWhen the preparations are ready, we write some code to call EthereumAPI to verify whether the local test chain is valid.import com.funtester.frame.SourceCode; When the console outputs the format information, it means that the environment setup work has been completed. ~☢~~☢~~☢~~☢~~☢~~☢~~☢~~☢~~☢~~☢~ JSON ~☢~~☢~~☢~~☢~~☢~~☢~~☢~~☢~~☢~~☢~transferEthereumThere are many APIs,Web3jThere are corresponding implementation methods. Although the documentation and test chain are not complete, as far as I am currently using it, I have learned enough and have not encountered any missing functions.Account transfer is a very important API, and it is more troublesome than other query APIs because it involves signature encryption. PS: There is documentation GanacheAllows transfers without signatures. I have not tried this. After all, I will be surfing the mainnet in the future.The following is a demo of the transfer. The keys are all test accounts on the test chain. You can pass GanacheObtained from the small key button on the page.package com.funtester.ethereum;The subsequent loop waiting for the response is not elegant enough. Once you become proficient, you can encapsulate a convenient method. console output deal confirmIf so, it means the transfer has been confirmed. can go GanacheMake sure the balance is correct. Of course you can pass EthereumAPI to query whether the changes in the balance of the corresponding account are consistent with expectations.![]() ![]() A young man's first EthereumThe transfer has been completed.FunTester original topic recommendation~ |