在 Clojure 中的移动设备上使用 WalletConnect v1 和 ethers.js 提供程序调用智能合约方法

问题描述 投票:0回答:0

在这里,我想允许从使用 WalletConnect 的 ethers 提供商调用我的智能合约的方法

我按照以下步骤将用户连接到 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))))))

用户连接后,我启动调用合约方法的我的函数方法:

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

与账户的连接顺利,我在我的钱包应用程序(Metamask iOS)上被正确重定向,但是在调用合约方法时,我的移动钱包应用程序没有任何反应。

我尝试了另一种方式来创建我的提供者,以这种方式但也没有任何结果:

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

请注意,当我尝试在桌面上调用使用此提供程序的方法时,它运行良好,我的 Metamask 扩展名为:

    (let [...
          provider (ethers/providers.Web3Provider. (object/get js/window "ethereum"))
          ...] 
   ...
)
clojure smartcontracts ethers.js wallet-connect web3
© www.soinside.com 2019 - 2024. All rights reserved.