因为账户交易这一块内容比较多,分为两部分来讲,承上一篇我们继续关于以太坊账户交易的练习
普通交易
在以太坊链上有两种交易,1是普通交易,2是裸交易,它们有不同的定义,
其中普通交易由以太坊节点进行签名,而裸交易,不要想歪,只是由外部应用进行签名
/**
* 普通交易
* @param fromIndex 发送方
* @param toIndex 接收方
* @param price 金额(wei)
* @return
* @throws IOException
*/
public String normalTrade(Integer fromIndex, Integer toIndex, Long price) throws IOException {
List<String> accounts = web3j.ethAccounts().send().getAccounts();
String from = accounts.get(fromIndex);
String to = accounts.get(toIndex);
BigInteger tradeValue = BigInteger.valueOf(price);
// 设置gas费用
BigInteger gasPrice = Convert.toWei("20", Convert.Unit.GWEI).toBigInteger();
BigInteger gasLimit = BigInteger.valueOf(60000);
Transaction tx = new Transaction(from, null, gasPrice, gasLimit, to