Ethereum: How do I create an offline transaction in java to broadcast via blockchain.info?
08 Feb
By admin0 comment
Creating outline transactions on Blockchain Ethereum using Java and Pushtx API
Blockchain Ethereum is a decentralized, public and safe platform for storage and transactions. One of its key functions is the ability to create and broadcast off -air transactions through API Pushtx from external applications, such as mobile applications or Internet customers. In this article, we will examine how to create an out -of -the -art transaction in Java, which can be given a blockchain Ethereum using API Pushtx interfaces.
background
API Pushtx allows developers to send raw transactions to the knot in the Ethereum network without waiting to check the transaction with a peer (ie the second knot). This allows you to create and broadcast offline transactions from external applications. To use the API Pushtx interface, you have to get the Ethereum portfolio address that is not yet used as a wallet.
Select between Bitcoinj and Pushtx
There are two popular interaction libraries with Blockchain Ethereum in Java: Bitcoinj and Pushtx. Here’s a brief comparison:
* Bitcoinj : A complete functional library of clients cryptocurrencies that allows interaction with blockchain Ethereum using different protocols (eg JSON-RPC, HTTP). However, it requires the portfolio address and is not specifically designed for offline transactions.
* Pushtx : Library developed by infrastructure infrastructure supplier based on an Ethereum web network. Pushtx provides simply API interface to create and send raw transactions to the nodes in the Ethereum network.
In this example, we will use Pushtx.
Extraordinary transactions in Java
To create an off -hearted transaction using Pushtx, you must:
Create a new class “Pushtx”:
`Java
Imports Com.infura.pushtx.pushtx;
Import Com.infura.pushtx.pushtransation;
Public class offlinetransactionexamammple {
Public Static Void Main (String [] ARGS) {
// Set your URL Ethereum Node Address (eg "
String nodeurl = "
// Create a new instance of pushtx class instances
Pushtx Pushtx = New Pushtx (Nodeurl);
Iche
Iche
Set "Walletaddress" to the address of the Ethereum portfolio, which is not yet used as a wallet:
New String [] {"0x1234567890ABDEF", "Your transaction data"})
);
Signature of offline transactions
In order to sign an off -speed transaction, you must use the "PushTx" Class "reference number::
Java
// Sign the transaction with a private key
String reportedtransation = pushtx.signtransation (transaction, new string [] {"your_private_KEY"});
Extraordinary Transaction
After creating and signature of the out -of -the -art transactions, you can broadcast it on the Ethereum network using API Pushtx. Here's an example of how to do it:
Java
// Create a new instance of Pushtx Class with the same URL and the Wallet Wallet address
Pushtx Pushtx = New Pushtx (Nodeurl);
// Set the signed transaction as a load load
String filling = sonnedtransation;
// transactional transaction using API Pushtx
Pushtx.broadCast (loading, new string [] {"0x1234567890ABDEF", "Your transaction data"});
Code samples
Here's an example of a code sample showing how to take the above steps: