本文整理了Java中org.web3j.utils.Numeric.toHexString()
方法的一些代码示例,展示了Numeric.toHexString()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Numeric.toHexString()
方法的具体详情如下:
包路径:org.web3j.utils.Numeric
类名称:Numeric
方法名:toHexString
暂无
代码示例来源:origin: web3j/web3j
public static String toHexString(byte[] input) {
return toHexString(input, 0, input.length, true);
}
代码示例来源:origin: web3j/web3j
public static String toHexStringNoPrefix(byte[] input) {
return toHexString(input, 0, input.length, false);
}
代码示例来源:origin: web3j/web3j
public String asString() {
return Numeric.toHexString(value);
}
代码示例来源:origin: web3j/web3j
static String buildMethodId(String methodSignature) {
byte[] input = methodSignature.getBytes();
byte[] hash = Hash.sha3(input);
return Numeric.toHexString(hash).substring(0, 10);
}
}
代码示例来源:origin: web3j/web3j
/**
* Keccak-256 hash function that operates on a UTF-8 encoded String.
*
* @param utf8String UTF-8 encoded string
* @return hash value as hex encoded string
*/
public static String sha3String(String utf8String) {
return Numeric.toHexString(sha3(utf8String.getBytes(StandardCharsets.UTF_8)));
}
代码示例来源:origin: web3j/web3j
/**
* Utility method to provide the transaction hash for a given transaction.
*
* @param rawTransaction we wish to send
* @param chainId of the intended chain
* @param credentials of the sender
* @return transaction hash as a hex encoded string
*/
public static String generateTransactionHashHexEncoded(
RawTransaction rawTransaction, byte chainId, Credentials credentials) {
return Numeric.toHexString(generateTransactionHash(rawTransaction, chainId, credentials));
}
}
代码示例来源:origin: web3j/web3j
public static String buildEventSignature(String methodSignature) {
byte[] input = methodSignature.getBytes();
byte[] hash = Hash.sha3(input);
return Numeric.toHexString(hash);
}
}
代码示例来源:origin: web3j/web3j
/**
* Utility method to provide the transaction hash for a given transaction.
*
* @param rawTransaction we wish to send
* @param credentials of the sender
* @return transaction hash as a hex encoded string
*/
public static String generateTransactionHashHexEncoded(
RawTransaction rawTransaction, Credentials credentials) {
return Numeric.toHexString(generateTransactionHash(rawTransaction, credentials));
}
代码示例来源:origin: web3j/web3j
public static String nameHash(String ensName) {
String normalisedEnsName = normalise(ensName);
return Numeric.toHexString(nameHash(normalisedEnsName.split("\\.")));
}
代码示例来源:origin: web3j/web3j
/**
* Keccak-256 hash function.
*
* @param hexInput hex encoded input data with optional 0x prefix
* @return hash value as hex encoded string
*/
public static String sha3(String hexInput) {
byte[] bytes = Numeric.hexStringToByteArray(hexInput);
byte[] result = sha3(bytes);
return Numeric.toHexString(result);
}
代码示例来源:origin: web3j/web3j
public String sign(RawTransaction rawTransaction) {
byte[] signedMessage;
if (chainId > ChainId.NONE) {
signedMessage = TransactionEncoder.signMessage(rawTransaction, chainId, credentials);
} else {
signedMessage = TransactionEncoder.signMessage(rawTransaction, credentials);
}
return Numeric.toHexString(signedMessage);
}
代码示例来源:origin: web3j/web3j
public static String generateContractAddress(String address, BigInteger nonce) {
byte[] result = generateContractAddress(Numeric.hexStringToByteArray(address), nonce);
return Numeric.toHexString(result);
}
}
代码示例来源:origin: web3j/web3j
@Test
public void testToHexString() {
assertThat(Numeric.toHexString(new byte[] {}), is("0x"));
assertThat(Numeric.toHexString(new byte[] { 0x1 }), is("0x01"));
assertThat(Numeric.toHexString(HEX_RANGE_ARRAY), is(HEX_RANGE_STRING));
}
代码示例来源:origin: web3j/web3j
@Test
public void testSignMessage() {
byte[] signedMessage = TransactionEncoder.signMessage(
createEtherTransaction(), SampleKeys.CREDENTIALS);
String hexMessage = Numeric.toHexString(signedMessage);
assertThat(hexMessage,
is("0xf85580010a840add5355887fffffffffffffff80"
+ "1c"
+ "a046360b50498ddf5566551ce1ce69c46c565f1f478bb0ee680caf31fbc08ab727"
+ "a01b2f1432de16d110407d544f519fc91b84c8e16d3b6ec899592d486a94974cd0"));
}
代码示例来源:origin: web3j/web3j
@Test
public void testTransferEther() throws Exception {
BigInteger nonce = getNonce(ALICE.getAddress());
RawTransaction rawTransaction = createEtherTransaction(
nonce, BOB.getAddress());
byte[] signedMessage = TransactionEncoder.signMessage(rawTransaction, ALICE);
String hexValue = Numeric.toHexString(signedMessage);
EthSendTransaction ethSendTransaction =
web3j.ethSendRawTransaction(hexValue).sendAsync().get();
String transactionHash = ethSendTransaction.getTransactionHash();
assertFalse(transactionHash.isEmpty());
TransactionReceipt transactionReceipt =
waitForTransactionReceipt(transactionHash);
assertThat(transactionReceipt.getTransactionHash(), is(transactionHash));
}
代码示例来源:origin: web3j/web3j
@Test
public void testDeploySmartContract() throws Exception {
BigInteger nonce = getNonce(ALICE.getAddress());
RawTransaction rawTransaction = createSmartContractTransaction(nonce);
byte[] signedMessage = TransactionEncoder.signMessage(rawTransaction, ALICE);
String hexValue = Numeric.toHexString(signedMessage);
EthSendTransaction ethSendTransaction =
web3j.ethSendRawTransaction(hexValue).sendAsync().get();
String transactionHash = ethSendTransaction.getTransactionHash();
assertFalse(transactionHash.isEmpty());
TransactionReceipt transactionReceipt =
waitForTransactionReceipt(transactionHash);
assertThat(transactionReceipt.getTransactionHash(), is(transactionHash));
assertFalse("Contract execution ran out of gas",
rawTransaction.getGasLimit().equals(transactionReceipt.getGasUsed()));
}
代码示例来源:origin: web3j/web3j
private String execute(
Credentials credentials, Function function, String contractAddress) throws Exception {
BigInteger nonce = getNonce(credentials.getAddress());
String encodedFunction = FunctionEncoder.encode(function);
RawTransaction rawTransaction = RawTransaction.createTransaction(
nonce,
GAS_PRICE,
GAS_LIMIT,
contractAddress,
encodedFunction);
byte[] signedMessage = TransactionEncoder.signMessage(rawTransaction, credentials);
String hexValue = Numeric.toHexString(signedMessage);
EthSendTransaction transactionResponse = web3j.ethSendRawTransaction(hexValue)
.sendAsync().get();
return transactionResponse.getTransactionHash();
}
代码示例来源: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
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();
}
代码示例来源: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());
}
内容来源于网络,如有侵权,请联系作者删除!