This blog will guide you on how to create an ethereum wallet in the ethereum network, and how to create it using spring boot.
In this blog, we have explained how to create an ethereum wallet using spring boot. To build an ether wallet, we will need a blockchain network URL in some testnet network, which may be either ropsten or rinkedby. Also, you can configure your local machine for the ether test network.
We will use the web3j library to connect with the Ethereum network and perform operations on the blockchain.
@Entity public class UserWallet extends BaseEntity{ @Id @GeneratedValue(strategy = GenerationType.AUTO) private Long id; private Long userId; @Column(nullable = false,columnDefinition ="mediumtext") private String address; @Column(columnDefinition ="mediumtext") private String fileName; @Column(columnDefinition="mediumtext") private String password; @Column(columnDefinition="mediumtext") private String passwordKey; @DecimalMin("0") @Column(precision = 20, scale = 8) private BigDecimal balance; @Enumerated(EnumType.STRING) private CoinType coinType; public UserWallet() { }
Getters and setters are omitted for better readability.
@Configuration public class EthereumConnectionConfig { private static Logger LOGGER = LoggerFactory.getLogger(EthereumConnectionConfig.class); @Value("${ethereum.service.url}") private String url; @Bean Web3j getEthereumCononnection() throws IOException { String serverIp = url; LOGGER.info("Ethereum sync serverIp : " + serverIp); Web3j web3 = Web3j.build(new HttpService(serverIp)); LOGGER.info("connected to ethereum server 123" + web3); Web3ClientVersion web3ClientVersion = web3.web3ClientVersion().send(); String clientVersion = web3ClientVersion.getWeb3ClientVersion(); LOGGER.info("Ethereum client version" + clientVersion); return web3; } }
@RestController public class UserWalletController { private static final Logger logger = LoggerFactory.getLogger(EthereumListener.class); @Autowired private WalletService walletService; @PostMapping(CREATE_WALLET) public ResponseEntity<Object> setUsersWallet() { return ResponseHandler.response(walletService.createEtherWallet(), LocaleService.toLocale("wallet.created")); } }
public Map<String, Object> createEtherWallet() { Map<String, Object> map = new HashMap<>(); map = createCredentials(); Object jsonFile = map.get("jsonFile"); Credentials credentials = (Credentials) map.get("credentials"); String passwordKey = (String) map.get("passwordKey"); String encPwd = (String) map.get("encPwd"); UserWallet userWallet = new UserWallet(userId, credentials.getAddress(), jsonFile.toString(), encPwd, passwordKey, ETHEREUM); userWalletRepository.save(userWallet); result.put("address", credentials.getAddress()); } return result; } private Map<String, Object> createCredentials() { Map<String, Object> map = new HashMap<>(); try { File file = new File(ethWalletLocation); String fileName; String password = UUID.randomUUID().toString().replaceAll("-", ""); fileName = WalletUtils.generateFullNewWalletFile(password, file); logger.info("wallet file name {} ", fileName); String passwordKey = CryptoUtil.getSecretKey(); logger.debug("wallet file passwordKey: {}", passwordKey); String encPwd = CryptoUtil.encrypt(password, passwordKey); logger.debug("wallet file encPwd: {}", encPwd); File jsonFile = new File(file + File.separator + fileName); logger.debug("wallet file jsonFile: {}", jsonFile.toString()); Credentials credentials = WalletUtils.loadCredentials(password, jsonFile); logger.debug("wallet address: {}", credentials.getAddress()); map.put("jsonFile", jsonFile); map.put("credentials", credentials); map.put("encPwd", encPwd); map.put("passwordKey", passwordKey); } catch (IOException | NoSuchAlgorithmException | NoSuchProviderException | InvalidAlgorithmParameterException | CipherException | InvalidKeyException | NoSuchPaddingException | IllegalBlockSizeException | BadPaddingException e) { e.printStackTrace(); } return map; }
Now, we have successfully created a user's wallet on the Ethereum's test network. You can verify your address in etherscan.io by giving your address.
Also Read Enterprise Ethereum: A Platform for Private Blockchain Solutions
Trending
Must-Read
Satoshi Nakamoto's Last Email Reveals Bitcoin Creator's...
How to Build a DAO | A Quick...
Redefining The Gaming Industry with Play-to-Own...
What Makes Solana Blockchain Development Stand...
Why Develop an Over-The-Counter (OTC) Crypto Trading...
NFT Loyalty Program: The Ultimate Guide for...
Exploring Crypto Arbitrage Trading Bot and...
A Quick Guide to Understanding Semi-Fungible...
Developing a Ride-Sharing App like Uber with...
Developing a Food Delivery App like UberEats with...
How useful was this post?
Click on a star to rate it!
No votes so far! Be the first to rate this post.
Name is required
Invalid Name
Please Enter a valid E-mail address
Email is required
Comment is required
Recaptcha is required.
Δ
No Comments Yet.
More From Oodles
Saudi Arabia is Ready to Embrace Web3 and Gaming
Saudi Arabia launched Vision 2030, an initiative to diversify its economy. This...
Vitalik Buterin Co-authors Paper Introducing Privacy Pools
In a noteworthy collaboration, Ethereum founder Vitalik Buterin recently teamed...
DeFi Auditing and Security Best Practices
Decentralized Finance (DeFi) has disrupted traditional financial systems by...
DeFi Asset Tokenization | A Beginner's Guide
In the ever-evolving landscape of decentralized finance (DeFi), asset...
Enter a valid Name
Enter a valid Email address
By using this site, you allow our use of cookies. For more information on the cookies we use and how to delete or block them, please read our cookie notice.
Oodles Blockchain
Blockchain Development Company | Innovate with Confidence
✕
Please enter a valid Name
Please enter a valid Phone Number
Please enter a valid Email address
Please remove URL from text