I want to initiate transactions using the following stack. However, Infura doesn't support web3.eth.sendTransaction(tx) because it requires the server to hold private keys. Here is a link to how it should work https://example.walletconnect.org/ and the repo https://github.com/WalletConnect/walletconnect-example-dapp.

So far this is what I have.

        const provider = new WalletConnectProvider({
            infuraId: "**************",

        await provider.enable();

        const web3 = new Web3(provider);

        web3.eth.getAccounts().then((account) => {
            console.log("kk", account)
        }).catch((err) => {
            console.log("Failed to get accounts", err)

        web3.eth.getBalance(account[0]).then((balance) => {
        }).catch((err) => {
            console.log("ayre", err)

you can use the contract function and that will work. For example if you want to initiate an ETH transaction and you have the function buy() in your contract used for purchasing goods, you can call it with your contract instance:

Declare the contract instance:

const instance = new web3.eth.Contract(contract.abi, contractAddress)

Use the contract instance to call your function

instance.methods.yourContractFunction().send({from: accounts[0],value:price}).then("confirmation",(confirmation) => {
      }).catch("error", (error) => {

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.