Skip to content

MultiversX kotlin SDK for interacting with the MultiversX blockchain (in general) and Smart Contracts (in particular).

License

Notifications You must be signed in to change notification settings

multiversx/mx-sdk-kotlin

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

46 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
QueryContractUsecase POST vm-values/query
QueryContractHexUsecase POST vm-values/hex
QueryContractStringUsecase POST vm-values/string
QueryContractIntUsecase POST vm-values/int

Contract

Usecase Description
CallContractUsecase Interact with a Smart Contract (execute function): equivalent to erdpy contract call
DNS
Usecase Description
RegisterDnsUsecase Send a register transaction to the appropriate DNS contract from given user and with given name: equivalent to erdpy dns register
GetDnsRegistrationCostUsecase Gets the registration cost from a DNS smart contract: equivalent to 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

MultiversX kotlin SDK for interacting with the MultiversX blockchain (in general) and Smart Contracts (in particular).

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 3

  •  
  •  
  •  

Languages