Skip to main content

Documentation Index

Fetch the complete documentation index at: https://docs.polygon.technology/llms.txt

Use this file to discover all available pages before exploring further.

All wallet operations require a selected wallet.
val walletAddress = requireNotNull(client.wallet.walletAddress) {
    "No wallet selected"
}

Supported Networks

Use the SDK network registry when passing network to wallet and indexer calls.
import com.omsclient.kotlin_sdk.Network
import com.omsclient.kotlin_sdk.findNetworkById
import com.omsclient.kotlin_sdk.findNetworkByName

val amoy = findNetworkById(80002) ?: Network.AMOY
val polygon = findNetworkByName("polygon")

println("${amoy.displayName} ${polygon?.id}")

for (network in client.supportedNetworks) {
    println("${network.id} ${network.displayName} ${network.nativeTokenSymbol}")
}
Parameters findNetworkById takes a numeric chain ID. findNetworkByName takes a registry name such as polygon, amoy, or base-sepolia. Returns client.supportedNetworks returns every Network supported by the SDK build. Top-level supportedNetworks returns the same list. Lookup helpers return Network?.

Send A Transaction

sendTransaction sends native tokens. Values are raw base-unit integers. Use parseUnits for display amounts.
import com.omsclient.kotlin_sdk.Network
import com.omsclient.kotlin_sdk.utils.parseUnits

val result = client.wallet.sendTransaction(
    network = Network.AMOY,
    to = "0xRecipient",
    value = parseUnits("0.01", 18),
)

println("Transaction id: ${result.txnId}")
println("Status: ${result.status}")
println("Transaction hash: ${result.txnHash}")
Parameters
ParameterTypeDescription
networkNetworkSupported SDK network, such as Network.POLYGON or Network.AMOY.
toStringRecipient address.
valueBigIntegerRaw base-unit native token value.
waitForStatusBooleanDefaults to true. Set to false to return immediately after execution.
statusPollingTransactionStatusPollingOptions?Optional fast poll, slow poll, and timeout configuration.
selectFeeOptionFeeOptionSelector?Optional callback for selecting a fee option.
Returns Returns SendTransactionResponse.
FieldTypeDescription
txnIdStringWallet transaction ID.
statusTransactionStatusLatest transaction status returned by OMS Wallet.
txnHashString?On-chain transaction hash when available.

Send Raw Calldata

Use the transaction request overload when you already have encoded calldata.
import com.omsclient.kotlin_sdk.Network
import com.omsclient.kotlin_sdk.models.SendTransactionRequest
import com.omsclient.kotlin_sdk.models.TransactionMode
import java.math.BigInteger

val transferCalldata = "0xa9059cbb000000000000000000000000..."

val result = client.wallet.sendTransaction(
    network = Network.AMOY,
    request = SendTransactionRequest(
        to = "0xTokenContract",
        value = BigInteger.ZERO,
        data = transferCalldata,
        mode = TransactionMode.Relayer,
    ),
)

println("Contract transaction hash: ${result.txnHash}")
Parameters
ParameterTypeDescription
networkNetworkSupported SDK network.
requestSendTransactionRequestRequest with to, raw value, optional encoded calldata data, and mode.
waitForStatusBooleanDefaults to true. Set to false to return immediately after execution.
statusPollingTransactionStatusPollingOptions?Optional fast poll, slow poll, and timeout configuration.
selectFeeOptionFeeOptionSelector?Optional callback for selecting a fee option.
Returns Returns SendTransactionResponse.

Call A Contract With Method And Args

Use callContract for state-changing contract methods. The SDK prepares the contract call, executes it, and polls for transaction status.
import com.omsclient.kotlin_sdk.Network
import com.omsclient.kotlin_sdk.models.AbiArg
import com.omsclient.kotlin_sdk.utils.parseUnits
import kotlinx.serialization.json.JsonPrimitive

val amount = parseUnits("1", 6)

val result = client.wallet.callContract(
    network = Network.AMOY,
    contract = "0xTokenContract",
    method = "transfer(address,uint256)",
    args = listOf(
        AbiArg(type = "address", value = JsonPrimitive("0xRecipient")),
        AbiArg(type = "uint256", value = JsonPrimitive(amount.toString())),
    ),
)

