org.web3j.crypto.Credentials Java Examples
The following examples show how to use
org.web3j.crypto.Credentials.
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: Contract.java From web3j with Apache License 2.0 | 6 votes |
public static <T extends Contract> RemoteCall<T> deployRemoteCall( Class<T> type, Web3j web3j, Credentials credentials, ContractGasProvider contractGasProvider, String binary, String encodedConstructor, BigInteger value) { return new RemoteCall<>( () -> deploy( type, web3j, credentials, contractGasProvider, binary, encodedConstructor, value)); }
Example #2
Source File: HumanStandardTokenIT.java From etherscan-explorer with GNU General Public License v3.0 | 6 votes |
private String createContract( Credentials credentials, BigInteger initialSupply) throws Exception { String createTransactionHash = sendCreateContractTransaction(credentials, initialSupply); assertFalse(createTransactionHash.isEmpty()); TransactionReceipt createTransactionReceipt = waitForTransactionReceipt(createTransactionHash); assertThat(createTransactionReceipt.getTransactionHash(), is(createTransactionHash)); assertFalse("Contract execution ran out of gas", createTransactionReceipt.getGasUsed().equals(GAS_LIMIT)); String contractAddress = createTransactionReceipt.getContractAddress(); assertNotNull(contractAddress); return contractAddress; }
Example #3
Source File: JsonRpc2_0Besu.java From web3j with Apache License 2.0 | 6 votes |
public Request<?, EthSendTransaction> privOnChainSetGroupLockState( final Base64String privacyGroupId, final Credentials credentials, final Base64String enclaveKey, final Boolean lock) throws IOException { BigInteger transactionCount = privGetTransactionCount(credentials.getAddress(), privacyGroupId) .send() .getTransactionCount(); String lockContractCall = OnChainPrivacyTransactionBuilder.getEncodedSingleParamFunction( lock ? "lock" : "unlock"); String lockPrivacyGroupTransactionPayload = OnChainPrivacyTransactionBuilder.buildOnChainPrivateTransaction( privacyGroupId, credentials, enclaveKey, transactionCount, lockContractCall); return eeaSendRawTransaction(lockPrivacyGroupTransactionPayload); }
Example #4
Source File: Contract.java From web3j with Apache License 2.0 | 6 votes |
public static <T extends Contract> RemoteCall<T> deployRemoteCall( Class<T> type, Web3j web3j, Credentials credentials, BigInteger gasPrice, BigInteger gasLimit, String binary, String encodedConstructor) { return deployRemoteCall( type, web3j, credentials, gasPrice, gasLimit, binary, encodedConstructor, BigInteger.ZERO); }
Example #5
Source File: OnChainPrivacyGroupManagementProxy.java From besu with Apache License 2.0 | 6 votes |
public static RemoteCall<OnChainPrivacyGroupManagementProxy> deploy( Web3j web3j, Credentials credentials, ContractGasProvider contractGasProvider, String _implementation) { String encodedConstructor = FunctionEncoder.encodeConstructor( Arrays.<Type>asList(new org.web3j.abi.datatypes.Address(160, _implementation))); return deployRemoteCall( OnChainPrivacyGroupManagementProxy.class, web3j, credentials, contractGasProvider, BINARY, encodedConstructor); }
Example #6
Source File: PrivateTransactionEncoderTest.java From web3j with Apache License 2.0 | 6 votes |
@Test public void testSignLegacyTransaction() { final String expected = "0xf8d4808203e8832dc6c094627306090abab3a6e1400e9345bc60c78a8bef578080820fe8a0e0b547d71d7a23d52382288b3a2a5a1610e0b504c404cc5009d7ada97d9015b2a076e997a83856d876fa2397b74510890eea3b73ffeda33daa4188120dac42d62fa0035695b4cc4b0941e60551d7a19cf30603db5bfc23e5ac43a56f57f25f75486af842a0035695b4cc4b0941e60551d7a19cf30603db5bfc23e5ac43a56f57f25f75486aa02a8d9b56a0fe9cd94d60be4413bcb721d3a7be27ed8e28b3a6346df874ee141b8a72657374726963746564"; final RawPrivateTransaction privateTransactionCreation = new RawPrivateTransaction( BigInteger.ZERO, BigInteger.valueOf(1000), BigInteger.valueOf(3000000), "0x627306090abab3a6e1400e9345bc60c78a8bef57", "0x", MOCK_ENCLAVE_KEY, MOCK_PRIVATE_FOR, null, RESTRICTED); final long chainId = 2018; final String privateKey = "8f2a55949038a9610f50fb23b5883af3b4ecb3c3bb792cbcefbd1542c692be63"; final Credentials credentials = Credentials.create(privateKey); final String privateRawTransaction = Numeric.toHexString( PrivateTransactionEncoder.signMessage( privateTransactionCreation, chainId, credentials)); assertEquals(expected, privateRawTransaction); }
Example #7
Source File: Contract.java From web3j with Apache License 2.0 | 6 votes |
public static <T extends Contract> RemoteCall<T> deployRemoteCall( Class<T> type, Web3j web3j, Credentials credentials, ContractGasProvider contractGasProvider, String binary, String encodedConstructor) { return new RemoteCall<>( () -> deploy( type, web3j, credentials, contractGasProvider, binary, encodedConstructor, BigInteger.ZERO)); }
Example #8
Source File: EventEmitter.java From besu with Apache License 2.0 | 5 votes |
@Deprecated public static RemoteCall<EventEmitter> deploy( final Web3j web3j, final Credentials credentials, final BigInteger gasPrice, final BigInteger gasLimit) { return deployRemoteCall(EventEmitter.class, web3j, credentials, gasPrice, gasLimit, BINARY, ""); }
Example #9
Source File: RevertReason.java From besu with Apache License 2.0 | 5 votes |
@Deprecated public static RemoteCall<RevertReason> deploy( final Web3j web3j, final Credentials credentials, final BigInteger gasPrice, final BigInteger gasLimit) { return deployRemoteCall(RevertReason.class, web3j, credentials, gasPrice, gasLimit, BINARY, ""); }
Example #10
Source File: EventEmitter.java From besu with Apache License 2.0 | 5 votes |
@Deprecated public static EventEmitter load( final String contractAddress, final Web3j web3j, final Credentials credentials, final BigInteger gasPrice, final BigInteger gasLimit) { return new EventEmitter(contractAddress, web3j, credentials, gasPrice, gasLimit); }
Example #11
Source File: SendingToken.java From Android-Wallet-Token-ERC20 with Apache License 2.0 | 5 votes |
public SendingToken(Web3j web3j, Credentials credentials, String valueGasPrice, String valueGasLimit){ mWeb3j = web3j; mCredentials = credentials; fromAddress = credentials.getAddress(); mValueGasPrice = valueGasPrice; mValueGasLimit = valueGasLimit; }
Example #12
Source File: HumanStandardToken.java From web3j with Apache License 2.0 | 5 votes |
public static RemoteCall<HumanStandardToken> deploy(Web3j web3j, Credentials credentials, ContractGasProvider contractGasProvider, BigInteger _initialAmount, String _tokenName, BigInteger _decimalUnits, String _tokenSymbol) { String encodedConstructor = FunctionEncoder.encodeConstructor(Arrays.<Type>asList(new org.web3j.abi.datatypes.generated.Uint256(_initialAmount), new org.web3j.abi.datatypes.Utf8String(_tokenName), new org.web3j.abi.datatypes.generated.Uint8(_decimalUnits), new org.web3j.abi.datatypes.Utf8String(_tokenSymbol))); return deployRemoteCall(HumanStandardToken.class, web3j, credentials, contractGasProvider, BINARY, encodedConstructor); }
Example #13
Source File: WalletManager.java From guarda-android-wallets with GNU General Public License v3.0 | 5 votes |
public void restoreFromBlock2(String privateKey, final Runnable callback){ credentials = Credentials.create(privateKey); WalletCreationTask2 task = new WalletCreationTask2(new WalletCreationCallback() { @Override public void onWalletCreated(WalletFile walletFile) { callback.run(); } }, credentials.getEcKeyPair()); task.execute(BLOCK); }
Example #14
Source File: WalletManager.java From guarda-android-wallets with GNU General Public License v3.0 | 5 votes |
public void restoreFromBlock2(String privateKey, final Runnable callback) { credentials = Credentials.create(privateKey); WalletCreationTask2 task = new WalletCreationTask2(new WalletCreationCallback() { @Override public void onWalletCreated(WalletFile walletFile) { callback.run(); } }, credentials.getEcKeyPair()); task.execute(BLOCK); }
Example #15
Source File: SimpleStorage.java From ethsigner with Apache License 2.0 | 5 votes |
protected SimpleStorage( String contractAddress, Web3j web3j, Credentials credentials, ContractGasProvider contractGasProvider) { super(BINARY, contractAddress, web3j, credentials, contractGasProvider); }
Example #16
Source File: HumanStandardTokenIT.java From etherscan-explorer with GNU General Public License v3.0 | 5 votes |
private String sendCreateContractTransaction( Credentials credentials, BigInteger initialSupply) throws Exception { BigInteger nonce = getNonce(credentials.getAddress()); String encodedConstructor = FunctionEncoder.encodeConstructor( Arrays.asList( new Uint256(initialSupply), new Utf8String("web3j tokens"), new Uint8(BigInteger.TEN), new Utf8String("w3j$"))); RawTransaction rawTransaction = RawTransaction.createContractTransaction( nonce, GAS_PRICE, GAS_LIMIT, BigInteger.ZERO, getHumanStandardTokenBinary() + encodedConstructor); byte[] signedMessage = TransactionEncoder.signMessage(rawTransaction, credentials); String hexValue = Numeric.toHexString(signedMessage); EthSendTransaction transactionResponse = web3j.ethSendRawTransaction(hexValue) .sendAsync().get(); return transactionResponse.getTransactionHash(); }
Example #17
Source File: SimpleStorage.java From ethsigner with Apache License 2.0 | 5 votes |
public static SimpleStorage load( String contractAddress, Web3j web3j, Credentials credentials, ContractGasProvider contractGasProvider) { return new SimpleStorage(contractAddress, web3j, credentials, contractGasProvider); }
Example #18
Source File: OnChainPrivacyGroupManagementInterface.java From besu with Apache License 2.0 | 5 votes |
@Deprecated protected OnChainPrivacyGroupManagementInterface( String contractAddress, Web3j web3j, Credentials credentials, BigInteger gasPrice, BigInteger gasLimit) { super(BINARY, contractAddress, web3j, credentials, gasPrice, gasLimit); }
Example #19
Source File: EthereumUtils.java From jbpm-work-items with Apache License 2.0 | 5 votes |
public static String deployContract(Credentials credentials, Web3j web3j, String contractBinary, int toSendEther, boolean waitForReceipt, int sleepDuration, int attempts) throws Exception { BigInteger depositEtherAmountToSend = BigInteger.valueOf(toSendEther); RawTransaction rawTransaction = RawTransaction.createContractTransaction( getNextNonce(credentials.getAddress(), web3j), DEFAULT_GAS_PRICE, DEFAULT_GAS_LIMIT, depositEtherAmountToSend, contractBinary); byte[] signedMessage = TransactionEncoder.signMessage(rawTransaction, credentials); String hexValue = Numeric.toHexString(signedMessage); EthSendTransaction ethSendTransaction = web3j.ethSendRawTransaction(hexValue).sendAsync().get(); if (waitForReceipt) { TransactionReceipt transReceipt = waitForTransactionReceipt( ethSendTransaction.getTransactionHash(), sleepDuration, attempts, web3j ); if (transReceipt != null) { return transReceipt.getContractAddress(); } } // we dont have a contract address logger.warn("Unable to retrieve contract address."); return null; }
Example #20
Source File: RevertReason.java From besu with Apache License 2.0 | 5 votes |
public static RevertReason load( final String contractAddress, final Web3j web3j, final Credentials credentials, final ContractGasProvider contractGasProvider) { return new RevertReason(contractAddress, web3j, credentials, contractGasProvider); }
Example #21
Source File: RevertReason.java From besu with Apache License 2.0 | 5 votes |
public static RemoteCall<RevertReason> deploy( final Web3j web3j, final Credentials credentials, final ContractGasProvider contractGasProvider) { return deployRemoteCall( RevertReason.class, web3j, credentials, contractGasProvider, BINARY, ""); }
Example #22
Source File: EventEmitter.java From besu with Apache License 2.0 | 5 votes |
protected EventEmitter( final String contractAddress, final Web3j web3j, final Credentials credentials, final ContractGasProvider contractGasProvider) { super(BINARY, contractAddress, web3j, credentials, contractGasProvider); }
Example #23
Source File: HumanStandardTokenIT.java From web3j with Apache License 2.0 | 5 votes |
private void sendTransferTokensTransaction( Credentials credentials, String to, String contractAddress, BigInteger qty) throws Exception { Function function = transfer(to, qty); String functionHash = execute(credentials, function, contractAddress); TransactionReceipt transferTransactionReceipt = waitForTransactionReceipt(functionHash); assertEquals(transferTransactionReceipt.getTransactionHash(), (functionHash)); List<Log> logs = transferTransactionReceipt.getLogs(); assertFalse(logs.isEmpty()); Log log = logs.get(0); // verify the event was called with the function parameters List<String> topics = log.getTopics(); assertEquals(topics.size(), (3)); Event transferEvent = transferEvent(); // check function signature - we only have a single topic our event signature, // there are no indexed parameters in this example String encodedEventSignature = EventEncoder.encode(transferEvent); assertEquals(topics.get(0), (encodedEventSignature)); assertEquals(new Address(topics.get(1)), (new Address(credentials.getAddress()))); assertEquals(new Address(topics.get(2)), (new Address(to))); // verify qty transferred List<Type> results = FunctionReturnDecoder.decode( log.getData(), transferEvent.getNonIndexedParameters()); assertEquals(results, (Collections.singletonList(new Uint256(qty)))); }
Example #24
Source File: HumanStandardToken.java From client-sdk-java with Apache License 2.0 | 5 votes |
public static RemoteCall<HumanStandardToken> deploy(Web3j web3j, Credentials credentials, GasProvider contractGasProvider, BigInteger _initialAmount, String _tokenName, BigInteger _decimalUnits, String _tokenSymbol) { String encodedConstructor = FunctionEncoder.encodeConstructor( Arrays.<Type>asList(new org.web3j.abi.datatypes.generated.Uint256(_initialAmount), new org.web3j.abi.datatypes.Utf8String(_tokenName), new org.web3j.abi.datatypes.generated.Uint8(_decimalUnits), new org.web3j.abi.datatypes.Utf8String(_tokenSymbol))); return deployRemoteCall(HumanStandardToken.class, web3j, credentials, contractGasProvider, BINARY, encodedConstructor); }
Example #25
Source File: CrossContractReader.java From besu with Apache License 2.0 | 5 votes |
public static RemoteCall<CrossContractReader> deploy( final Web3j web3j, final Credentials credentials, final ContractGasProvider contractGasProvider) { return deployRemoteCall( CrossContractReader.class, web3j, credentials, contractGasProvider, BINARY, ""); }
Example #26
Source File: Contract.java From etherscan-explorer with GNU General Public License v3.0 | 5 votes |
public static <T extends Contract> RemoteCall<T> deployRemoteCall( Class<T> type, Web3j web3j, Credentials credentials, BigInteger gasPrice, BigInteger gasLimit, String binary, String encodedConstructor, BigInteger value) { return new RemoteCall<>(() -> deploy( type, web3j, credentials, gasPrice, gasLimit, binary, encodedConstructor, value)); }
Example #27
Source File: Contract.java From client-sdk-java with Apache License 2.0 | 5 votes |
@Deprecated protected Contract(String contractBinary, String contractAddress, Web3j web3j, Credentials credentials, BigInteger gasPrice, BigInteger gasLimit) { this(contractBinary, contractAddress, web3j, new RawTransactionManager(web3j, credentials), gasPrice, gasLimit); }
Example #28
Source File: ContractTest.java From web3j with Apache License 2.0 | 5 votes |
public TestContract( String contractAddress, Web3j web3j, Credentials credentials, ContractGasProvider contractGasProvider) { super(TEST_CONTRACT_BINARY, contractAddress, web3j, credentials, contractGasProvider); }
Example #29
Source File: WalletManager.java From guarda-android-wallets with GNU General Public License v3.0 | 5 votes |
private void restoreWalletFromFile(String walletPath, String pass, WalletCreationCallback callback) { Credentials credentials = null; try { credentials = WalletUtils.loadCredentials(pass, walletPath); } catch (IOException | CipherException e) { e.printStackTrace(); } if (credentials != null) { ECKeyPair keyPair = credentials.getEcKeyPair(); WalletCreationTask task = new WalletCreationTask(callback, keyPair); task.execute(pass); } }
Example #30
Source File: DepositContract.java From teku with Apache License 2.0 | 5 votes |
@Deprecated protected DepositContract( String contractAddress, Web3j web3j, Credentials credentials, BigInteger gasPrice, BigInteger gasLimit) { super(BINARY, contractAddress, web3j, credentials, gasPrice, gasLimit); }