Java Code Examples for org.web3j.protocol.core.methods.request.Transaction
The following examples show how to use
org.web3j.protocol.core.methods.request.Transaction.
These examples are extracted from open source projects.
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 Project: ethsigner Author: PegaSysEng File: ReadTimeoutAcceptanceTest.java License: 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 #2
Source Project: ethsigner Author: PegaSysEng File: ConnectionTimeoutAcceptanceTest.java License: 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 #3
Source Project: ethsigner Author: PegaSysEng File: MultiKeyTransactionSigningAcceptanceTestBase.java License: 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 #4
Source Project: web3j Author: web3j File: RequestTest.java License: 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 #5
Source Project: ethsigner Author: PegaSysEng File: ValueTransferAcceptanceTest.java License: 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 #6
Source Project: ethsigner Author: PegaSysEng File: ValueTransferAcceptanceTest.java License: 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 #7
Source Project: ethsigner Author: PegaSysEng File: ValueTransferAcceptanceTest.java License: 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 #8
Source Project: ethsigner Author: PegaSysEng File: ValueTransferAcceptanceTest.java License: 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 #9
Source Project: ethsigner Author: PegaSysEng File: ReplayProtectionAcceptanceTest.java License: 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 #10
Source Project: ethsigner Author: PegaSysEng File: ValueTransferWithHashicorpAcceptanceTest.java License: 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 #11
Source Project: ethsigner Author: PegaSysEng File: ValueTransferWithAzureAcceptanceTest.java License: 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 #12
Source Project: web3j Author: web3j File: ClientTransactionManager.java License: 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 #13
Source Project: web3j Author: web3j File: RequestTest.java License: 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 #14
Source Project: etherscan-explorer Author: bing-chou File: DeployContractIT.java License: 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 #15
Source Project: web3j Author: web3j File: RequestTest.java License: 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 #16
Source Project: web3j Author: web3j File: GreeterContractIT.java License: 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 #17
Source Project: web3j_demo Author: matthiaszimmermann File: Web3jUtils.java License: Apache License 2.0 | 6 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 #18
Source Project: web3j Author: web3j File: RequestTest.java License: 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 #19
Source Project: etherscan-explorer Author: bing-chou File: RequestTest.java License: 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 #20
Source Project: ethsigner Author: PegaSysEng File: Eth.java License: Apache License 2.0 | 5 votes |
public String sendTransaction(final Transaction transaction) throws IOException { final EthSendTransaction response = jsonRpc.ethSendTransaction(transaction).send(); assertThat(response.getTransactionHash()).isNotEmpty(); assertThat(response.getError()).isNull(); return response.getTransactionHash(); }
Example #21
Source Project: web3j Author: web3j File: ClientTransactionManager.java License: Apache License 2.0 | 5 votes |
@Override public String sendCall(String to, String data, DefaultBlockParameter defaultBlockParameter) throws IOException { EthCall ethCall = web3j.ethCall( Transaction.createEthCallTransaction(getFromAddress(), to, data), defaultBlockParameter) .send(); assertCallNotReverted(ethCall); return ethCall.getValue(); }
Example #22
Source Project: ethsigner Author: PegaSysEng File: Transactions.java License: Apache License 2.0 | 5 votes |
public SignerResponse<JsonRpcErrorResponse> submitExceptional(final Transaction transaction) { try { failOnIOException(() -> eth.sendTransaction(transaction)); fail("Expecting exceptional response "); } catch (final ClientConnectionException e) { LOG.info("ClientConnectionException with message: " + e.getMessage()); return SignerResponse.fromError(e); } return null; }
Example #23
Source Project: eventeum Author: ConsenSys File: BaseIntegrationTest.java License: Apache License 2.0 | 5 votes |
@Before public void setUp() throws Exception { initRestTemplate(); this.web3j = Web3j.build(new HttpService("http://localhost:8545")); this.admin = Admin.build(new HttpService("http://localhost:8545")); this.web3j.ethSendTransaction(Transaction.createEtherTransaction( this.web3j.ethAccounts().send().getAccounts().get(0), this.web3j.ethGetTransactionCount( this.web3j.ethAccounts().send().getAccounts().get(0), DefaultBlockParameterName.fromString("latest") ).send().getTransactionCount(), BigInteger.valueOf(2000), BigInteger.valueOf(6721975), CREDS.getAddress(), new BigInteger("9460000000000000000")) ).send(); dummyEventFilterId = UUID.randomUUID().toString(); dummyEventNotOrderedFilterId = UUID.randomUUID().toString(); clearMessages(); }
Example #24
Source Project: web3j Author: web3j File: GreeterContractIT.java License: Apache License 2.0 | 5 votes |
private String callSmartContractFunction(Function function, String contractAddress) throws Exception { String encodedFunction = FunctionEncoder.encode(function); org.web3j.protocol.core.methods.response.EthCall response = web3j.ethCall( Transaction.createEthCallTransaction( ALICE.getAddress(), contractAddress, encodedFunction), DefaultBlockParameterName.LATEST) .sendAsync() .get(); return response.getValue(); }
Example #25
Source Project: alpha-wallet-android Author: AlphaWallet File: TransactionHandler.java License: MIT License | 5 votes |
private String makeEthCall(Transaction transaction) throws ExecutionException, InterruptedException { org.web3j.protocol.core.methods.response.EthCall ethCall = mWeb3.ethCall(transaction, DefaultBlockParameterName.LATEST) .sendAsync().get(); return ethCall.getValue(); }
Example #26
Source Project: web3j Author: web3j File: RawTransactionManager.java License: Apache License 2.0 | 5 votes |
@Override public String sendCall(String to, String data, DefaultBlockParameter defaultBlockParameter) throws IOException { EthCall ethCall = web3j.ethCall( Transaction.createEthCallTransaction(getFromAddress(), to, data), defaultBlockParameter) .send(); assertCallNotReverted(ethCall); return ethCall.getValue(); }
Example #27
Source Project: alpha-wallet-android Author: AlphaWallet File: TransactionHandler.java License: MIT License | 5 votes |
private String callSmartContractFunction( Function function, String contractAddress) throws Exception { String encodedFunction = FunctionEncoder.encode(function); return makeEthCall( org.web3j.protocol.core.methods.request.Transaction .createEthCallTransaction(null, contractAddress, encodedFunction)); }
Example #28
Source Project: web3j Author: web3j File: DeployContractIT.java License: Apache License 2.0 | 5 votes |
private String callSmartContractFunction(Function function, String contractAddress) throws Exception { String encodedFunction = FunctionEncoder.encode(function); org.web3j.protocol.core.methods.response.EthCall response = web3j.ethCall( Transaction.createEthCallTransaction( ALICE.getAddress(), contractAddress, encodedFunction), DefaultBlockParameterName.LATEST) .sendAsync() .get(); return response.getValue(); }
Example #29
Source Project: web3j Author: web3j File: HumanStandardTokenIT.java License: Apache License 2.0 | 5 votes |
private String callSmartContractFunction(Function function, String contractAddress) throws Exception { String encodedFunction = FunctionEncoder.encode(function); org.web3j.protocol.core.methods.response.EthCall response = web3j.ethCall( Transaction.createEthCallTransaction( ALICE.getAddress(), contractAddress, encodedFunction), DefaultBlockParameterName.LATEST) .sendAsync() .get(); return response.getValue(); }
Example #30
Source Project: Upchain-wallet Author: xilibi2003 File: FetchGasSettingsInteract.java License: GNU Affero General Public License v3.0 | 5 votes |
public BigInteger getTransactionGasLimit(Transaction transaction) { final Web3j web3j = Web3j.build(new HttpService(networkRepository.getDefaultNetwork().rpcServerUrl)); try { EthEstimateGas ethEstimateGas = web3j.ethEstimateGas(transaction).send(); if (ethEstimateGas.hasError()){ throw new RuntimeException(ethEstimateGas.getError().getMessage()); } return ethEstimateGas.getAmountUsed(); } catch (IOException e) { throw new RuntimeException("net error"); } }