Skip to content

Elrond kotlin SDK for interacting with the Elrond Network (in general) and Smart Contracts (in particular).

License

Notifications You must be signed in to change notification settings

Alexandre-saddour/elrond-sdk-erdkotlin

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

29 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Elrond Kotlin SDK

This is the kotlin implementation of Elrond SDK

This project was primarily designed for Android but is also compatible with any Kotlin-friendly app since it doesn't use the Android SDK

Usage

This SDK is built with the clean architecture principles.
Interaction are done through usecases

Here is an example for sending a transaction.

// Create a wallet from mnemonics
val wallet = Wallet.createFromMnemonic(..., 0)

// Get information related to this address (ie: balance and nonce)
val account = ErdSdk.getAccountUsecase().execute(Address.fromHex(wallet.publicKeyHex))

// Get the network informations
val networkConfig = ErdSdk.getNetworkConfigUsecase().execute()

// Create the transaction object
val transaction = Transaction(
    sender = account.address,
    receiver = Address.fromHex(...),
    value = 1000000000000000000.toBigInteger(), // 1 xEGLD
    data = "Elrond rocks !",
    chainID = networkConfig.chainID,
    gasPrice = networkConfig.minGasPrice,
    gasLimit = networkConfig.minGasLimit,
    nonce = account.nonce
)

// Send transaction.
// Signature is handled internally
val sentTransaction = ErdSdk.sendTransactionUsecase().execute(transaction, wallet)
Log.d("Transaction", "tx:${sentTransaction.txHash}")

In a real world example, the usescases would be injected
The sample application showcase how to do it on Android with Hilt framework (see the Sample App).

Usecases list

API
Usecase Endpoint
GetAccountUsecase GET address/:bech32Address
GetAddressBalanceUsecase GET address/:bech32Address/balance
GetAddressNonceUsecase GET address/:bech32Address/nonce
GetAddressTransactionsUsecase GET address/:bech32Address/transactions
GetTransactionInfoUsecase GET transaction/:txHash
GetTransactionStatusUsecase GET transaction/:txHash/status
SendTransactionUsecase POST transaction/send
EstimateCostOfTransactionUsecase POST transaction/cost
GetNetworkConfigUsecase GET network/config
QuerySmartContractUsecase POST vm-values/query
DNS
Usecase Description
RegisterDnsUsecase erdpy dns register
GetDnsRegistrationCostUsecase erdpy dns registration-cost
CheckUsernameUsecase Can be useful for validating a text field before calling RegisterDnsUsecase

Configuration

// default value is ProviderUrl.DevNet
ErdSdk.setNetwork(ProviderUrl.MainNet)

// configure the OkHttpClient
ErdSdk.elrondHttpClientBuilder.apply {
    addInterceptor(HttpLoggingInterceptor())
}

Build

The SDK is not yet uploaded to a maven repository
You can build the jar from the sources by running mvn package

Sample App

For a complete example you can checkout this sample application

About

Elrond kotlin SDK for interacting with the Elrond Network (in general) and Smart Contracts (in particular).

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Kotlin 100.0%