private static RawTransaction createEtherTransaction() { return RawTransaction.createEtherTransaction( BigInteger.ZERO, BigInteger.ONE, BigInteger.TEN, "0xadd5355", BigInteger.valueOf(Long.MAX_VALUE)); }
private static RawTransaction createEip155RawTransaction() { return RawTransaction.createEtherTransaction( BigInteger.valueOf(9), BigInteger.valueOf(20000000000L), BigInteger.valueOf(21000), "0x3535353535353535353535353535353535353535", BigInteger.valueOf(1000000000000000000L)); } }
private static RawTransaction createTransaction() { BigInteger value = Convert.toWei("1", Convert.Unit.ETHER).toBigInteger(); return RawTransaction.createEtherTransaction( BigInteger.valueOf(1048587), BigInteger.valueOf(500000), BigInteger.valueOf(500000), "0x9C98E381Edc5Fe1Ac514935F3Cc3eDAA764cf004", value); } }
private static RawTransaction createEtherTransaction(BigInteger nonce, String toAddress) { BigInteger value = Convert.toWei("0.5", Convert.Unit.ETHER).toBigInteger(); return RawTransaction.createEtherTransaction( nonce, GAS_PRICE, GAS_LIMIT, toAddress, value); }
@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()); }
@Test public void testDecodingSignedChainId() throws Exception { BigInteger nonce = BigInteger.ZERO; BigInteger gasPrice = BigInteger.ONE; BigInteger gasLimit = BigInteger.TEN; String to = "0x0add5355"; BigInteger value = BigInteger.valueOf(Long.MAX_VALUE); Integer chainId = 1; RawTransaction rawTransaction = RawTransaction.createEtherTransaction( nonce, gasPrice, gasLimit, to, value); byte[] signedMessage = TransactionEncoder.signMessage( rawTransaction, chainId.byteValue(), SampleKeys.CREDENTIALS); String hexMessage = Numeric.toHexString(signedMessage); 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()); assertTrue(result instanceof SignedRawTransaction); SignedRawTransaction signedResult = (SignedRawTransaction) result; assertEquals(SampleKeys.ADDRESS, signedResult.getFrom()); signedResult.verify(SampleKeys.ADDRESS); assertEquals(chainId, signedResult.getChainId()); }
String to = "0x0add5355"; BigInteger value = BigInteger.valueOf(Long.MAX_VALUE); RawTransaction rawTransaction = RawTransaction.createEtherTransaction( nonce, gasPrice, gasLimit, to, value); byte[] signedMessage = TransactionEncoder.signMessage(
/** * ETH 转账离线签名 * * @param to 转入的钱包地址 * @param nonce 以太坊nonce * @param gasPrice gasPrice * @param gasLimit gasLimit * @param amount 转账的eth数量 * @param walletfile 钱包对象 * @param password 密码 * @return 签名data */ public String signedEthTransactionData(String to, BigInteger nonce, BigInteger gasPrice, BigInteger gasLimit, BigDecimal amount, WalletFile walletfile, String password) throws Exception { // 把十进制的转换成ETH的Wei, 1ETH = 10^18 Wei BigDecimal amountInWei = Convert.toWei(amount.toString(), Convert.Unit.ETHER); RawTransaction rawTransaction = RawTransaction.createEtherTransaction(nonce, gasPrice, gasLimit, to, amountInWei.toBigInteger()); return signData(rawTransaction, walletfile, password); }
Log.d(TAG, "run: value wei" + value.toPlainString()); String to = mToAddressEdit.getText().toString().trim(); RawTransaction etherTransaction = RawTransaction.createEtherTransaction(transactionCount, gasPrice, gasLimit, to, value.toBigInteger()); ECKeyPair ecKeyPair = Wallet.decrypt("a12345678", mWalletFile); Credentials credentials = Credentials.create(ecKeyPair);
public String signedTransactionData() { final RawTransaction transaction = RawTransaction.createEtherTransaction( nonce.orElse(nonce.orElseGet(sender::getNextNonce)), MINIMUM_GAS_PRICE, TRANSFER_GAS_COST, recipient.getAddress(), Convert.toWei(amount, unit).toBigIntegerExact()); return toHexString(TransactionEncoder.signMessage(transaction, sender.web3jCredentials())); } }