Skip to content

klepto/kweb3

Repository files navigation

kweb3

Ethereum interface for Kotlin and Java

Maven Central javadoc License

Getting Started

In this example, we are obtaining the WETH balance of a wallet address:

var client = new Web3Client(PublicNode.ETHEREUM);
var contract = client.contract(Erc20.class, "0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2");
var result = contract.balanceOf(walletAddress).get();
System.out.println(result);

Or in Kotlin using kweb3-kotlin dependency:

val client = CoroutineWeb3Client(PublicNode.ETHEREUM)
val contract = client.contract<Erc20>("0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2")
runBlocking {
    val result = contract.balanceOf(walletAddress)
    println(result)
}

Smart Contracts

Unlike competing libraries, kweb3 does not generate code from ABI json.
Instead, to interact with smart contracts, simply define their function signatures:

Java

public interface Erc20 extends Web3Contract {
    @View
    Web3Result<EthUint> balanceOf(EthAddress account);
}

Kotlin (for coroutine support)

interface Erc20 : Web3Contract {
    @View
    suspend fun balanceOf(account: EthAddress): EthUint
}

Note

This README serves as a placeholder and does not contain working hyperlinks yet.

About

Ethereum interface for Kotlin and Java

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published