Gitee开源排行第一之springboot+web3j实现区块链(生成地址,转账,扫块)等功能


微服务架构springboot+web3j实现区块链(BTC链,ETH链,币安链,波场链)操作(生成地址,转账,扫块)等功能。开箱即用,例子完善

开源地址:https://gitee.com/Linriqiang/springboot-btc-eth-trx

动动您发财的手为我们点一颗star,是对我们最好的鼓励和支持,也是我们前进的动力

1.项目才刚刚开始,后面还有很多丰富的功能
2.请关注我们了解后续的情况(不定期更新)

重要提示:
本项目只用作学习,不做任何投资建议,一切风险自行承担,敬请广大开发者注意
以下是部门部分代码展示

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<String> 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<Type> inputParameters = new ArrayList<>();
		List<TypeReference<?>> outputParameters = new ArrayList<>();
		Address address = new Address(fromAddress);
		inputParameters.add(address);

		TypeReference<Uint256> typeReference = new TypeReference<Uint256>() {
		};
		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<Type> results = FunctionReturnDecoder.decode(ethCall.getValue(), function.getOutputParameters());
			balanceValue = (BigInteger) results.get(0).getValue();
		} catch (Exception e) {
			e.printStackTrace();
		}
		return balanceValue.toString();
	}

总结:开源不易,希望能得到你一个小小的star
Gitee: springboot-btc-eth-trx: 微服务架构springboot+web3j实现区块链(BTC链,ETH链,币安链,波场链)操作(生成地址,转账,扫块)等功能。开箱即用,例子完善

  • 3
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
作为一个AI模型,人脸识别涉及到多个技术领域。在此我们以常规的人脸识别为基础,实现一个简单的基于springboot/vue/mybatis的人脸识别系统。 1、人脸检测和人脸识别的技术选择 我们可以使用开放的Python的人脸识别库(face_recognition),通过Python调用,实现人脸检测和人脸识别。Face_recognition 是使用Dlib进行基于Python的人脸识别的开源项目,仅仅需要几行代码就可以完成一项任务,包括人脸识别,面部比较和面部定位等。 2、技术实现步骤 2.1、环境搭建 开发工具:IntelliJ IDEA 数据库:MySQL 前端技术:Vue.js 后端技术:Spring Boot + MyBatis + Face Recognition Library 2.2、集成Face Recognition Library 通过Python安装Face Recognition Library(face_recognition)库,直接使用Python的Pip命令安装 pip install face_recognition 2.3、指定图片目录 在项目中指定图片目录,将其用于人脸检测和识别,默认将图片存储在本项目路径下的img文件夹中。 2.4、前端设计 使用Vue.js实现前端设计,支持以下功能: - 显示识别结果和置信度 - 支持上传图片,实现人脸识别 - 支持查询人脸信息 2.5、后端设计 使用Spring Boot和MyBatis实现后端功能,包括人脸检测和识别,以及查询人脸信息。 使用Spring Boot实现RESTful API,以处理前端请求和响应。 在MyBatis Mapper文件中定义SQL语句,用于从数据库中检索人脸信息。 2.6、上传图片实现人脸识别 实现上传图片实现人脸识别功能,主要包括以下步骤: - 通过上传功能获取上传图片,并且存储到指定目录下 - 对于新上传的照片进行人脸检测和识别 - 将人脸特征存储到数据库中,用于后续识别和查询 3、总结 我们可以通过Spring Boot和Vue.js对Face Recognition Library(face_recognition)进行集成,实现一个基于人脸识别的系统。同时,我们也应该意识到,在实现基于人脸识别的系统时,我们需要保持对隐私和数据保护的高度警惕性,避免出现不必要的隐私泄露情况。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值