https://github.com/multiversx/mx-sdk-kotlin
MultiversX kotlin SDK for interacting with the MultiversX blockchain (in general) and Smart Contracts (in particular).
https://github.com/multiversx/mx-sdk-kotlin
Last synced: 8 months ago
JSON representation
MultiversX kotlin SDK for interacting with the MultiversX blockchain (in general) and Smart Contracts (in particular).
- Host: GitHub
- URL: https://github.com/multiversx/mx-sdk-kotlin
- Owner: multiversx
- License: gpl-3.0
- Created: 2021-05-27T12:42:20.000Z (about 5 years ago)
- Default Branch: main
- Last Pushed: 2021-10-22T10:10:14.000Z (over 4 years ago)
- Last Synced: 2024-04-01T15:08:42.520Z (about 2 years ago)
- Language: Kotlin
- Homepage:
- Size: 238 KB
- Stars: 8
- Watchers: 27
- Forks: 6
- Open Issues: 4
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
## [CHANGELOG](CHANGELOG.md)
## 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](#sample-app)).
## Usecases list
##### API
| Usecase | Endpoint |
| ------------- | ------------- |
| GetAccountUsecase | [GET address/:bech32Address](https://docs.elrond.com/sdk-and-tools/rest-api/addresses/#get-address) |
| GetAddressBalanceUsecase | [GET address/:bech32Address/balance](https://docs.elrond.com/sdk-and-tools/rest-api/addresses/#get-address-balance) |
| GetAddressNonceUsecase | [GET address/:bech32Address/nonce](https://docs.elrond.com/sdk-and-tools/rest-api/addresses/#get-address-nonce) |
| GetAddressTransactionsUsecase | [GET address/:bech32Address/transactions](https://docs.elrond.com/sdk-and-tools/rest-api/addresses/#get-address-transactions) |
| GetTransactionInfoUsecase | [GET transaction/:txHash](https://docs.elrond.com/sdk-and-tools/rest-api/transactions/#get-transaction) |
| GetTransactionStatusUsecase | [GET transaction/:txHash/status](https://docs.elrond.com/sdk-and-tools/rest-api/transactions/#get-transaction-status) |
| SendTransactionUsecase | [POST transaction/send](https://docs.elrond.com/sdk-and-tools/rest-api/transactions/#send-transaction) |
| EstimateCostOfTransactionUsecase | [POST transaction/cost](https://docs.elrond.com/sdk-and-tools/rest-api/transactions/#estimate-cost-of-transaction) |
| GetNetworkConfigUsecase | [GET network/config](https://docs.elrond.com/sdk-and-tools/rest-api/network/#get-network-configuration) |
| QueryContractUsecase | [POST vm-values/query](https://docs.elrond.com/sdk-and-tools/rest-api/virtual-machine/#compute-output-of-pure-function) |
| QueryContractHexUsecase | [POST vm-values/hex](https://docs.elrond.com/sdk-and-tools/rest-api/virtual-machine/#compute-hex-output-of-pure-function) |
| QueryContractStringUsecase | [POST vm-values/string](https://docs.elrond.com/sdk-and-tools/rest-api/virtual-machine/#compute-string-output-of-pure-function) |
| QueryContractIntUsecase | [POST vm-values/int](https://docs.elrond.com/sdk-and-tools/rest-api/virtual-machine/#get-integer-output-of-pure-function) |
#### Contract
| Usecase | Description |
| ------------- | ------------- |
| CallContractUsecase | Interact with a Smart Contract (execute function): equivalent to [`erdpy contract call`](https://docs.elrond.com/sdk-and-tools/erdpy/erdpy/) |
##### 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`](https://docs.elrond.com/sdk-and-tools/erdpy/erdpy/) |
| GetDnsRegistrationCostUsecase | Gets the registration cost from a DNS smart contract: equivalent to [`erdpy dns registration-cost`](https://docs.elrond.com/sdk-and-tools/erdpy/erdpy/) |
| 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](https://github.com/Alexandre-saddour/ElrondKotlinSampleApp)