# springboot-btc-eth-trx
**Repository Path**: pplus_open_source/springboot-btc-eth-trx
## Basic Information
- **Project Name**: springboot-btc-eth-trx
- **Description**: 微服务架构springboot+web3j实现区块链(BTC链,ETH链,币安链,波场链)操作(生成地址,转账,扫块)等功能。开箱即用,例子完善
- **Primary Language**: Java
- **License**: Apache-2.0
- **Default Branch**: master
- **Homepage**: None
- **GVP Project**: No
## Statistics
- **Stars**: 0
- **Forks**: 107
- **Created**: 2024-06-25
- **Last Updated**: 2024-06-25
## Categories & Tags
**Categories**: Uncategorized
**Tags**: None
## README
# 重要提示:
_本项目只用作学习,不做任何投资建议,一切风险自行承担,敬请广大开发者注意_
#### 介绍
使用springboot+web3j方式进行对ETH链,BTC链,币安链,波场链等热门区块链进行链上开发,开箱即可用,大大缩小了入门门槛。
如有帮助请记得 **点击右上角star** 。
```
1.项目才刚刚开始,后面还有很多丰富的功能
2.请关注我们了解后续的情况(不定期更新)
```
## 区块链项目推荐:
**1.Brc20铭文管理系统:**
http://insc.wechatqun.cn:8088
**2.区块链数字货币交易所:**
PC端: http://coin-pc.mj.ink 账号:coinexpro@gmail.com 密码:123456qq 验证码:123456
后台端: http://coin-ht.mj.ink 账号:test 密码:123456
H5端: http://coin-h5.mj.ink 账号:coinexpro@gmail.com 密码:123456qq 验证码:123456
# 1.数字货币合约交易所
**介绍:** 基于Spring Cloud Alibaba的比特币币交易所,比特币交易所 | BTC交易所 | ETH交易所 | 区块链 | 本项目有后台管理(后端+前端)、前台(交易、活动、个人中心等)、安卓APP源码等,项目有实时在线体验链接,即刻体验!
**项目地址:** https://github.com/CoinExPro/CoinExchange
# 2.BRC20铭文诊断系统 **全开源**
1. 亲,动动您发财的手为我们点一颗star,是对我们最好的鼓励和支持,也是我们前进的动力
2. 演示环境:http://insc.wechatqun.cn:8088
3. 项目地址:https://gitee.com/Linriqiang/springboot-insc
## 项目关系
| 项目 | Star | 简介 |
|-----------------------------------------------------------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|-----------------------------|
| [数字货币交易所](https://github.com/CoinExPro/CoinExchange) | [](https://github.com/CoinExPro/CoinExchange) | 基于 Spring Cloud 微服务架构 |
| [铭文诊断管理系统](https://gitee.com/Linriqiang/springboot-insc) | [](https://gitee.com/Linriqiang/springboot-insc) | 对Brc20 Ordinals的铭文数据进行了诊断分析 |
## 部分代码
**1.创建钱包**
```
public String createAddress() {
try {
String ethKeystorePath = BlockChainProperties.getErc20_keystore_path();
String password = Func.randomUUID();
String filename = WalletUtils.generateNewWalletFile(password, new File(ethKeystorePath), true);
String fileUrl = ethKeystorePath + filename;
Credentials credentials = WalletUtils.loadCredentials(password, new File(fileUrl));
String address = credentials.getAddress();//地址
String privateKey = credentials.getEcKeyPair().getPrivateKey().toString(16);//私钥
Bip39Wallet wallet = WalletUtils.generateBip39Wallet(password, new File(ethKeystorePath));
String filename2 = wallet.getFilename();
String fileUrl2 = ethKeystorePath + filename2;
Credentials credentials2 = WalletUtils.loadCredentials(password, new File(fileUrl2));
String address2 = credentials2.getAddress();//地址
String mnemonic = wallet.getMnemonic();//这里是助记词
System.out.println("mnemonic============" + mnemonic);
System.out.println("address2========" + address2);
System.out.println(JsonUtil.toJson(credentials));
return address;
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
```
**2.导入助记词生成地址**
```
public boolean importAddressByMnemonic(String mnemonic) {
String ETH_TYPE = "m/44'/60'/0'/0/0";
try {
List list = Func.toStrList(" ", mnemonic);
String password = IdWorker.getIdStr();
String passphrase = "";
long creationTimeSeconds = System.currentTimeMillis() / 1000;
DeterministicSeed ds = new DeterministicSeed(list, null, passphrase, creationTimeSeconds);
String[] pathArray = ETH_TYPE.split("/");
//根私钥
byte[] seedBytes = ds.getSeedBytes();
DeterministicKey dkKey = HDKeyDerivation.createMasterPrivateKey(seedBytes);
for (int i = 1; i < pathArray.length; i++) {
ChildNumber childNumber;
if (pathArray[i].endsWith("'")) {
int number = Integer.parseInt(pathArray[i].substring(0, pathArray[i].length() - 1));
childNumber = new ChildNumber(number, true);
} else {
int number = Integer.parseInt(pathArray[i]);
childNumber = new ChildNumber(number, false);
}
dkKey = HDKeyDerivation.deriveChildKey(dkKey, childNumber);
}
ECKeyPair keyPair = ECKeyPair.create(dkKey.getPrivKeyBytes());
WalletFile walletFile = Wallet.createLight(password, keyPair);
System.out.println("地址:" + "0x" + walletFile.getAddress());
System.out.println("私钥:" + keyPair.getPrivateKey().toString(16));
;
} catch (Exception e) {
e.printStackTrace();
return false;
}
return true;
}
```
**3.获取代币余额**
```
public String getTokenBalance(String fromAddress, String contractAddress) {
String methodName = "balanceOf";
List inputParameters = new ArrayList<>();
List> outputParameters = new ArrayList<>();
Address address = new Address(fromAddress);
inputParameters.add(address);
TypeReference typeReference = new TypeReference() {
};
outputParameters.add(typeReference);
Function function = new Function(methodName, inputParameters, outputParameters);
String data = FunctionEncoder.encode(function);
Transaction transaction = Transaction.createEthCallTransaction(fromAddress, contractAddress, data);
EthCall ethCall;
BigInteger balanceValue = BigInteger.ZERO;
try {
ethCall = this.getWeb3j().ethCall(transaction, DefaultBlockParameterName.LATEST).send();
List results = FunctionReturnDecoder.decode(ethCall.getValue(), function.getOutputParameters());
balanceValue = (BigInteger) results.get(0).getValue();
} catch (Exception e) {
e.printStackTrace();
}
return balanceValue.toString();
}
```
## 添加小编,+区块链技术交流群: