Tabnine Logo
TransactionEncoder
Code IndexAdd Tabnine to your IDE (free)

How to use
TransactionEncoder
in
org.web3j.crypto

Best Java code snippets using org.web3j.crypto.TransactionEncoder (Showing top 20 results out of 315)

origin: web3j/web3j

public String sign(RawTransaction rawTransaction) {
  byte[] signedMessage;
  if (chainId > ChainId.NONE) {
    signedMessage = TransactionEncoder.signMessage(rawTransaction, chainId, credentials);
  } else {
    signedMessage = TransactionEncoder.signMessage(rawTransaction, credentials);
  }
  return Numeric.toHexString(signedMessage);
}
origin: web3j/web3j

public static byte[] encode(RawTransaction rawTransaction) {
  return encode(rawTransaction, null);
}
origin: web3j/web3j

private static byte[] encode(RawTransaction rawTransaction, Sign.SignatureData signatureData) {
  List<RlpType> values = asRlpValues(rawTransaction, signatureData);
  RlpList rlpList = new RlpList(values);
  return RlpEncoder.encode(rlpList);
}
origin: web3j/web3j

public static byte[] signMessage(
    RawTransaction rawTransaction, byte chainId, Credentials credentials) {
  byte[] encodedTransaction = encode(rawTransaction, chainId);
  Sign.SignatureData signatureData = Sign.signMessage(
      encodedTransaction, credentials.getEcKeyPair());
  Sign.SignatureData eip155SignatureData = createEip155SignatureData(signatureData, chainId);
  return encode(rawTransaction, eip155SignatureData);
}
origin: web3j/web3j

RawTransaction rawTransaction = RawTransaction.createEtherTransaction(
    nonce, gasPrice, gasLimit, to, value);
byte[] signedMessage = TransactionEncoder.signMessage(
    rawTransaction, SampleKeys.CREDENTIALS);
String hexMessage = Numeric.toHexString(signedMessage);
assertNotNull(signedResult.getSignatureData());
Sign.SignatureData signatureData = signedResult.getSignatureData();
byte[] encodedTransaction = TransactionEncoder.encode(rawTransaction);
BigInteger key = Sign.signedMessageToKey(encodedTransaction, signatureData);
assertEquals(key, SampleKeys.PUBLIC_KEY);
origin: org.web3j/crypto

public static byte[] signMessage(
    RawTransaction rawTransaction, byte chainId, Credentials credentials) {
  byte[] encodedTransaction = encode(rawTransaction, chainId);
  Sign.SignatureData signatureData = Sign.signMessage(
      encodedTransaction, credentials.getEcKeyPair());
  Sign.SignatureData eip155SignatureData = createEip155SignatureData(signatureData, chainId);
  return encode(rawTransaction, eip155SignatureData);
}
origin: web3j/web3j

/**
 * Utility method to provide the transaction hash for a given transaction.
 *
 * @param rawTransaction we wish to send
 * @param credentials of the sender
 * @return encoded transaction hash
 */
public static byte[] generateTransactionHash(
    RawTransaction rawTransaction, Credentials credentials) {
  byte[] signedMessage = TransactionEncoder.signMessage(rawTransaction, credentials);
  return Hash.sha3(signedMessage);
}
origin: web3j/web3j

public static byte[] encode(RawTransaction rawTransaction, byte chainId) {
  Sign.SignatureData signatureData = new Sign.SignatureData(
      chainId, new byte[] {}, new byte[] {});
  return encode(rawTransaction, signatureData);
}
origin: web3j/web3j

@Test
public void testContractAsRlpValues() {
  List<RlpType> rlpStrings = TransactionEncoder.asRlpValues(
      createContractTransaction(), null);
  assertThat(rlpStrings.size(), is(6));
  assertThat(rlpStrings.get(3), is(RlpString.create("")));
}
origin: web3j/web3j

/**
 * Utility method to provide the transaction hash for a given transaction.
 *
 * @param rawTransaction we wish to send
 * @param chainId of the intended chain
 * @param credentials of the sender
 * @return encoded transaction hash
 */
public static byte[] generateTransactionHash(
    RawTransaction rawTransaction, byte chainId, Credentials credentials) {
  byte[] signedMessage = TransactionEncoder.signMessage(rawTransaction, chainId, credentials);
  return Hash.sha3(signedMessage);
}
origin: web3j/web3j

public static byte[] signMessage(RawTransaction rawTransaction, Credentials credentials) {
  byte[] encodedTransaction = encode(rawTransaction);
  Sign.SignatureData signatureData = Sign.signMessage(
      encodedTransaction, credentials.getEcKeyPair());
  return encode(rawTransaction, signatureData);
}
origin: web3j/web3j

@Test
public void testEtherTransactionAsRlpValues() {
  List<RlpType> rlpStrings = TransactionEncoder.asRlpValues(createEtherTransaction(),
      new Sign.SignatureData((byte) 0, new byte[32], new byte[32]));
  assertThat(rlpStrings.size(), is(9));
  assertThat(rlpStrings.get(3), equalTo(RlpString.create(new BigInteger("add5355", 16))));
}
origin: web3j/web3j

@Test
public void testSignMessage() {
  byte[] signedMessage = TransactionEncoder.signMessage(
      createEtherTransaction(), SampleKeys.CREDENTIALS);
  String hexMessage = Numeric.toHexString(signedMessage);
  assertThat(hexMessage,
      is("0xf85580010a840add5355887fffffffffffffff80"
          + "1c"
          + "a046360b50498ddf5566551ce1ce69c46c565f1f478bb0ee680caf31fbc08ab727"
          + "a01b2f1432de16d110407d544f519fc91b84c8e16d3b6ec899592d486a94974cd0"));
}
origin: web3j/web3j

public String getFrom() throws SignatureException {
  Integer chainId = getChainId();
  byte[] encodedTransaction;
  if (null == chainId) {
    encodedTransaction = TransactionEncoder.encode(this);
  } else {
    encodedTransaction = TransactionEncoder.encode(this, chainId.byteValue());
  }
  byte v = signatureData.getV();
  byte[] r = signatureData.getR();
  byte[] s = signatureData.getS();
  Sign.SignatureData signatureDataV = new Sign.SignatureData(getRealV(v), r, s);
  BigInteger key = Sign.signedMessageToKey(encodedTransaction, signatureDataV);
  return "0x" + Keys.getAddress(key);
}
origin: org.web3j/crypto

private static byte[] encode(RawTransaction rawTransaction, Sign.SignatureData signatureData) {
  List<RlpType> values = asRlpValues(rawTransaction, signatureData);
  RlpList rlpList = new RlpList(values);
  return RlpEncoder.encode(rlpList);
}
origin: web3j/web3j

@Test
public void testEip155Transaction() {
  // https://github.com/ethereum/EIPs/issues/155
  Credentials credentials = Credentials.create(
      "0x4646464646464646464646464646464646464646464646464646464646464646");
  assertThat(TransactionEncoder.signMessage(
      createEip155RawTransaction(), (byte) 1, credentials),
      is(Numeric.hexStringToByteArray(
          "0xf86c098504a817c800825208943535353535353535353535353535353535353535880"
              + "de0b6b3a76400008025a028ef61340bd939bc2195fe537567866003e1a15d"
              + "3c71ff63e1590620aa636276a067cbe9d8997f761aecb703304b3800ccf55"
              + "5c9f3dc64214b297fb1966a3b6d83")));
}
origin: web3j/web3j

@Test
public void testEip155Encode() {
  assertThat(TransactionEncoder.encode(createEip155RawTransaction(), (byte) 1),
      is(Numeric.hexStringToByteArray(
          "0xec098504a817c800825208943535353535353535353535353535353535353535880de0"
              + "b6b3a764000080018080")));
}
origin: web3j/web3j

private String execute(
    Credentials credentials, Function function, String contractAddress) throws Exception {
  BigInteger nonce = getNonce(credentials.getAddress());
  String encodedFunction = FunctionEncoder.encode(function);
  RawTransaction rawTransaction = RawTransaction.createTransaction(
      nonce,
      GAS_PRICE,
      GAS_LIMIT,
      contractAddress,
      encodedFunction);
  byte[] signedMessage = TransactionEncoder.signMessage(rawTransaction, credentials);
  String hexValue = Numeric.toHexString(signedMessage);
  EthSendTransaction transactionResponse = web3j.ethSendRawTransaction(hexValue)
      .sendAsync().get();
  return transactionResponse.getTransactionHash();
}
origin: web3j/web3j

@Test
public void testSignTransaction() throws Exception {
  boolean accountUnlocked = unlockAccount();
  assertTrue(accountUnlocked);
  RawTransaction rawTransaction = createTransaction();
  byte[] encoded = TransactionEncoder.encode(rawTransaction);
  byte[] hashed = Hash.sha3(encoded);
  EthSign ethSign = web3j.ethSign(ALICE.getAddress(), Numeric.toHexString(hashed))
      .sendAsync().get();
  String signature = ethSign.getSignature();
  assertNotNull(signature);
  assertFalse(signature.isEmpty());
}
origin: web3j/web3j

@Test
public void testTransferEther() throws Exception {
  BigInteger nonce = getNonce(ALICE.getAddress());
  RawTransaction rawTransaction = createEtherTransaction(
      nonce, BOB.getAddress());
  byte[] signedMessage = TransactionEncoder.signMessage(rawTransaction, ALICE);
  String hexValue = Numeric.toHexString(signedMessage);
  EthSendTransaction ethSendTransaction =
      web3j.ethSendRawTransaction(hexValue).sendAsync().get();
  String transactionHash = ethSendTransaction.getTransactionHash();
  assertFalse(transactionHash.isEmpty());
  TransactionReceipt transactionReceipt =
      waitForTransactionReceipt(transactionHash);
  assertThat(transactionReceipt.getTransactionHash(), is(transactionHash));
}
org.web3j.cryptoTransactionEncoder

Javadoc

Create RLP encoded transaction, implementation as per p4 of the yellow paper.

Most used methods

  • signMessage
  • encode
  • asRlpValues
  • createEip155SignatureData

Popular in Java

  • Creating JSON documents from java classes using gson
  • setRequestProperty (URLConnection)
  • getOriginalFilename (MultipartFile)
    Return the original filename in the client's filesystem.This may contain path information depending
  • scheduleAtFixedRate (ScheduledExecutorService)
  • GridBagLayout (java.awt)
    The GridBagLayout class is a flexible layout manager that aligns components vertically and horizonta
  • GridLayout (java.awt)
    The GridLayout class is a layout manager that lays out a container's components in a rectangular gri
  • Scanner (java.util)
    A parser that parses a text string of primitive types and strings with the help of regular expressio
  • CountDownLatch (java.util.concurrent)
    A synchronization aid that allows one or more threads to wait until a set of operations being perfor
  • Manifest (java.util.jar)
    The Manifest class is used to obtain attribute information for a JarFile and its entries.
  • FileUtils (org.apache.commons.io)
    General file manipulation utilities. Facilities are provided in the following areas: * writing to a
  • Top plugins for Android Studio
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogTabnine AcademyTerms of usePrivacy policyJava Code IndexJavascript Code Index
Get Tabnine for your IDE now