java web3j交易查询_java以太坊库web3j文档

交易

Web3j支持使用以太坊钱包文件(推荐的)和用于发送事务的以太坊客户端管理命令。

使用以太钱包文件发送以太币给其他人:

Web3j web3 = Web3j.build(new HttpService()); // defaults to http://localhost:8545/

Credentials credentials = WalletUtils.loadCredentials("password", "/path/to/walletfile");

TransactionReceipt transactionReceipt = Transfer.sendFunds(

web3, credentials, "0x

|",

BigDecimal.valueOf(1.0), Convert.Unit.ETHER)

.send();

或者你希望建立你自己定制的交易:

Web3j web3 = Web3j.build(new HttpService()); // defaults to http://localhost:8545/

Credentials credentials = WalletUtils.loadCredentials("password", "/path/to/walletfile");

// get the next available nonce

EthGetTransactionCount ethGetTransactionCount = web3j.ethGetTransactionCount(

address, DefaultBlockParameterName.LATEST).send();

BigInteger nonce = ethGetTransactionCount.getTransactionCount();

// create our transaction

RawTransaction rawTransaction = RawTransaction.createEtherTransaction(

nonce, , , , );

// sign & send our transaction

byte[] signedMessage = TransactionEncoder.signMessage(rawTransaction, credentials);

String hexValue = Numeric.toHexString(signedMessage);

EthSendTransaction ethSendTransaction = web3j.ethSendRawTransaction(hexValue).send();

// ...

使用Web3j的Transfer进行以太币交易要简单得多。

使用以太坊客户端的管理命令(如果你的钱包密钥已经在客户端存储):

Admin web3j = Admin.build(new HttpService()); // defaults to http://localhost:8545/

PersonalUnlockAccount personalUnlockAccount = web3j.personalUnlockAccount("0x000...", "a password").sendAsync().get();

if (personalUnlockAccount.accountUnlocked()) {

// send a transaction

}

如果你想使用 Parity’s Personal 或者 Trace 功能, 或者 Geth’s Personal 客户端 APIs,可以使用org.web3j:parity和org.web3j:geth模块。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值