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

How to use
encode
method
in
org.web3j.crypto.TransactionEncoder

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

origin: web3j/web3j

public static byte[] encode(RawTransaction rawTransaction) {
  return encode(rawTransaction, null);
}
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

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

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

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: web3j/web3j

@Test
public void testEip155Encode() {
  assertThat(TransactionEncoder.encode(createEip155RawTransaction(), (byte) 1),
      is(Numeric.hexStringToByteArray(
          "0xec098504a817c800825208943535353535353535353535353535353535353535880de0"
              + "b6b3a764000080018080")));
}
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 testDecoding() throws Exception {
  BigInteger nonce = BigInteger.ZERO;
  BigInteger gasPrice = BigInteger.ONE;
  BigInteger gasLimit = BigInteger.TEN;
  String to = "0x0add5355";
  BigInteger value = BigInteger.valueOf(Long.MAX_VALUE);
  RawTransaction rawTransaction = RawTransaction.createEtherTransaction(
      nonce, gasPrice, gasLimit, to, value);
  byte[] encodedMessage = TransactionEncoder.encode(rawTransaction);
  String hexMessage = Numeric.toHexString(encodedMessage);
  RawTransaction result = TransactionDecoder.decode(hexMessage);
  assertNotNull(result);
  assertEquals(nonce, result.getNonce());
  assertEquals(gasPrice, result.getGasPrice());
  assertEquals(gasLimit, result.getGasLimit());
  assertEquals(to, result.getTo());
  assertEquals(value, result.getValue());
  assertEquals("", result.getData());
}
origin: web3j/web3j

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[] encode(RawTransaction rawTransaction) {
  return encode(rawTransaction, null);
}
origin: org.web3j/crypto

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: org.web3j/crypto

public static byte[] encode(RawTransaction rawTransaction, byte chainId) {
  Sign.SignatureData signatureData = new Sign.SignatureData(
      chainId, new byte[] {}, new byte[] {});
  return encode(rawTransaction, signatureData);
}
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: org.web3j/crypto

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: ethjava/web3j-sample

private static void decodeMessage(String signedData) {
  //样例 https://ropsten.etherscan.io/tx/0xfd8acd10d72127f29f0a01d8bcaf0165665b5598781fe01ca4bceaa6ab9f2cb0
  try {
    System.out.println(signedData);
    System.out.println("解密 start " + System.currentTimeMillis());
    RlpList rlpList = RlpDecoder.decode(Numeric.hexStringToByteArray(signedData));
    List<RlpType> values = ((RlpList) rlpList.getValues().get(0)).getValues();
    BigInteger nonce = Numeric.toBigInt(((RlpString) values.get(0)).getBytes());
    BigInteger gasPrice = Numeric.toBigInt(((RlpString) values.get(1)).getBytes());
    BigInteger gasLimit = Numeric.toBigInt(((RlpString) values.get(2)).getBytes());
    String to = Numeric.toHexString(((RlpString) values.get(3)).getBytes());
    BigInteger value = Numeric.toBigInt(((RlpString) values.get(4)).getBytes());
    String data = Numeric.toHexString(((RlpString) values.get(5)).getBytes());
    RawTransaction rawTransaction = RawTransaction.createTransaction(nonce, gasPrice, gasLimit, to, value, data);
    RlpString v = (RlpString) values.get(6);
    RlpString r = (RlpString) values.get(7);
    RlpString s = (RlpString) values.get(8);
    Sign.SignatureData signatureData = new Sign.SignatureData(
        v.getBytes()[0],
        Numeric.toBytesPadded(Numeric.toBigInt(r.getBytes()), 32),
        Numeric.toBytesPadded(Numeric.toBigInt(s.getBytes()), 32));
    BigInteger pubKey = Sign.signedMessageToKey(TransactionEncoder.encode(rawTransaction), signatureData);
    System.out.println("publicKey " + pubKey.toString(16));
    String address = Numeric.prependHexPrefix(Keys.getAddress(pubKey));
    System.out.println("address " + address);
    System.out.println("解密 end " + System.currentTimeMillis());
  } catch (Exception e) {
    e.printStackTrace();
  }
}
org.web3j.cryptoTransactionEncoderencode

Popular methods of TransactionEncoder

  • signMessage
  • asRlpValues
  • createEip155SignatureData

Popular in Java

  • Running tasks concurrently on multiple threads
  • getOriginalFilename (MultipartFile)
    Return the original filename in the client's filesystem.This may contain path information depending
  • onRequestPermissionsResult (Fragment)
  • notifyDataSetChanged (ArrayAdapter)
  • ObjectMapper (com.fasterxml.jackson.databind)
    ObjectMapper provides functionality for reading and writing JSON, either to and from basic POJOs (Pl
  • LinkedHashMap (java.util)
    LinkedHashMap is an implementation of Map that guarantees iteration order. All optional operations a
  • SortedSet (java.util)
    SortedSet is a Set which iterates over its elements in a sorted order. The order is determined eithe
  • Vector (java.util)
    Vector is an implementation of List, backed by an array and synchronized. All optional operations in
  • Manifest (java.util.jar)
    The Manifest class is used to obtain attribute information for a JarFile and its entries.
  • JList (javax.swing)
  • Top plugins for WebStorm
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