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

Executing contract methods #58

Open
anandsemtech opened this issue Jan 15, 2022 · 3 comments
Open

Executing contract methods #58

anandsemtech opened this issue Jan 15, 2022 · 3 comments

Comments

@anandsemtech
Copy link

Successfully connected Metamask with this library. Now, How do I establish web3 connection to my contract and call the contract's method. Can you please provide me some examples?

@Neo-glitch
Copy link

How did you connect this library pls, can't seem to do that

@mendelordanza
Copy link

This approach worked for me. You can try this

  1. Generate the encoded contract abi using web3j https://docs.web3j.io/4.8.7/
val function = Function(
                "{method name}",
                listOf(
                    Address(from),
                    Address(to),
                    Uint256(BigInteger(tokenId)),
                ),  // input parameters. Change this based on the method you're using
                listOf(object : TypeReference<Utf8String>() {}) // output parameters. Change this based on the method you're using,
            )

            val encodedFunction = FunctionEncoder.encode(function)
  1. Peform the Send Transaction method call with WalletConnect.
MainApplication.session?.performMethodCall(
                        Session.MethodCall.SendTransaction(
                            txRequest,
                            from = viewModel.address.value,
                            to = contractAddress,
                            nonce = nonce.transactionCount.toString(16),
                            gasPrice = DefaultGasProvider.GAS_PRICE.toString(16),
                            gasLimit = DefaultGasProvider.GAS_LIMIT.toString(16),
                            value = BigInteger.ZERO.toString(16),
                            data = endcodedFunction
                        )
                    ) { resp ->
                        // do something with callback
                    }
                    val i = Intent(Intent.ACTION_VIEW)
                    i.data = Uri.parse("wc:")
                    context.startActivity(i)

Make sure that to to parameter is the contract address you're interacting with

For some reason, this approach only works with Metamask v4.0.1 and does not work with Metamask's latest update v4.2.2. It might be a bug on their end.

@Mukesh6201
Copy link

Mukesh6201 commented May 31, 2022

@mendelordanza Can you explain in brief . I really need to connect with the metamask wallet using my smart contract. I have successfully connected with my wallet but when I try to perform a transaction, it redirected to metamask, but nothing happens. No dialog is showing. Now when I tried your method it is not importing any of the functions above although when I tried the same method in java it works ? Can you please refer me some tutorial or anything?
code

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants