Ich versuche, Ether programmgesteuert mit EthereumJ von meiner Brieftasche auf eine andere zu übertragen. Ich habe hier eine ähnliche Frage gesehen , aber die Antwort hat nicht alle Variablen definiert und initialisiert, noch den Link zum Code. Kann jemand ein vollständiges Beispiel dafür posten, wie das geht? Ich bin nicht neu in Java oder Bitcoin, aber Ether hat sich für mich als sehr kompliziert erwiesen.
Das ist völlig aus dem Kopf und ich habe noch kein funktionierendes Projekt mit EthereumJ auf meiner Entwicklungsmaschine. Aber die allgemeine Idee ist wie folgt. Ich habe nur einige zusätzliche Kommentare hinzugefügt, um die Erklärung zu erleichtern.
import org.ethereum.core.*;
import org.ethereum.crypto.ECKey;
import org.ethereum.db.ByteArrayWrapper;
import org.ethereum.facade.EthereumFactory;
import org.ethereum.listener.EthereumListenerAdapter;
import org.ethereum.util.ByteUtil;
import org.spongycastle.util.encoders.Hex;
import org.springframework.context.annotation.Bean;
import java.math.BigInteger;
public class sendEth{
// Amount in ether to send
BigInteger etherToSend = BigInteger.valueOf(100);//change 100 to any amount of eth
// Weis in 1 ether
BigInteger weiInEther = BigInteger.valueOf(1_000_000_000_000_000_000L);//This remains unchanged
BigInteger weiToSend = weiInEther.multiply(etherToSend);//this converts the whole number from "etherToSend" into wei
BigInteger nonce = ethereum.getRepository().getNonce(senderKey.getAddress());//this gets the current nonce
/*now we call Transaction.class "Transaction tx = new Transaction(nonce,gasPrice,gasLimit,recieving address,amount to send(in wei))"
*/
Transaction tx = new Transaction(
ByteUtil.bigIntegerToBytes(nonce),//adds the transaction nonce to transaction
ByteUtil.longToBytesNoLeadZeroes(ethereum.getGasPrice()),//adds the gas current gas price
ByteUtil.longToBytesNoLeadZeroes(3_000_000), // adds the Gas limit
receiveAddress,// adds the destination address of the transaction
ByteUtil.bigIntegerToBytes(weiToSend), //adds the Amount to send in wei
new byte[0] // We don't need to send any data
);
tx.sign(senderKey);//this signs the transaction with your private key
ethereum.submitTransaction(tx);//this submits it to the blockchain
}
Es gibt auch dieses https://github.com/ethereum/ethereumj/blob/develop/ethereumj-core/src/main/java/org/ethereum/samples/SendTransaction.java