println("Contract transaction hash: ${result.txnHash}")
Parameters
ParameterTypeDescription
networkNetworkSupported SDK network.
contractStringContract address to call.
methodStringABI method signature, such as transfer(address,uint256).
argsList<AbiArg>?Method arguments as ABI args.
modeTransactionModeTransaction mode. Defaults to TransactionMode.Relayer.
waitForStatusBooleanDefaults to true. Set to false to return immediately after execution.
statusPollingTransactionStatusPollingOptions?Optional fast poll, slow poll, and timeout configuration.
selectFeeOptionFeeOptionSelector?Optional callback for selecting a fee option.
Returns Returns SendTransactionResponse.

Select A Fee Option

When a prepared transaction returns fee options, pass a selector callback. The selector receives fee options enriched with the wallet balance for each fee token when available. On testnets, fee options are automatically sponsored, so you usually do not need to choose a fee token.
import com.omsclient.kotlin_sdk.Network
import com.omsclient.kotlin_sdk.models.FeeOptionSelection
import com.omsclient.kotlin_sdk.utils.parseUnits

val result = client.wallet.sendTransaction(
    network = Network.AMOY,
    to = "0xRecipient",
    value = parseUnits("0", 18),
) { feeOptions ->
    val selected = feeOptions.first()
    FeeOptionSelection(token = selected.feeOption.token.symbol)
}
If you do not pass a selector, the SDK uses the first required fee option, or no fee option when the transaction is sponsored. Parameters selectFeeOption receives a list of FeeOptionWithBalance values. Returns Return FeeOptionSelection?.

Polling And Status

Transaction helpers execute and poll for transaction status. Fetch status directly when you have a Wallet transaction ID.
import com.omsclient.kotlin_sdk.Network
import com.omsclient.kotlin_sdk.utils.parseUnits

val tx = client.wallet.sendTransaction(
    network = Network.AMOY,
    to = "0xRecipient",
    value = parseUnits("0", 18),
    waitForStatus = false,
)

val status = client.wallet.getTransactionStatus(txnId = tx.txnId)

println("Status: ${status.status}")
println("Transaction hash: ${status.txnHash}")
Parameters
ParameterTypeDescription
txnIdStringWallet transaction ID returned by sendTransaction or callContract.
Returns Returns TransactionStatusResponse.

Sign A Message

import com.omsclient.kotlin_sdk.Network

val signature = client.wallet.signMessage(
    network = Network.AMOY,
    message = "Hello from OMS",
)

println("Signature: $signature")
Parameters
ParameterTypeDescription
networkNetworkSupported SDK network.
messageStringPlaintext message to sign.
Returns Returns String, the hex-encoded signature.

Verify A Message Signature

val isValid = client.wallet.isValidMessageSignature(
    network = Network.AMOY,
    message = "Hello from OMS",
    signature = signature,
)

println("Signature valid: $isValid")
Parameters
ParameterTypeDescription
networkNetworkSupported SDK network.
messageStringOriginal plaintext message.
signatureStringHex-encoded signature to verify against the selected wallet.
Returns Returns Boolean.

Sign Typed Data

Use signTypedData for EIP-712 typed data. Build the payload with JsonElement values.
import kotlinx.serialization.json.add
import kotlinx.serialization.json.buildJsonArray
import kotlinx.serialization.json.buildJsonObject
import kotlinx.serialization.json.put

val typedData = buildJsonObject {
    put("domain", buildJsonObject {
        put("name", "Example App")
        put("version", "1")
        put("chainId", 80002)
    })
    put("types", buildJsonObject {
        put("Message", buildJsonArray {
            add(buildJsonObject {
                put("name", "contents")
                put("type", "string")
            })
        })
    })
    put("primaryType", "Message")
    put("message", buildJsonObject {
        put("contents", "Hello from OMS")
    })
}

val typedSignature = client.wallet.signTypedData(
    network = Network.AMOY,
    typedData = typedData,
)
Parameters
ParameterTypeDescription
networkNetworkSupported SDK network.
typedDataJsonElementEIP-712 typed-data payload.
Returns Returns String, the hex-encoded signature.

Verify Typed Data

Verify an EIP-712 typed-data signature against the selected wallet.
val typedDataValid = client.wallet.isValidTypedDataSignature(
    network = Network.AMOY,
    typedData = typedData,
    signature = typedSignature,
)
Parameters
ParameterTypeDescription
networkNetworkSupported SDK network.
typedDataJsonElementOriginal EIP-712 typed-data payload.
signatureStringHex-encoded signature to verify.
Returns Returns Boolean.