区块链Web3j编程: 账户交易(普通交易,裸交易)

因为账户交易这一块内容比较多,分为两部分来讲,承上一篇我们继续关于以太坊账户交易的练习

普通交易

在以太坊链上有两种交易,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
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值