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)
}
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
}
This README serves as a placeholder and does not contain working hyperlinks yet.