secretk
A Kotlin multiplatform Encryption and REST client for Secret Network utilizing gRPC gateway endpoints.
Supported Features:
- Contract Queries
- Simulate Contract Execution To Estimate Gas
- Contract Execution (MsgExecuteContract)
- Contract Code Upload (MsgStoreCode)
- Contract Instantiate (MsgInstantiateContract)
- Contract Migrate (MsgMigrateContract)
- Contract Update Admin (MsgUpdateAdmin)
- Contract Clear Admin (MsgClearAdmin)
- Bank Send (MsgSend)
- Web: Delegate signing transactions to Kepler or Metamask browser wallets
Supported Targets:
- JVM
- js
- wasmJs
- iOS, tvOS, watchOS
- macOS
- linux (x64)
- windows (x64)
Setup
Gradle
dependencies {
implementation("io.eqoty.secretk:client:$latest")
}
Swift Package Manager
you need to declare your dependency in your Package.swift:
.package(url: "https://github.com/eqoty-labs/secretk.git", from: "latest"),
Samples
- Secret Contract Template using secretk for Integration Testing
- Compose UI sample project
- Swift sample project
Useage
Kotlin
Create SigningCosmWasmClient
val grpcGatewayEndpoint = "http://secretnetworkendpoint.com:1337"
val mnemonic = ""
val wallet = DirectSigningWallet(mnemonic)
val client = SigningCosmWasmClient.init(
grpcGatewayEndpoint,
wallet
)
Query Contract
val contractAddress = "secret1lz4m46vpdn8f2aj8yhtnexus40663udv7hhprm"
val contractInfoQuery = """{"contract_info": {}}"""
val contractInfo = client.queryContractSmart(contractAddress, contractInfoQuery)
println("nft contract info response: $contractInfo")
Simulate Execute + Execute + Query Contract(Generate and use viewing key for query)
Bank Send Tx
val client = SigningCosmWasmClient.init(
grpcGatewayEndpoint,
accAddress,
wallet
)
val toAccount = wallet.addAccount()
val amountToSend = listOf(Coin(10, "uscrt"))
val msgs = listOf(
MsgSend(
fromAddress = accAddress,
toAddress = toAccount.publicData.address,
amount = amountToSend
)
)
val simulate = client.simulate(msgs)
val gasLimit = (simulate.gasUsed.toDouble() * 1.1).toInt()
client.execute(
msgs,
txOptions = TxOptions(gasLimit = gasLimit)
)
recipientBalance = client.getBalance(toAccount.publicData.address).balances
println()
Swift
Create SigningCosmWasmClient
let wallet = DirectSigningWallet(mnemonic: mnemonic)
let SigningCosmWasmClientCompanion = SigningCosmWasmClient.Companion()
let client = try! await ..doInit()(
apiUrl: grpcGatewayEndpoint,
wallet: wallet,
enigmaUtils: ,
broadcastMode: .,
chainId:
)
Query Contract
let contractAddress = "secret1lz4m46vpdn8f2aj8yhtnexus40663udv7hhprm"
let contractInfoQuery = #"{"contract_info": {}}"#
let contractInfo = try! await client.queryContractSmart(
contractAddress: contractAddress,
queryMsg: contractInfoQuery,
contractCodeHash: nil)
print("nft contract info response: \(contractInfo)")
Simulate Execute + Execute + Query Contract(Generate and use viewing key for query)
Credits:
Based on the work of: