从广义上讲,有web3j支持三种类型的以太坊交易:
Broadly speaking, xff0c; web3j supports three types of xff1a transactions;
- 1.以太币从一方交易到另一方
- 2.创建一个智能合约
- 3.与智能合约交易
为了进行这些交易,必须有以太币(以太坊区块链的代币)存在于交易发生的以太坊账户中。这是为了支付gas成本,这是为支付参与交易的以太坊客户端的交易执行成本,支付了这个成本就能将结果提交到以太坊区块链上。获得以太币的说明下文会说到。
In order to make these transactions xff0c; there must be an Ether currency (in a token of the #xff0c chain) in which the transaction took place. This is to pay gasgas< #xfff0c; this is the cost of implementing the transaction on the #xff0c end of the thongs involved in the transaction ; this cost is paid to submit the results to the Ethio chain.
此外,我们还可以查询智能合约的状态。
xff0c; we can also check the status of the smart contract.
如何获得以太币Ether
要想获得以太币Ether你有两种途径可以选择:
There are two ways you can choose xff1a if you want to get to Ether in TT;
- 1.自己开采挖矿
- 2.从别人那里获取以太币
在私有链中自己挖矿,或者公共测试链()是非常简单直接的。但是,在主要的公有链()中,它需要很多很明显的专用GPU时间,除非你已经拥有多个专用GPU的矿机,否则基本上不太可行。如果你希望使用私有链,则在这个官方文档中有一些指导。
Self-mining in private chains xff0c; or public testing chains () is very simple and straightforward. But xff0c; in the main public chain () xff0c; it takes a lot of distinctly dedicated GPU time xff0c; unless you already have several dedicated GPU mine machines xff0c; it is hardly feasible. If you want to use private chains xff0c; there is some guidance in this official document .
要购买以太币Ether,你需要通过交易所。由于不同的地区有不同的交易所,你还需要研究自己去哪儿合适。官方文档中包含多个交易所,是一个很好的参考。
针对Ethereum以太坊有许多专用测试网络或者叫测试链,他们由各种客户端支持。 There are many dedicated testing networks for Etherum or the Test Chain #xff0c; they are supported by a variety of clients. 对于开发,建议你使用或测试链。这是因为他们使用的工作量证明共识机制,确保交易和块能够一致并及时的创建。测试链,虽然最接近公有链(),但是因为它使用的工作量证明是共识机制,过去已受到攻击,对以太坊开发人员来说往往有更多的问题。 For the development of xff0c; it is recommended that you use or test the chain. This is because they use workload proofs of consensus mechanisms xff0c; ensure that transactions and blocks are created in a consistent and timely manner. Test chains xff0c; although it is closest to the public chain () xff0c; but because it uses workloads that prove to be consensus mechanisms xff0c; have been attacked in the past xff0c; and there are often more problems for the user community developers. 你可以通过测试链的请求以太坊币,具体怎么做可以看这里https://www.rinkeby.io/。 You can use #xff0c as a test chain request; see https://www.rinkeby.io/. 有关如何请求测试链的细节可以在这里找到。 Details of how to request the test chain can be found here at . 如果你需要在上的得到一些以太币,将你的钱包地址的消息发布到web3j gitter channel,然后会发送一些给你。 If you need to get some e-notes xff0c; send information about your wallet address to web3j giftchannel #xff0c; then send some to you. 在ethereum以太坊测试链中,挖掘难度低于公有链。这意味着你可以用普通的CPU,比如你的笔记本电脑来挖掘新的以太币。你需要做的是运行一个以太坊客户端,例如或,开始做一些储备。进一步的资料可在他们的官方网站上获得。 xff0c; digging is less difficult than public chains. This means that you can use common CPUxff0c; for example, your laptop to dig for new Ethers. What you need to do is run an Ether client xff0c; for example, xff0c; start making some reserves. Further information can be found on their official website. 一旦你开采了一些以太币,你就可以开始使用以太坊区块链了。 Once you've mined some Ethercopic #xff0c; you can start using the Etherton block chain. 然而,如上所述,使用或者测试网络更简单些。 However, xff0c; as noted above xff0c; use or test the network simpler. 当在Ethereum以太坊发生交易时,必须为执行该交易的客户端支付交易成本,将该交易的输出提交到以太坊区块链Ethereum blockchain。 When a transaction takes place in Etheeum, & #xff0c; the client performing the transaction must pay transaction costs & #xff0c; the output of the transaction is submitted to Etherium block chain Etherium blockchain. 此成本是通过gas来测量的,其中gas是用于在以太坊虚拟机中执行交易指令的数量。请参阅官方文档以获取更多信息。 This cost is measured by gas & #xff0c; of which gas is the number used to execute trade instructions in Ether's virtual machine. See for more information. 当你使用以太坊客户端时,这意味着,有两个参数用来指示你希望花费多少以太来完成传输: xff0c when you use an Etheraya client; this means xff0c; two parameters are used to show how much you want to spend on xff1a; 这两个参数共同决定了你愿意花费在交易成本上的最大量的以太币Ether。也就是说,你花费的gas不会超过。gas价格也会影响交易发生的速度,这取决于其他交易是否能为矿工提供更有利的gas价格。 Together, these two parameters determine the largest amount of ether that you would like to spend on transaction costs. That is, & #xff0c; you will not spend more on gas. Gas prices also affect the speed at which the transaction takes place & #xff0c; this depends on whether other transactions provide more favourable gas prices for miners. 你可能需要调整这些参数以确保交易能及时进行。 You may need to adjust these parameters to ensure that the transaction is conducted in a timely manner. 当你用一些以太币Ether创建了一个有效的帐户时,你可以使用两种机制来与以太坊进行交易。 #xff0c when you create a valid account with some Ethel; you can use two mechanisms to trade with Ether. 这两种机制都是Web3j所支持的。 Both mechanisms are supported by Web3j. 为了通过以太坊客户端进行交易,首先需要确保你正在使用的客户端知道你的钱包地址。最好是运行自己的以太坊客户端,比如/,以便可以更方便的做到这一点。一旦你有一个客户端运行,你可以创建一个以太坊钱包,通过: In order to trade xff0c through the Taiwan client; first of all to ensure that the client you are using knows your wallet address. It is best to run your own xff0c; e.g. xff0c; so that this can be done more easily. Once you have a client running xff0c; you can create a xff0c; via xff1a; 通过创建你的钱包文件,你可以通过web3j打开帐户,首先创建支持/管理命令的web3j实例: By creating your wallet file xff0c; you can open the account xff0c through web3j; first you create the web3j example xff1a that supports/managing the command; 然后,你可以解锁帐户,并如果是成功的,就可以发送一个交易: xff0c; you can unlock accounts xff0c; and if xff0c is successful; you can send a transaction xff1a; 以这种方式发送的交易应该通过EthSendTransaction创建,使用Transaction类型: Transactions sent in this way should be created by >EthSendTransalaction; using 以太坊测试链(testnets)
在testnet测试链或者私有链上挖掘
gas
交易机制
通过以太坊ethereum客户端进行认证签名交易
其中值获得方式,下文会提到。 有关此交易工作流的详细信息,请参阅 DeployContractIT和Scenario。
See , for more information on this trade stream, see .
web3j支持的各种管理命令的进一步细节在Management APIs中。
Further details of the various management orders supported by web3j are available at .
离线交易签名认证Offline transaction signing
如果你不想管理自己的以太坊客户端,或者不想向以太坊客户端提供诸如密码之类的钱包详细信息,那么就通过离线交易认证签名。
If you do not want to manage your Etherm client & #xff0c; or do not want to provide Ether's client with details of wallets such as passwords & #xff0c; then the signature is authenticated by offline transactions.
离线交易签名认证允许你在web3j中使用你的以太坊钱包签署交易,允许你完全控制你的私有凭据。然后,离线创建的交易可以被发送到网络上的任何以太坊客户端,只要它是一个有效的交易,它会将交易传播到其他节点。
The offline transaction signature certification allows you to sign the transaction xff0c using your taupulega wallet in Web3j; allows you to fully control your private credentials. Then xff0c; offline created transactions can be sent to any #xff0c user on the network; as long as it is a valid transaction xff0c; it spreads the transaction to other nodes.
如果需要,还可以执行进程外交易签名认证。这可以通过重写ECKeyPair的方法来实现。
This can be done by rewriting ECKeyPair.
创建和使用钱包文件Ethereum wallet file
为了离线脱机交易,你需要有你的钱包文件或与私密钱包/账户相关的公共和私人密钥。
To offline transactions xff0c; you need your wallet file or public and private keys associated with a private wallet/account.
web3j能够为你生成一个新的安全的以太坊钱包文件Ethereum wallet file,或者与也可以通过私钥来和现有的钱包文件一起工作。
Web3j can generate a new secure Etherium wallet file for you; or work with existing wallet files that can also be used through private keys.
创建新的钱包文件:
Create new wallet file:
加载凭据从钱包文件:
Loading of supporting documents from wallet file:
然后这些凭据会被用来签署交易,请参阅Web3安全存储定义钱包文件规范Web3 Secret Storage Definition
These papers will then be used to sign the transaction & #xff0c; see Web3 security storage definition wallet file instruction RawTransaction类型。类似于前面提到的类型,但是它不需要通过具体的账号地址来请求,因为可以从签名中推断出来。
For offline signature transactions to be signed xff0c; a type of RawTransaaction is required. Similar to the above-mentioned type xff0c; however, it does not need to request xff0c through a specific account address; it can be extrapolated from the signature.
为了创建和签署原生交易,交易的顺序如下:
To create and sign the original transaction xff0c; the order of the transaction is as follows xff1a;
- 1.确定交易发起者帐户的下一个可用随机数
- 2.创建对象
- 3.使用递归长度前缀编码(RLP即Recursive Length Prefix)对对象进行编码
- 4.签署对象
- 5.将对象发送到节点进行处理
是一个不断增长的数值,用来唯一地标识交易。一个只能使用一次,直到交易被挖掘完成,可以以相同的随机数发送交易的多个版本,但是一旦其中一个被挖掘完成,其他后续提交的都将被拒绝。
is a growing value xff0c; used to identify transactions only. One can only use xff0c once; until the transaction is excavated xff0c; multiple versions of the transaction xff0c can be sent at the same random number; but once one of them is excavated xff0c; other subsequent submissions will be rejected.
一旦获得下一个可用的,该值就可以用来创建对象:
Once the next available xff0c is available; this value can be used to create objects xff1a;
然后可以对交易进行签名和编码:
The transaction can then be signed and coded xff1a;
其中凭据是根据创建和使用钱包文件加载的。
These documents are based on the creation and use of wallet files based on
然后使用eth_SendRawTransaction发送交易: eth_SendRawTransaction to send the transaction #xff1a; 有关创建和发送原始事务的完整示例,请参阅 CreateRawTransactionIT。 Full examples of the creation and sending of the original service & #xff0c; see 是一个不断增长的数值,用来唯一地标识交易。一个只能使用一次,直到交易被挖掘完成,可以以相同的随机数发送交易的多个版本,但是一旦其中一个被挖掘完成,其他后续提交的都将被拒绝。 is a growing value xff0c; used to identify transactions only. One can only use xff0c once; until the transaction is excavated xff0c; multiple versions of the transaction xff0c can be sent at the same random number; but once one of them is excavated xff0c; other subsequent submissions will be rejected. 可以通过方法获得下一个可用的: The next available xff1a can be obtained by means; 然后可以使用创建你的交易对象: Then you can use the object that created you & #xff1a; web3j中的不同类型的交易都使用和对象。关键的区别是交易对象必须始终有一个地址,以便处理请求的以太坊客户端知道要使用哪个钱包来代表消息发送者并发送该交易。如上所述,对于离线签名认证签署的原始交易而言,这不是必须的。 The key difference is that the subject must always have an address & #xff0c; in order to process the request, the user knows which wallet to use to represent the sender and send the transaction. As noted above & #xff0c; xff0c for offline signature authentication of the original transaction; this is not necessary. 接下来的部分概述了不同交易类型所需的关键交易属性。下列属性对所有人都是不变: The following section outlines the key transaction properties required for different transaction types. The following attributes are constant for everyone xff1a; 和对象在所有后续示例中都可互换使用。 and objects can be used interchangeably in all subsequent examples. 在双方之间发送以太币Ether需要交易对象的最少量的信息: Sending the smallest amount of information between the parties to whom Ether needs to deal xff1a; 但是,建议你使用TransferClass来发送以太币Ether,它负责对管理和通过不断的轮询为你提供响应: xff0c; however, it is recommended that you use
当使用下面列出的智能合约打包器时,将不得不手动执行从Solidity到本机Java类型的所有转换。使用Solidity smart contract wrappers是非常有效的,它负责所有的代码生成和转换。 When using the smart contract packager listed below & #xff0c; you will have to manually execute all conversions from Solidity to the current Java type. Use
要部署新的智能合约,需要提供以下属性: To deploy a new smart contract xff0c; the following properties are required xff1a; 如果智能合约包含构造函数,则必须对关联的构造函数字段值进行编码,并将其附加到编译的智能合约代码中: If an intelligent contract contains a construction function & #xff0c; the associated construction letter numerical segment value & #xff0c must be encoded and attached to the compiled smart contract code & #xff1a; 要与现有的智能合约进行交易,需要提供以下属性: To trade with existing smart contracts xff0c; the following properties are required xff1a; web3j负责函数编码,有关实现的进一步细节,请参阅应用程序二进制接口部分Application Binary Interface。 Web3j is responsible for function coding & #xff0c; further details on the achievement & #xff0c; see application binary interface section . 无论消息签名的返回类型如何,都不可能从事务性函数调用返回值。但是,使用过滤器捕获函数返回的值是可能的。详情请参阅过滤器和事件部分。 No matter the type of return of the message signature xff0c; it is not possible to call the return value from the transactional function. But xff0c; values returned from the capture function using the filter are possible. See the filter and the event section for details. 这种功能是由eth_call通过调用来实现的。 This function is performed by eth_call. eth_call允许你调用智能合约上的方法来查询某个值。此函数没有关联交易成本,这是因为它不改变任何智能合约方法的状态,它只返回它们的值: Eth_call allows you to call the smart contract to search for a value. This function does not relate to transaction costs xff0c; it does not change the status of any smart contract method xff0c; it only returns their value xff1a; 注意:如果一个无效的函数调用被执行,或者得到一个空null返回结果时,返回值将是一个Collections.emptyList实例。 汇智网原创翻译,转载请标明出处。原文访问其官方博客 Original translator & #xff0c; reprinted from 交易随机数nonce
交易类型
以太币从一方交易到另一方
使用智能合约打包器smart contract wrappers
创建一个智能合约
与智能合约交易
查询智能合约状态
注册有任何问题请添加 微信:MVIP619 拉你进入群
打开微信扫一扫
添加客服
进入交流群
发表评论