org.web3j.protocol.core.methods.request.Transaction Java Examples
The following examples show how to use
org.web3j.protocol.core.methods.request.Transaction.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: Web3jUtils.java From web3j_demo with Apache License 2.0 | 7 votes |
/** * Transfers the specified amount of Wei from the coinbase to the specified account. * The method waits for the transfer to complete using method {@link waitForReceipt}. */ public static TransactionReceipt transferFromCoinbaseAndWait(Web3j web3j, String to, BigInteger amountWei) throws Exception { String coinbase = getCoinbase(web3j).getResult(); BigInteger nonce = getNonce(web3j, coinbase); // this is a contract method call -> gas limit higher than simple fund transfer BigInteger gasLimit = Web3jConstants.GAS_LIMIT_ETHER_TX.multiply(BigInteger.valueOf(2)); Transaction transaction = Transaction.createEtherTransaction( coinbase, nonce, Web3jConstants.GAS_PRICE, gasLimit, to, amountWei); EthSendTransaction ethSendTransaction = web3j .ethSendTransaction(transaction) .sendAsync() .get(); String txHash = ethSendTransaction.getTransactionHash(); return waitForReceipt(web3j, txHash); }
Example #2
Source File: DeployContractIT.java From etherscan-explorer with GNU General Public License v3.0 | 6 votes |
private String sendTransaction() throws Exception { BigInteger nonce = getNonce(ALICE.getAddress()); Transaction transaction = Transaction.createContractTransaction( ALICE.getAddress(), nonce, GAS_PRICE, GAS_LIMIT, BigInteger.ZERO, getFibonacciSolidityBinary()); org.web3j.protocol.core.methods.response.EthSendTransaction transactionResponse = web3j.ethSendTransaction(transaction) .sendAsync().get(); return transactionResponse.getTransactionHash(); }
Example #3
Source File: RequestTest.java From etherscan-explorer with GNU General Public License v3.0 | 6 votes |
@Test public void testPersonalSendTransaction() throws Exception { web3j.personalSendTransaction( new Transaction( "FROM", BigInteger.ONE, BigInteger.TEN, BigInteger.ONE, "TO", BigInteger.ZERO, "DATA" ), "password" ).send(); //CHECKSTYLE:OFF verifyResult("{\"jsonrpc\":\"2.0\",\"method\":\"personal_sendTransaction\",\"params\":[{\"from\":\"FROM\",\"to\":\"TO\",\"gas\":\"0x1\",\"gasPrice\":\"0xa\",\"value\":\"0x0\",\"data\":\"0xDATA\",\"nonce\":\"0x1\"},\"password\"],\"id\":1}"); //CHECKSTYLE:ON }
Example #4
Source File: ClientTransactionManager.java From web3j with Apache License 2.0 | 6 votes |
@Override public EthSendTransaction sendTransactionEIP1559( BigInteger gasPremium, BigInteger feeCap, BigInteger gasLimit, String to, String data, BigInteger value, boolean constructor) throws IOException { Transaction transaction = new Transaction( getFromAddress(), null, null, gasLimit, to, value, data, gasPremium, feeCap); return web3j.ethSendTransaction(transaction).send(); }
Example #5
Source File: ReadTimeoutAcceptanceTest.java From ethsigner with Apache License 2.0 | 6 votes |
@Test public void submittingTransactionWithoutNonceReturnsAGatewayTimeoutError() { final String recipient = "0x1b00ba00ca00bb00aa00bc00be00ac00ca00da00"; final BigInteger transferAmountWei = Convert.toWei("15.5", Unit.ETHER).toBigIntegerExact(); final Transaction transaction = Transaction.createEtherTransaction( richBenefactor().address(), null, GAS_PRICE, INTRINSIC_GAS, recipient, transferAmountWei); final SignerResponse<JsonRpcErrorResponse> signerResponse = ethSigner.transactions().submitExceptional(transaction); assertThat(signerResponse.status()).isEqualTo(GATEWAY_TIMEOUT); assertThat(signerResponse.jsonRpc().getError()) .isEqualTo(CONNECTION_TO_DOWNSTREAM_NODE_TIMED_OUT); }
Example #6
Source File: ConnectionTimeoutAcceptanceTest.java From ethsigner with Apache License 2.0 | 6 votes |
@Test public void submittingTransactionWithoutNonceReturnsAGatewayTimeoutError() { final String recipient = "0x1b00ba00ca00bb00aa00bc00be00ac00ca00da00"; final BigInteger transferAmountWei = Convert.toWei("15.5", Unit.ETHER).toBigIntegerExact(); final Transaction transaction = Transaction.createEtherTransaction( richBenefactor().address(), null, GAS_PRICE, INTRINSIC_GAS, recipient, transferAmountWei); final SignerResponse<JsonRpcErrorResponse> signerResponse = ethSigner.transactions().submitExceptional(transaction); assertThat(signerResponse.status()).isEqualTo(GATEWAY_TIMEOUT); assertThat(signerResponse.jsonRpc().getError()) .isEqualTo(CONNECTION_TO_DOWNSTREAM_NODE_TIMED_OUT); }
Example #7
Source File: MultiKeyTransactionSigningAcceptanceTestBase.java From ethsigner with Apache License 2.0 | 6 votes |
void performTransaction() { final BigInteger transferAmountWei = Convert.toWei("1.75", Unit.ETHER).toBigIntegerExact(); final BigInteger startBalance = ethNode.accounts().balance(RECIPIENT); final Transaction transaction = Transaction.createEtherTransaction( richBenefactor().address(), null, GAS_PRICE, INTRINSIC_GAS, RECIPIENT, transferAmountWei); final String hash = ethSigner.transactions().submit(transaction); ethNode.transactions().awaitBlockContaining(hash); final BigInteger expectedEndBalance = startBalance.add(transferAmountWei); final BigInteger actualEndBalance = ethNode.accounts().balance(RECIPIENT); assertThat(actualEndBalance).isEqualTo(expectedEndBalance); }
Example #8
Source File: RequestTest.java From web3j with Apache License 2.0 | 6 votes |
@Test public void testEthSendTransaction() throws Exception { web3j.ethSendTransaction( new Transaction( "0xb60e8dd61c5d32be8058bb8eb970870f07233155", BigInteger.ONE, Numeric.toBigInt("0x9184e72a000"), Numeric.toBigInt("0x76c0"), "0xb60e8dd61c5d32be8058bb8eb970870f07233155", Numeric.toBigInt("0x9184e72a"), "0xd46e8dd67c5d32be8d46e8dd67c5d32be8058bb8eb" + "970870f072445675058bb8eb970870f072445675")) .send(); verifyResult( "{\"jsonrpc\":\"2.0\",\"method\":\"eth_sendTransaction\",\"params\":[{\"from\":\"0xb60e8dd61c5d32be8058bb8eb970870f07233155\",\"to\":\"0xb60e8dd61c5d32be8058bb8eb970870f07233155\",\"gas\":\"0x76c0\",\"gasPrice\":\"0x9184e72a000\",\"value\":\"0x9184e72a\",\"data\":\"0xd46e8dd67c5d32be8d46e8dd67c5d32be8058bb8eb970870f072445675058bb8eb970870f072445675\",\"nonce\":\"0x1\"}],\"id\":1}"); }
Example #9
Source File: RequestTest.java From web3j with Apache License 2.0 | 6 votes |
@Test public void testPrivCall() throws Exception { web3j.privCall( MOCK_PRIVACY_GROUP_ID.toString(), Transaction.createEthCallTransaction( "0xa70e8dd61c5d32be8058bb8eb970870f07233155", "0xb60e8dd61c5d32be8058bb8eb970870f07233155", "0x0"), DefaultBlockParameter.valueOf("latest")) .send(); verifyResult( "{\"jsonrpc\":\"2.0\",\"method\":\"priv_call\"," + "\"params\":[\"DyAOiF/ynpc+JXa2YAGB0bCitSlOMNm+ShmB/7M6C4w=\",{\"from\":\"0xa70e8dd61c5d32be8058bb8eb970870f07233155\"," + "\"to\":\"0xb60e8dd61c5d32be8058bb8eb970870f07233155\",\"data\":\"0x0\"}," + "\"latest\"],\"id\":1}"); }
Example #10
Source File: ValueTransferAcceptanceTest.java From ethsigner with Apache License 2.0 | 6 votes |
@Test public void valueTransfer() { final BigInteger transferAmountWei = Convert.toWei("1.75", Unit.ETHER).toBigIntegerExact(); final BigInteger startBalance = ethNode().accounts().balance(RECIPIENT); final Transaction transaction = Transaction.createEtherTransaction( richBenefactor().address(), null, GAS_PRICE, INTRINSIC_GAS, RECIPIENT, transferAmountWei); final String hash = ethSigner().transactions().submit(transaction); ethNode().transactions().awaitBlockContaining(hash); final BigInteger expectedEndBalance = startBalance.add(transferAmountWei); final BigInteger actualEndBalance = ethNode().accounts().balance(RECIPIENT); assertThat(actualEndBalance).isEqualTo(expectedEndBalance); }
Example #11
Source File: ValueTransferAcceptanceTest.java From ethsigner with Apache License 2.0 | 6 votes |
@Test public void valueTransferNonceTooLow() { valueTransfer(); // call this test to increment the nonce final BigInteger transferAmountWei = Convert.toWei("15.5", Unit.ETHER).toBigIntegerExact(); final Transaction transaction = Transaction.createEtherTransaction( richBenefactor().address(), BigInteger.ZERO, GAS_PRICE, INTRINSIC_GAS, RECIPIENT, transferAmountWei); final SignerResponse<JsonRpcErrorResponse> jsonRpcErrorResponseSignerResponse = ethSigner().transactions().submitExceptional(transaction); assertThat(jsonRpcErrorResponseSignerResponse.jsonRpc().getError()) .isEqualTo(JsonRpcError.NONCE_TOO_LOW); }
Example #12
Source File: ReplayProtectionAcceptanceTest.java From ethsigner with Apache License 2.0 | 6 votes |
@Test public void wrongChainId() { setUp("eth_hash_4404.json"); final SignerResponse<JsonRpcErrorResponse> signerResponse = ethSigner .transactions() .submitExceptional( Transaction.createEtherTransaction( richBenefactor().address(), richBenefactor().nextNonceAndIncrement(), GAS_PRICE, INTRINSIC_GAS, RECIPIENT, TRANSFER_AMOUNT_WEI)); assertThat(signerResponse.status()).isEqualTo(BAD_REQUEST); assertThat(signerResponse.jsonRpc().getError()).isEqualTo(WRONG_CHAIN_ID); }
Example #13
Source File: ValueTransferAcceptanceTest.java From ethsigner with Apache License 2.0 | 6 votes |
@Test public void multipleValueTransfers() { final BigInteger transferAmountWei = Convert.toWei("1", Unit.ETHER).toBigIntegerExact(); final BigInteger startBalance = ethNode().accounts().balance(RECIPIENT); final Transaction transaction = Transaction.createEtherTransaction( richBenefactor().address(), null, GAS_PRICE, INTRINSIC_GAS, RECIPIENT, transferAmountWei); String hash = null; for (int i = 0; i < FIFTY_TRANSACTIONS; i++) { hash = ethSigner().transactions().submit(transaction); } ethNode().transactions().awaitBlockContaining(hash); final BigInteger endBalance = ethNode().accounts().balance(RECIPIENT); final BigInteger numberOfTransactions = BigInteger.valueOf(FIFTY_TRANSACTIONS); assertThat(endBalance) .isEqualTo(startBalance.add(transferAmountWei.multiply(numberOfTransactions))); }
Example #14
Source File: ValueTransferWithHashicorpAcceptanceTest.java From ethsigner with Apache License 2.0 | 6 votes |
@Test public void valueTransfer() { final BigInteger transferAmountWei = Convert.toWei("1.75", Convert.Unit.ETHER).toBigIntegerExact(); final BigInteger startBalance = ethNode().accounts().balance(RECIPIENT); final Transaction transaction = Transaction.createEtherTransaction( richBenefactor().address(), null, GAS_PRICE, INTRINSIC_GAS, RECIPIENT, transferAmountWei); final String hash = ethSigner().transactions().submit(transaction); ethNode().transactions().awaitBlockContaining(hash); final BigInteger expectedEndBalance = startBalance.add(transferAmountWei); final BigInteger actualEndBalance = ethNode().accounts().balance(RECIPIENT); assertThat(actualEndBalance).isEqualTo(expectedEndBalance); }
Example #15
Source File: GreeterContractIT.java From web3j with Apache License 2.0 | 6 votes |
private String sendCreateContractTransaction() throws Exception { BigInteger nonce = getNonce(ALICE.getAddress()); String encodedConstructor = FunctionEncoder.encodeConstructor(Collections.singletonList(new Utf8String(VALUE))); Transaction transaction = Transaction.createContractTransaction( ALICE.getAddress(), nonce, GAS_PRICE, GAS_LIMIT, BigInteger.ZERO, getGreeterSolidityBinary() + encodedConstructor); org.web3j.protocol.core.methods.response.EthSendTransaction transactionResponse = web3j.ethSendTransaction(transaction).sendAsync().get(); return transactionResponse.getTransactionHash(); }
Example #16
Source File: ValueTransferWithAzureAcceptanceTest.java From ethsigner with Apache License 2.0 | 6 votes |
@Test public void valueTransfer() { final BigInteger transferAmountWei = Convert.toWei("1.75", Convert.Unit.ETHER).toBigIntegerExact(); final BigInteger startBalance = ethNode().accounts().balance(RECIPIENT); final Transaction transaction = Transaction.createEtherTransaction( richBenefactor().address(), null, GAS_PRICE, INTRINSIC_GAS, RECIPIENT, transferAmountWei); final String hash = ethSigner().transactions().submit(transaction); ethNode().transactions().awaitBlockContaining(hash); final BigInteger expectedEndBalance = startBalance.add(transferAmountWei); final BigInteger actualEndBalance = ethNode().accounts().balance(RECIPIENT); assertThat(actualEndBalance).isEqualTo(expectedEndBalance); }
Example #17
Source File: RequestTest.java From web3j with Apache License 2.0 | 6 votes |
@Test public void testEthCall() throws Exception { web3j.ethCall( Transaction.createEthCallTransaction( "0xa70e8dd61c5d32be8058bb8eb970870f07233155", "0xb60e8dd61c5d32be8058bb8eb970870f07233155", "0x0"), DefaultBlockParameter.valueOf("latest")) .send(); verifyResult( "{\"jsonrpc\":\"2.0\",\"method\":\"eth_call\"," + "\"params\":[{\"from\":\"0xa70e8dd61c5d32be8058bb8eb970870f07233155\"," + "\"to\":\"0xb60e8dd61c5d32be8058bb8eb970870f07233155\",\"data\":\"0x0\"}," + "\"latest\"],\"id\":1}"); }
Example #18
Source File: RequestTest.java From web3j with Apache License 2.0 | 6 votes |
@Test public void testPersonalSendTransaction() throws Exception { web3j.personalSendTransaction( new Transaction( "FROM", BigInteger.ONE, BigInteger.TEN, BigInteger.ONE, "TO", BigInteger.ZERO, "DATA"), "password") .send(); verifyResult( "{\"jsonrpc\":\"2.0\",\"method\":\"personal_sendTransaction\",\"params\":[{\"from\":\"FROM\",\"to\":\"TO\",\"gas\":\"0x1\",\"gasPrice\":\"0xa\",\"value\":\"0x0\",\"data\":\"0xDATA\",\"nonce\":\"0x1\"},\"password\"],\"id\":1}"); }
Example #19
Source File: ValueTransferAcceptanceTest.java From ethsigner with Apache License 2.0 | 6 votes |
@Test public void valueTransferFromAccountWithInsufficientFunds() { final String recipientAddress = "0x1b11ba11ca11bb11aa11bc11be11ac11ca11da11"; final BigInteger senderStartBalance = ethNode().accounts().balance(richBenefactor()); final BigInteger recipientStartBalance = ethNode().accounts().balance(recipientAddress); final BigInteger transferAmountWei = senderStartBalance.add(BigInteger.ONE); final Transaction transaction = Transaction.createEtherTransaction( richBenefactor().address(), richBenefactor().nextNonce(), GAS_PRICE, INTRINSIC_GAS, recipientAddress, transferAmountWei); final SignerResponse<JsonRpcErrorResponse> signerResponse = ethSigner().transactions().submitExceptional(transaction); assertThat(signerResponse.status()).isEqualTo(BAD_REQUEST); assertThat(signerResponse.jsonRpc().getError()) .isEqualTo(TRANSACTION_UPFRONT_COST_EXCEEDS_BALANCE); final BigInteger senderEndBalance = ethNode().accounts().balance(richBenefactor()); final BigInteger recipientEndBalance = ethNode().accounts().balance(recipientAddress); assertThat(senderEndBalance).isEqualTo(senderStartBalance); assertThat(recipientEndBalance).isEqualTo(recipientStartBalance); }
Example #20
Source File: RequestTest.java From client-sdk-java with Apache License 2.0 | 5 votes |
@Test public void testEthEstimateGasContractCreation() throws Exception { web3j.platonEstimateGas( Transaction.createContractTransaction( "0x52b93c80364dc2dd4444c146d73b9836bbbb2b3f", BigInteger.ONE, BigInteger.TEN, "")).send(); verifyResult("{\"jsonrpc\":\"2.0\",\"method\":\"platon_estimateGas\"," + "\"params\":[{\"from\":\"0x52b93c80364dc2dd4444c146d73b9836bbbb2b3f\"," + "\"gasPrice\":\"0xa\",\"data\":\"0x\",\"nonce\":\"0x1\"}],\"id\":1}"); }
Example #21
Source File: RequestTest.java From web3j with Apache License 2.0 | 5 votes |
@Test public void testEthEstimateGasContractCreation() throws Exception { web3j.ethEstimateGas( Transaction.createContractTransaction( "0x52b93c80364dc2dd4444c146d73b9836bbbb2b3f", BigInteger.ONE, BigInteger.TEN, "")) .send(); verifyResult( "{\"jsonrpc\":\"2.0\",\"method\":\"eth_estimateGas\"," + "\"params\":[{\"from\":\"0x52b93c80364dc2dd4444c146d73b9836bbbb2b3f\"," + "\"gasPrice\":\"0xa\",\"data\":\"0x\",\"nonce\":\"0x1\"}],\"id\":1}"); }
Example #22
Source File: RevertReasonExtractor.java From web3j with Apache License 2.0 | 5 votes |
/** * Retrieves the error reason of a reverted transaction (if one exists). * * @param transactionReceipt the reverted transaction receipt * @param data the reverted transaction data * @param web3j Web3j instance * @return the reverted transaction error reason if exists or null otherwise * @throws IOException if the call to the node fails */ public static String retrieveRevertReason( TransactionReceipt transactionReceipt, String data, Web3j web3j) throws IOException { if (transactionReceipt.getBlockNumber() == null) { return null; } return web3j.ethCall( Transaction.createEthCallTransaction( transactionReceipt.getFrom(), transactionReceipt.getTo(), data), DefaultBlockParameter.valueOf(transactionReceipt.getBlockNumber())) .send() .getRevertReason(); }
Example #23
Source File: JsonRpc2_0Admin.java From etherscan-explorer with GNU General Public License v3.0 | 5 votes |
@Override public Request<?, EthSendTransaction> personalSendTransaction( Transaction transaction, String passphrase) { return new Request<>( "personal_sendTransaction", Arrays.asList(transaction, passphrase), web3jService, EthSendTransaction.class); }
Example #24
Source File: DefaultGasLimitEstimator.java From asf-sdk with GNU General Public License v3.0 | 5 votes |
@Override public BigInteger estimate(Address from, Address to, byte[] data) throws EstimateGasException { Transaction transaction = Transaction.createEthCallTransaction(from.toHexString(true), to.toHexString(true), Hex.toHexString(data)); try { return web3j.ethEstimateGas(transaction) .send() .getAmountUsed(); } catch (IOException e) { throw new EstimateGasException("Failed to estimate gas!", e); } }
Example #25
Source File: JsonRpc2_0Parity.java From web3j with Apache License 2.0 | 5 votes |
@Override public Request<?, ParityFullTraceResponse> traceCall( Transaction transaction, List<String> traces, DefaultBlockParameter blockParameter) { return new Request<>( "trace_call", Arrays.asList(transaction, traces, blockParameter), web3jService, ParityFullTraceResponse.class); }
Example #26
Source File: JsonRpc2_0Web3j.java From web3j with Apache License 2.0 | 5 votes |
@Override public Request<?, org.web3j.protocol.core.methods.response.EthSendTransaction> ethSendTransaction(Transaction transaction) { return new Request<>( "eth_sendTransaction", Arrays.asList(transaction), web3jService, org.web3j.protocol.core.methods.response.EthSendTransaction.class); }
Example #27
Source File: Web3jServiceTest.java From eventeum with Apache License 2.0 | 5 votes |
@Test public void testGetRevertReason() throws IOException { final Request<?, EthCall> mockRequest = mock(Request.class); final EthCall ethCall = mock(EthCall.class); when(ethCall.getRevertReason()).thenReturn(REVERT_REASON); when(mockRequest.send()).thenReturn(ethCall); doReturn(mockRequest).when(mockWeb3j).ethCall(any(Transaction.class), any(DefaultBlockParameter.class)); assertEquals(REVERT_REASON, underTest.getRevertReason(FROM_ADDRESS, TO_ADDRESS, BLOCK_NUMBER, "0x1")); }
Example #28
Source File: ContractTest.java From client-sdk-java with Apache License 2.0 | 5 votes |
@SuppressWarnings("unchecked") private void prepareCall(PlatonCall ethCall) throws IOException { Request<?, PlatonCall> request = mock(Request.class); when(request.send()).thenReturn(ethCall); when(web3j.platonCall(any(Transaction.class), eq(DefaultBlockParameterName.LATEST))) .thenReturn((Request) request); }
Example #29
Source File: EventFilterIT.java From etherscan-explorer with GNU General Public License v3.0 | 5 votes |
private String sendTransaction( Credentials credentials, String contractAddress, BigInteger gas, String encodedFunction) throws Exception { BigInteger nonce = getNonce(credentials.getAddress()); Transaction transaction = Transaction.createFunctionCallTransaction( credentials.getAddress(), nonce, Transaction.DEFAULT_GAS, gas, contractAddress, encodedFunction); org.web3j.protocol.core.methods.response.EthSendTransaction transactionResponse = web3j.ethSendTransaction(transaction).sendAsync().get(); assertFalse(transactionResponse.hasError()); return transactionResponse.getTransactionHash(); }
Example #30
Source File: JsonRpc2_0Besu.java From web3j with Apache License 2.0 | 5 votes |
@Override public Request<?, EthCall> privCall( String privacyGroupId, final Transaction transaction, final DefaultBlockParameter defaultBlockParameter) { return new Request<>( "priv_call", Arrays.asList(privacyGroupId, transaction, defaultBlockParameter), web3jService, org.web3j.protocol.core.methods.response.EthCall.class); }