walletconnectkit-android
walletconnectkit-android copied to clipboard
how perform transaction to smart contract?
Hi, How can I perform transaction to smart contract? Thanks
Hi, how can I interact with a smart contract? Thanks in advance
Hi all! To perform a transaction to a smart contract you need to use the performTransaction
method and pass the data
parameter. This parameter should be the encoded function call of the smart contract. To encode the function you need to use other tools like web3j.
I want to write a blog post explaining this but I'm currently limited on time. So, it might take some time before I share it publicly.
What if you don't want to pass anything in the value parameter of performTransaction? I've already tried to pass the value "0.0", it opens my wallet but no confirmation popup appears
@San4es-hue Hope the cheat code would be helpful for you.
@f4cker What is tokenUri ?
Can you please provide more details about the code
@jayvs6341 As the code shows that the first list is a collection of input param, and the second list is a collection of output param, and all of this are according to functions declared in your contract
@f4cker
Can you please explian me,
Utf8String(tokenUri)
Here is what is tokenUri ?
Here is my code.
val function = Function("transfer", listOf(Address(walletConnectKit.address),
Utf8String("file:///android_asset/Token.json")
),
emptyList<TypeReference<*>>() )
val data = FunctionEncoder.encode(function)
val web3j = Web3j.build(HttpService("https://polygon-mumbai.infura.io/v3/f7587fb94ddb497c90cb7edb88ad3395"))
lifecycleScope.launch {
withContext(Dispatchers.IO){
val nounce = web3j.ethGetTransactionCount(walletConnectKit.address,DefaultBlockParameterName.LATEST).send().transactionCount
kotlin.runCatching {
walletConnectKit.performTransaction("0xa8E59566Ab7c6FD5729f61388131099ce02d074E",value = "", data , nounce.toString())
}
}.onSuccess {
Log.e("OnSuccess",":-"+it.result)
}.onFailure {
Log.e("onFailure",":-"+it.message)
}
}
I am getting following error.
Bad offset/length: offset=0 len=0 in.length=0
Can you please help me to sort it out, I am badly stuck at this.
@jayvs6341
There is no matter about the 'tokenUri', may be you should make the 'value' param send a "0" in 'performTransaction' method which I have refactored it and try it again.
@f4cker
error resolved.
But when it redirects to Metamask, it dont show the transaction approval dialog.
I have my own smart contract tokens. And I imported that tokens to polygon test net.
I have 100 tokens in my metamask and I want to send 10 to other address using my application.
If I try the default performTranscation function, it always sends the default test net currency. Like ether, matics etc.
How can I initiate transaction to send "MyToken" ?
@jayvs6341 That should be about the business, may be you should invoke the approve method in contract first to make sure your contract has the privilege to transfer tokens
@f4cker
yes, I have the function "transfer" to transfer the tokens, and I want metamask to approve the transaction.
If we go to metamask, we can manylly send the tokens correct,
Same think I want to invoke through Dapp, so it will redirect to metamask and then user just needs to approve it.
@jayvs6341 You didn't get it, the approve method is just a transaction like transfer, you should invoke it with performTransaction to interact with the smart contract through MetaMask, and then the MetaMask would show the approval dialog for you to confirm the transaction.
@f4cker
Thanks a lot for your ongoing support. Yeah, trying to understand
It would be very helpful, if you can provide me some thing like sample code
Hello @jayvs6341, I tried your code . but I get and error on building :
Caused by: org.gradle.workers.internal.DefaultWorkerExecutor$WorkExecutionException: A failure occurred while executing com.android.build.gradle.internal.tasks.CheckDuplicatesRunnable
note that I import the methods that you use from
implementation 'org.web3j:codegen:5.0.0'
and I'm using :
implementation 'dev.pinkroom:walletconnectkit:0.3.2'
please if you can help me and give us more details about your code if it works
Hi @San4es-hue gas price sent to metamask transaction popup does not displayed
gas price null to invalid amount popup displayed
Did any one solve the problem. I been trying to implement the same but no luck. Can any one help.