Skip to content

Backend Libraries

Kethereum is a Kotlin library created for Ethereum. It opts for a non-monolithic structure, empowering users to selectively integrate modules and thereby maintain a lean library footprint.

KEthereum gives the possibility to pick and choose the modules the developer need and keep the footprint of the library small this way. Some of the modules are:

  • eip155: TX signing with Simple replay attack protection
  • blockscout: BlockScout BlockExplorer helper functions
  • ERC20: Contract wrapper for the ERC20 Token standard
  • wallet: functions for keys from and to JSON wallet files

Implementation Example

  1. Create Gradle Kotlin project
  2. Setup build.gradle.kts file
    import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
    plugins {
    kotlin("jvm") version "1.8.21"
    application
    }
    group = "org.example"
    version = "1.0-SNAPSHOT"
    repositories {
    mavenCentral()
    maven("https://www.jitpack.io")
    }
    dependencies {
    implementation("com.github.komputing.kethereum:abi:0.86.0")
    implementation("com.github.komputing.kethereum:erc20:0.86.0")
    implementation("com.github.komputing.kethereum:model:0.86.0")
    implementation("com.github.komputing.kethereum:eip155:0.86.0")
    implementation("com.github.komputing.kethereum:erc681:0.86.0")
    implementation("com.github.komputing.kethereum:erc1450:0.86.0")
    implementation("com.github.komputing.kethereum:extensions_transactions:0.86.0")
    implementation("com.github.komputing.kethereum:flows:0.86.0")
    implementation("com.github.komputing.kethereum:rpc:0.86.0")
    implementation("com.github.komputing.kethereum:rpc_min3:0.86.0")
    implementation("com.github.komputing.kethereum:crypto:0.86.0")
    implementation("com.github.komputing.kethereum:keystore:0.86.0")
    implementation("com.github.komputing:khex:1.1.2")
    implementation("com.github.walleth.kethereum:extensions_transactions:0.86.0")
    implementation("com.github.walleth.kethereum:crypto_impl_bouncycastle:0.86.0")
    testImplementation(kotlin("test"))
    }
    tasks.test {
    useJUnitPlatform()
    }
    tasks.withType<KotlinCompile> {
    kotlinOptions.jvmTarget = "1.8"
    }
    application {
    mainClass.set("MainKt")
    }
  3. Contract Call
    import org.kethereum.model.Address
    import org.kethereum.model.ChainId
    import org.kethereum.model.createTransactionWithDefaults
    import org.kethereum.rpc.min3.getMin3RPC
    import org.kethereum.abi.EthereumABI
    import org.kethereum.crypto.toAddress
    import org.kethereum.eip155.signViaEIP155
    import org.kethereum.extensions.transactions.encode
    import java.math.BigInteger
    import org.komputing.khex.extensions.hexToByteArray
    import org.komputing.khex.extensions.toHexString
    import org.komputing.khex.model.HexString
    import org.kethereum.model.PrivateKey
    import org.kethereum.crypto.toECKeyPair
    import org.kethereum.rpc.EthereumRPCException
    import chains;
    fun main(args: Array<String>) {
    val privateKey = PrivateKey(HexString("your private key"))
    var keyPar = privateKey.toECKeyPair()
    val selected_chain = chains[ChainKey.nebula];
    val rpc_url = selected_chain!!.chainInfo!!.testnet!!.rpcUrl;
    val SKALE_CHAIN_RPC = listOf(
    rpc_url,
    rpc_url
    )
    //Your contract address
    val CONTRACT_ADDRESS = Address(selected_chain.chainInfo!!.testnet.contracts[0].address);
    //chain_id
    val chainID = ChainId(37084624)
    val rpc = getMin3RPC(SKALE_CHAIN_RPC)
    val txCount = rpc.getTransactionCount(keyPar.toAddress(), "latest");
    val address_mint_receiver = "address without the 0x";
    val tx = createTransactionWithDefaults(
    chain = chainID,
    to= CONTRACT_ADDRESS,
    from = keyPar.toAddress(),
    gasLimit = BigInteger("100000"),
    gasPrice = BigInteger("100000"),
    input = HexString("d2fe5e92000000000000000000000000$address_mint_receiver").hexToByteArray(), //hex of your contract method and input params
    nonce = txCount,
    value = BigInteger("0")
    );
    val tx_signed = tx.signViaEIP155(keyPar,chainID);
    val tx_ = tx.encode(tx_signed).toHexString()
    try {
    val result = rpc.sendRawTransaction(tx_)
    if (result == null) {
    println("Problem sending transaction")
    } else {
    println("sending tx OK ($result)")
    }
    } catch (rpcException: EthereumRPCException) {
    println("send tx error " + rpcException.message)
    }
    }

Additional KEthereum Documentation

Click here for the official documentation.