首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Polkadot.js "signAndSend“函数导致”签名者“选项编译错误

Polkadot.js "signAndSend“函数导致”签名者“选项编译错误
EN

Stack Overflow用户
提问于 2022-07-12 22:38:02
回答 1查看 141关注 0票数 1

我正在使用polkadot.js.

  • I'm框架为创建一个前端应用程序,试图从扩展中获取一个帐户,并实现"signAndSend“函数来调用我实现的契约的函数。我将粘贴下面的代码片段。
  1. 我得到以下编译错误,为什么?

代码片段:

代码语言:javascript
复制
    const injector = await web3FromSource(performingAccount.meta.source);
    const keyring = new Keyring({ type: 'sr25519' });
//    const accountKeyring = keyring.addFromUri('//Alice');
    const accountKeyring = keyring.addFromAddress(performingAccount.address);

    const flip = await contract.tx.flip({ value: 0, gasLimit: -1 });
    flip.signAndSend(accountKeyring,{signer:injector.signer},(result) => {
      if (result.status.isInBlock) {
        setResult("in a block");
      } else if (result.status.isFinalized) {
        setResult("finalized");
      }
    });

编译错误:

代码语言:javascript
复制
(property) signer?: Signer | undefined
Type 'import("/Users/shin.takahashi/develop/substrate/flipper_frontend/fillper_frontend/node_modules/@polkadot/rpc-core/node_modules/@polkadot/types/types/extrinsic").Signer' is not assignable to type 'import("/Users/shin.takahashi/develop/substrate/flipper_frontend/fillper_frontend/node_modules/@polkadot/api-contract/node_modules/@polkadot/types/types/extrinsic").Signer'.
  Types of property 'update' are incompatible.
    Type '((id: number, status: H256 | ISubmittableResult) => void) | undefined' is not assignable to type '((id: number, status: ISubmittableResult | H256) => void) | undefined'.
      Type '(id: number, status: H256 | ISubmittableResult) => void' is not assignable to type '(id: number, status: ISubmittableResult | H256) => void'.
        Types of parameters 'status' and 'status' are incompatible.
          Type 'ISubmittableResult | H256' is not assignable to type 'H256 | ISubmittableResult'.
            Type 'ISubmittableResult' is not assignable to type 'H256 | ISubmittableResult'.
              Type 'import("/Users/shin.takahashi/develop/substrate/flipper_frontend/fillper_frontend/node_modules/@polkadot/api-contract/node_modules/@polkadot/types/types/extrinsic").ISubmittableResult' is not assignable to type 'import("/Users/shin.takahashi/develop/substrate/flipper_frontend/fillper_frontend/node_modules/@polkadot/rpc-core/node_modules/@polkadot/types/types/extrinsic").ISubmittableResult'.
                Types of property 'dispatchError' are incompatible.
                  Type 'import("/Users/shin.takahashi/develop/substrate/flipper_frontend/fillper_frontend/node_modules/@polkadot/api-contract/node_modules/@polkadot/types/interfaces/system/types").DispatchError | undefined' is not assignable to type 'import("/Users/shin.takahashi/develop/substrate/flipper_frontend/fillper_frontend/node_modules/@polkadot/rpc-core/node_modules/@polkadot/types/interfaces/system/types").DispatchError | undefined'.
                    Property '#private' is missing in type 'import("/Users/shin.takahashi/develop/substrate/flipper_frontend/fillper_frontend/node_modules/@polkadot/api-contract/node_modules/@polkadot/types/interfaces/system/types").DispatchError' but required in type 'import("/Users/shin.takahashi/develop/substrate/flipper_frontend/fillper_frontend/node_modules/@polkadot/rpc-core/node_modules/@polkadot/types/interfaces/system/types").DispatchError'.ts(2322)
Enum.d.ts(27, 5): '#private' is declared here.
submittable.d.ts(17, 5): The expected type comes from property 'signer' which is declared here on type 'Partial<SignerOptions>'
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2022-07-15 09:01:48

我不明白确切的原因,但我通过以下步骤解决了这个问题。

package.json.

  • remove directory.

  • Execute "npm安装“
  1. 更新.

修改前的Package.json:

代码语言:javascript
复制
{
  "name": "fillper_frontend",
  "version": "0.1.0",
  "private": true,
  "scripts": {
    "dev": "next dev",
    "build": "next build",
    "start": "next start",
    "lint": "next lint"
  },
  "dependencies": {
    "@polkadot/api": "^8.3.1",
    "@polkadot/api-contract": "^8.11.2",
    "@polkadot/extension-dapp": "^0.43.1",
    "@polkadot/ts": "^0.4.22",
    "@polkadot/types": "^8.3.1",
    "@polkadot/types-support": "^8.3.1",
    "@polkadot/util": "^10.0.1",
    "@polkadot/util-crypto": "^10.0.1",
    "next": "12.2.0",
    "react": "18.2.0",
    "react-dom": "18.2.0",
    "webpack": "^5.73.0",
    "webpack-cli": "^4.10.0"
  },
  "devDependencies": {
    "@types/node": "18.0.1",
    "@types/react": "18.0.14",
    "@types/react-dom": "18.0.5",
    "autoprefixer": "^10.4.7",
    "eslint": "8.19.0",
    "eslint-config-next": "12.2.0",
    "postcss": "^8.4.14",
    "tailwindcss": "^3.1.4",
    "typescript": "4.7.4"
  }
}

新package.json

代码语言:javascript
复制
{
  "name": "fillper_frontend",
  "version": "0.1.0",
  "private": true,
  "scripts": {
    "dev": "next dev",
    "build": "next build",
    "start": "next start",
    "lint": "next lint"
  },
  "dependencies": {
    "@polkadot/api": "latest",
    "@polkadot/api-contract": "latest",
    "@polkadot/extension-dapp": "latest",
    "@polkadot/ts": "latest",
    "@polkadot/types": "latest",
    "@polkadot/types-support": "latest",
    "@polkadot/util": "latest",
    "@polkadot/util-crypto": "latest",
    "next": "12.2.0",
    "react": "18.2.0",
    "react-dom": "18.2.0",
    "webpack": "^5.73.0",
    "webpack-cli": "^4.10.0"
  },
  "devDependencies": {
    "@types/node": "18.0.1",
    "@types/react": "18.0.14",
    "@types/react-dom": "18.0.5",
    "autoprefixer": "^10.4.7",
    "eslint": "8.19.0",
    "eslint-config-next": "12.2.0",
    "postcss": "^8.4.14",
    "tailwindcss": "^3.1.4",
    "typescript": "4.7.4"
  }
}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/72959078

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档