|
| 1 | +/* |
| 2 | + * This Kotlin source file was generated by the Gradle 'init' task. |
| 3 | + */ |
| 4 | +package quickstartkt |
| 5 | + |
| 6 | +// $start: quickstart-kt-import-client |
| 7 | +import io.polywrap.configBuilder.polywrapClient // Import of the Polywrap Client itself |
| 8 | +import io.polywrap.core.resolution.Uri // The Polywrap Client uses the Uri class for invocations |
| 9 | + |
| 10 | +// $end |
| 11 | + |
| 12 | +fun main() { |
| 13 | + // $start: quickstart-kt-init-client |
| 14 | + val client = polywrapClient { addDefaults() } |
| 15 | + // $end |
| 16 | + |
| 17 | + // $start: quickstart-kt-invoke-client |
| 18 | + val result = |
| 19 | + client.invoke<String>( |
| 20 | + uri = Uri("wrapscan.io/polywrap/sha3@1.0"), |
| 21 | + method = "sha3_256", |
| 22 | + args = mapOf("message" to "Hello Polywrap!") |
| 23 | + ) |
| 24 | + |
| 25 | + if (result.isFailure) { |
| 26 | + throw result.exceptionOrNull()!! |
| 27 | + } |
| 28 | + |
| 29 | + println(result) |
| 30 | + // $end |
| 31 | + |
| 32 | + // $start: quickstart-kt-uniswap |
| 33 | + val wethResult = |
| 34 | + client.invoke<Map<String, Any>>( |
| 35 | + uri = Uri("wrapscan.io/polywrap/uniswap-v3@1.0"), |
| 36 | + method = "fetchToken", |
| 37 | + args = |
| 38 | + mapOf( |
| 39 | + "address" to "0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2", |
| 40 | + "chainId" to "MAINNET" |
| 41 | + ) |
| 42 | + ) |
| 43 | + |
| 44 | + // Log the invocation error and stop execution if the invocation fails |
| 45 | + println(wethResult.getOrThrow()) |
| 46 | + |
| 47 | + val usdcResult = |
| 48 | + client.invoke<Map<String, Any>>( |
| 49 | + uri = Uri("wrapscan.io/polywrap/uniswap-v3@1.0"), |
| 50 | + method = "fetchToken", |
| 51 | + args = |
| 52 | + mapOf( |
| 53 | + "address" to "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48", |
| 54 | + "chainId" to "MAINNET" |
| 55 | + ) |
| 56 | + ) |
| 57 | + |
| 58 | + // Log the invocation error and stop execution if the invocation fails |
| 59 | + println(usdcResult.getOrThrow()) |
| 60 | + |
| 61 | + val poolAddressResult = |
| 62 | + client.invoke<String>( |
| 63 | + uri = Uri("wrapscan.io/polywrap/uniswap-v3@1.0"), |
| 64 | + method = "getPoolAddress", |
| 65 | + args = |
| 66 | + mapOf( |
| 67 | + "tokenA" to wethResult.getOrDefault(null), |
| 68 | + "tokenB" to usdcResult.getOrDefault(null), |
| 69 | + "fee" to "MEDIUM" |
| 70 | + ) |
| 71 | + ) |
| 72 | + |
| 73 | + // Log the invocation error and stop execution if the invocation fails |
| 74 | + println(poolAddressResult.getOrThrow()) |
| 75 | + // $end |
| 76 | +} |
0 commit comments