java ethereum_java以太坊库web3j文档

通过以太坊ethereum客户端进行认证签名交易

为了通过以太坊客户端进行交易,首先需要确保你正在使用的客户端知道你的钱包地址。最好是运行自己的以太坊客户端,比如geth/Parity,以便可以更方便的做到这一点。一旦你有一个客户端运行,你可以创建一个以太坊钱包,通过:

geth Wiki包含了geth支持的良好运行的不同机制,例如导入私有密钥文件,并通过控制台创建新的以太坊帐户。

或者,你可以通过客户端使用JSON-RPC管理命令,例如用personal_newAccount为geth/Parity创建新以太坊账户。

通过创建你的钱包文件,你可以通过web3j打开帐户,首先创建支持geth/Parity管理命令的web3j实例:

Admin web3j = Admin.build(new HttpService());

然后,你可以解锁帐户,并如果是成功的,就可以发送一个交易:

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

if (personalUnlockAccount.accountUnlocked()) {

// send a transaction

}Transaction transaction = Transaction.createContractTransaction(

,

,

BigInteger.valueOf(), // we use default gas limit

"0x..."

);

org.web3j.protocol.core.methods.response.EthSendTransaction

transactionResponse = parity.ethSendTransaction(ethSendTransaction)

.send();

String transactionHash = transactionResponse.getTransactionHash();

// poll for transaction response via org.web3j.protocol.Web3j.ethGetTransactionReceipt()

其中nonce值获得方式,下文会提到。

有关此交易工作流的详细信息,请参阅DeployContractIT和Scenario。

web3j支持的各种管理命令的进一步细节在Management APIs中。

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值