I've been trying to send ethereum transaction which has been signed using Trust Wallet wallet-core v2 library. Everytime I'm receiving the error "Transaction has been reverted by the EVM". Below is the code, I'm using:
val signerInput = Ethereum.SigningInput.newBuilder().apply {
this.chainId = ByteString.copyFrom(BigInteger(chainValue).toByteArray()) //5A2,1442
this.gasPrice = BigInteger("d693a400", 16).toByteString()
this.gasLimit = BigInteger("5208", 16).toByteString()
this.toAddress = "addressHere"
this.transaction = Ethereum.Transaction.newBuilder().apply {
this.transfer = Ethereum.Transaction.Transfer.newBuilder().apply {
this.amount = BigInteger("0348bca5a16000", 16).toByteString()
}.build()
}.build()
this.privateKey = ByteString.copyFrom(walletPrivateKey.data())
this.nonce = BigInteger("0").toByteString()
}.build()
val signerOutput =
AnySigner.sign(signerInput, CoinType.ETHEREUM, Ethereum.SigningOutput.parser())
val outputSignature = signerOutput.encoded.toByteArray().toHexString()
Hex String method::
fun ByteArray.toHexString(withPrefix: Boolean = true): String {
val stringBuilder = StringBuilder()
if (withPrefix) {
stringBuilder.append("0x")
}
for (element in this) {
stringBuilder.append(String.format("%02x", element and 0xFF.toByte()))
}
return stringBuilder.toString()
}
Byte String::
fun BigInteger.toByteString(): ByteString {
return ByteString.copyFrom(this.toByteArray())
}
fun Long?.toHexString(): String {
return java.lang.Long.toHexString(this ?: 0L)
}