iotexproject / iotexproject/userop-kt

A working example?

Open
#1 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Kotlin
Stars
7
Forks
1
PR merge metrics
No merged PRs in 30d

Description

Hi! Is there any open sourced repo where I can get a minimal example of a project using `userop-kt`? I'm trying to set up an Android project but it gives me strange network error probably related to web3j:

```
Process: com.example.myapplication, PID: 11190
java.net.SocketTimeoutException: failed to connect to /192.168.68.104 (port 8080) from /10.0.2.16 (port 34700) after 10000ms
at libcore.io.IoBridge.connectErrno(IoBridge.java:235)
at libcore.io.IoBridge.connect(IoBridge.java:179)
at java.net.PlainSocketImpl.socketConnect(PlainSocketImpl.java:142)
at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:390)
at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:230)
at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:212)
at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:436)
at java.net.Socket.connect(Socket.java:646)
at okhttp3.internal.platform.Platform.connectSocket(Platform.kt:117)
at okhttp3.internal.connection.RealConnection.connectSocket(RealConnection.kt:266)
at okhttp3.internal.connection.RealConnection.connectTunnel(RealConnection.kt:232)
at okhttp3.internal.connection.RealConnection.connect(RealConnection.kt:174)
at okhttp3.internal.connection.ExchangeFinder.findConnection(ExchangeFinder.kt:238)
at okhttp3.internal.connection.ExchangeFinder.findHealthyConnection(ExchangeFinder.kt:111)
at okhttp3.internal.connection.ExchangeFinder.find(ExchangeFinder.kt:79)
at okhttp3.internal.connection.Transmitter.newExchange$okhttp(Transmitter.kt:163)
at okhttp3.internal.connection.ConnectInterceptor.intercept(ConnectInterceptor.kt:35)
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.kt:112)
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.kt:87)
at okhttp3.internal.cache.CacheInterceptor.intercept(CacheInterceptor.kt:82)
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.kt:112)
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.kt:87)
at okhttp3.internal.http.BridgeInterceptor.intercept(BridgeInterceptor.kt:84)
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.kt:112)
at okhttp3.internal.http.RetryAndFollowUpInterceptor.intercept(RetryAndFollowUpInterceptor.kt:71)
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.kt:112)
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.kt:87)
at okhttp3.RealCall.getResponseWithInterceptorChain(RealCall.kt:194)
at okhttp3.RealCall.execute(RealCall.kt:67)
at org.web3j.protocol.http.HttpService.performIO(HttpService.java:160)
at org.web3j.protocol.Service.send(Service.java:48)
at org.web3j.protocol.core.Request.send(Request.java:87)
at org.web3j.tx.ReadonlyTransactionManager.sendCall(ReadonlyTransactionManager.java:70)
at org.web3j.tx.ManagedTransaction.call(ManagedTransaction.java:134)
at org.web3j.tx.Contract.executeCall(Contract.java:292)
at org.web3j.tx.Contract.executeCallSingleValueReturn(Contract.java:300)
at org.web3j.tx.Contract.executeCallSingleValueReturn(Contract.java:311)
at org.web3j.tx.Contract.lambda$executeRemoteCallSingleValueReturn$1$org-web3j-tx-Contract(Contract.java:397)
at org.web3j.tx.Contract$$ExternalSyntheticLambda0.call(Unknown Source:6)
at org.web3j.protocol.core.RemoteCall.send(RemoteCall.java:42)
at io.iotex.userop.preset.builder.P256AccountBuilder$Companion$init$2.invokeSuspend(P256AccountBuilder.kt:74)
at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
```

Here's my code:
```kotlin
package com.example.myapplication

import P256Signer
import android.os.Bundle
import android.util.Log
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Surface
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.tooling.preview.Preview
import androidx.lifecycle.lifecycleScope
import com.example.myapplication.ui.theme.MyApplicationTheme
import io.iotex.userop.PresetBuilderOpts
import io.iotex.userop.preset.builder.P256AccountBuilder
import kotlinx.coroutines.launch
import java.math.BigInteger

val stackupApiKey = "API_KEY"
val rpcUrl = "https://api.stackup.sh/v1/node/$stackupApiKey"
val paymasterUrl = "https://api.stackup.sh/v1/paymaster/$stackupApiKey"
val usdcAddress = "0x833589fcd6edb6e08f4c7c32d4f71b54bda02913"
val entryPointAddress = "0x5FF137D4b0FDCD49DcA30c7CF57E578a026d2789"
val lightAccountFactoryAddress = "0x00000055C0b4fA41dde26A74435ff03692292FBD"
val smartAccountOwnerPrivateKey = "PK"

class MainActivity : ComponentActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)

lifecycleScope.launch {
val builder = P256AccountBuilder.init(
null,
rpcUrl = rpcUrl,
signer = P256Signer(smartAccountOwnerPrivateKey),
opts = PresetBuilderOpts(
entryPoint = entryPointAddress,
factory = lightAccountFactoryAddress,
salt = BigInteger.ZERO,
bundlerRpc = rpcUrl
)
)

val address = builder.sender
Log.d("userop", "Account address: $address")
}

setContent {
MyApplicationTheme {
// A surface container using the 'background' color from the theme
Surface(
modifier = Modifier.fillMaxSize(),
color = MaterialTheme.colorScheme.background
) {
Greeting("Android")
}
}
}
}
}

@Composable
fun Greeting(name: String, modifier: Modifier = Modifier) {
Text(
text = "Hello $name!",
modifier = modifier
)
}

@Preview(showBackground = true)
@Composable
fun GreetingPreview() {
MyApplicationTheme {
Greeting("Android")
}
}
```

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.