In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/01 Report--
The main content of this article is to explain "what is the Java development method of Web3j 4.x mobile wallet". Interested friends may wish to have a look. The method introduced in this paper is simple, fast and practical. Now let the editor take you to learn "what is the Java development method of Web3j 4.x mobile wallet?"
1. Project configuration
The first step in using Web3j is to add Web3j dependencies to the Android project. Since Web3j has a maven plug-in, it's simple: just add mavencentral to your project's build.gradle file, and then add web3j as a dependency to the build.gradle file (make sure you're using the android version).
Repositories {mavenCentral () google () jcenter ()} dependencies {implementation fileTree (dir: 'libs' Include: ['* .jar']) implementation 'com.android.support:appcompat-v7:28.0.0' implementation' com.android.support.constraint:constraint-layout:1.1.3' testImplementation 'junit:junit:4.12' androidTestImplementation' com.android.support.test:runner:1.0.2' androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2' implementation' org.web3j:core:4.1.0-android'}
To learn web3j systematically and efficiently, we recommend Huizhi's online interactive tutorial "detailed introduction to web3j ethernet development", which covers the core concepts of ethernet, such as account management, status and trading, intelligent contract development and interaction, filters and events, etc., as well as detailed instructions on how to use web3j to interact with ethernet block chain, which is the best choice for java engineers to learn ethernet application development.
2. Decide the type of node to use
The wallet application must communicate with the etherfang block chain through an ethersquare node. We can deploy our own nodes or use cloud nodes provided by third parties, such as Infura's open nodes. The reason I decided to use Infura is that I don't need to synchronize the blockchain data myself, because the synchronization process is time-consuming and tedious, so I want to avoid setting up my own nodes as much as possible.
You can register with Infura and get an API Key, and you can create a Web3j object to connect to the Rinkeby test network as follows:
/ / FIXME: Add your own API key hereweb3 = Web3j.build (new HttpService ("https://rinkeby.infura.io/v3/YOURKEY"));try {Web3ClientVersion clientVersion = web3.web3ClientVersion (). SendAsync (). Get (); if (! clientVersion.hasError ()) {/ / Connected} else {/ / Show Error}} catch (Exception e) {/ / Show Error}
Note that the URL in the above code-https://rinkeby.infura.io/v3/YOURKEY MagneYOURKEY needs to be replaced with your API KEY. The rinkeby in this url means that you can use this url to access the rinkeby test chain of Ethernet Square. It is easy to understand. Replace rinkeby with mainnet, and you can access the main network of Ethernet Square, for example:
Https://mainnet.infura.io/v3/YOURKEY
If everything is all right, the above code can be connected to the Rinkeby test chain of Ethernet Square!
3. Create a wallet
Now let's create a wallet to send or receive some test chain Ethernet coins. To do this, we need to first create a wallet file on the user's device:
/ / FIXME: Use your own password hereprivate final String password = "medium"; private String walletPath = getFilesDir (). GetAbsolutePath (); private File walletDir = new File (walletPath); try {WalletUtils.generateNewWalletFile (password, walletDir);} catch (Exception e) {/ / Display an Error} 4, get the address and load the wallet
Well, now that we have a wallet, let's get the wallet address and get some test Ethernet coins for that address from Rinkeby Faucet:
Try {Credentials credentials = WalletUtils.loadCredentials (password, walletDir); Toast.makeText (this, "Your address is" + credentials.getAddress (), Toast.LENGTH_LONG). Show ();} catch (Exception e) {/ / Show Error} 5, send transaction
Now that we have some etheric coins in our wallet, let's turn these test coins back:
Try {Credentials credentials = WalletUtils.loadCredentials (password, walletDir); TransactionReceipt receipt = Transfer.sendFunds (web3,credentials, "0x31B98D14007bDEe637298086988A0bBd31184523", new BigDecimal (1), Convert.Unit.ETHER). SendAsync (). Get (); Toast.makeText (this, "Transaction complete:" + receipt.getTransactionHash (), Toast.LENGTH_LONG). Show () } catch (Exception e) {/ / Show Error} here, I believe you have a deeper understanding of "what is the Java development method of Web3j 4.x mobile wallet". 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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.