-1

Here I would like to allow calling a method of my smart contract from a ethers provider that uses WalletConnect.

I proceed as follows to connect a user to WalletConnect :

    (ns my.project
      (:require
        ["@walletconnect/client" :default WalletConnect]
        ["@walletconnect/qrcode-modal" :as QRCodeModal]
        ["ethers" :as ethers]))
    
    (defn create-connector []
        (let [connector (WalletConnect.
                          #js{ "bridge" "https://bridge.walletconnect.org" 
                               "qrcodeModal" QRCodeModal})]
          (-> (.createSession connector)
              (.then
                  #(.on connector "connect" #(my-function connector DATAS))))))

Once the user is connected I launch the my-function method that calls the contract method:

    (defn my-function [connector DATAS]
      (let [{:keys [abi address params]} DATAS
            provider connector
            signer (.getSigner provider)
            contract (ethers/Contract. address abi signer)
            contract (.connect contract signer)]
        (-> (.contract-method contract params)
            (.then
              #(println "SUCCESS CALL.")))))

The connection to the account goes well, I am redirected correctly on my wallet app (Metamask iOS), however at the time of the call to the contract method nothing happens at the level of my mobile wallet application.

I tried another way to create my provider, in this way but without any results either:

    (let [...
          provider (ethers/providers.Web3Provider. connector)
          ...] 
   ...
)

Note that when I try on desktop my call to the method using this provider, it works perfectly, my Metamask extension is well called:

    (let [...
          provider (ethers/providers.Web3Provider. (object/get js/window "ethereum"))
          ...] 
   ...
)

What would be useful here is to be able to retrieve the signature from the walletconnect client.

TylerH
  • 20,799
  • 66
  • 75
  • 101
Antoine
  • 47
  • 6

1 Answers1

0

I know nothing about any of the wallet specifics, but in general you should add a .catch to handle promise rejections, aka. failed .contract-method calls.

So, try changing it to this. Maybe that surfaces the actual error.

    (defn my-function [connector DATAS]
      (let [{:keys [abi address params]} DATAS
            provider connector
            signer (.getSigner provider)
            contract (ethers/Contract. address abi signer)
            contract (.connect contract signer)]
        (-> (.contract-method contract params)
            (.then #(println "SUCCESS CALL."))
            (.catch #(println "FAILED CALL." %)))))

Maybe use js/console.log instead of println. That might yield more usable output.

Thomas Heller
  • 3,842
  • 1
  • 9
  • 9