Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

how perform transaction to smart contract? #11

Open
San4es-hue opened this issue Mar 28, 2022 · 16 comments
Open

how perform transaction to smart contract? #11

San4es-hue opened this issue Mar 28, 2022 · 16 comments
Assignees
Labels
help wanted Need help? We will do our best to help you. v1

Comments

@San4es-hue
Copy link

San4es-hue commented Mar 28, 2022

Hi, How can I perform transaction to smart contract? Thanks

@Neo-glitch
Copy link

Hi, how can I interact with a smart contract? Thanks in advance

@bffcorreia bffcorreia self-assigned this Mar 29, 2022
@bffcorreia bffcorreia added the help wanted Need help? We will do our best to help you. label Mar 29, 2022
@bffcorreia
Copy link
Collaborator

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.

@mariavieira99
Copy link

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

@f4cker
Copy link

f4cker commented Apr 21, 2022

@San4es-hue Hope the cheat code would be helpful for you.

codeshot 2022-04-21 at 17 00 03 PM

@jayvs6341
Copy link

@f4cker
What is tokenUri ?

Can you please provide more details about the code

@f4cker
Copy link

f4cker commented Apr 22, 2022

@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

@jayvs6341
Copy link

@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.

@f4cker
Copy link

f4cker commented Apr 22, 2022

@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.
image

@jayvs6341
Copy link

@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" ?

@f4cker
Copy link

f4cker commented Apr 22, 2022

@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

@jayvs6341
Copy link

@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.

@f4cker
Copy link

f4cker commented Apr 22, 2022

@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.

@jayvs6341
Copy link

@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

@mazrou
Copy link

mazrou commented May 17, 2022

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

@Ravikumarsym
Copy link

Ravikumarsym commented Sep 21, 2022

Hi @San4es-hue
gas price sent to metamask transaction popup does not displayed

gas price null to invalid amount popup displayed

@bffcorreia bffcorreia added the v1 label Jun 28, 2023
@anishsuwal
Copy link

Did any one solve the problem. I been trying to implement the same but no luck. Can any one help.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Need help? We will do our best to help you. v1
Projects
None yet
Development

No branches or pull requests

9 participants