小编Gh0*_*05d的帖子

在 ethers.js 中设置合约方法的 Gas 限制

问题

我试图在测试网络(ropsten)上使用合约的方法,但由于以下错误而失败:

原因:'无法估计气体;交易可能失败或可能需要手动气体限制',代码:'UNPREDICTABLE_GAS_LIMIT'

代码

我创建了一个智能合约的实例,并想调用它的注册方法:

const registrationContract = new ethers.Contract(ADDRESS, abi, signer);
const hashedDomain = utils.keccak256(utils.toUtf8Bytes(domain));

const register = await registrationContract.register(hashedDomain, walletAddress);
Run Code Online (Sandbox Code Playgroud)

ethers.js是否提供了对合约设置限制的功能?或者可以用其他方式做到这一点吗?我在文档中没有找到。

javascript ethereum ether ethers.js

26
推荐指数
2
解决办法
5万
查看次数

如何在 next.js 中加载导出 Typescript 的库

当尝试从导出Typescript 的私有库导入组件时,我们收到以下错误消息:

Module parse failed: Unexpected token (82:7)
You may need an appropriate loader to handle this file type, currently no loaders are configured to process this file. See https://webpack.js.org/concepts#loaders
| 
| // Types
> export type {
Run Code Online (Sandbox Code Playgroud)

我该如何解决这个问题?我尝试在tsconfig文件中显式包含库节点模块:

  "include": [
    "next-env.d.ts",
    "**/*.ts",
    "**/*.tsx",
    "node_modules/@private-lib/*.*"
  ],
  "exclude": [""]
Run Code Online (Sandbox Code Playgroud)

但不幸的是,没有效果。似乎可以更改next.jswebpack配置,但不幸的是,尝试插入 Typescript 加载器并不起作用:

module.exports = {
  webpack: (config, options) => {
    config.module.rules.push({
      test: /\.(ts|js)x?$/,
      use: [
        options.defaultLoaders.babel,
        {
          loader: "ts-loader",
          options: {
            transpileOnly: true,
            experimentalWatchApi: …
Run Code Online (Sandbox Code Playgroud)

typescript webpack next.js webpack-4

21
推荐指数
3
解决办法
2万
查看次数

Angular 中的错误 NG02100 是什么意思?

问题

一段时间以来,我们的应用程序中出现错误:NG02100。我的问题是,我不知道发生了什么,除了导航栏中的一项之外,一切都正常,但它与其他组件具有相同的代码。

我尝试检查文档,但那里没有记录该错误。还有其他人遇到此错误并可以提供帮助吗?

我们在应用程序中使用这些 Angular 包作为参考:

"@angular/animations": "^13.2.1",
"@angular/common": "^13.2.1",
"@angular/compiler": "^13.2.1",
"@angular/core": "^13.2.1",
"@angular/forms": "^13.2.1",
"@angular/localize": "^13.2.1",
"@angular/platform-browser": "^13.2.1",
"@angular/platform-browser-dynamic": "^13.2.1",
"@angular/router": "^13.2.1",
"@angular/service-worker": "^13.2.1",
"@angular-devkit/architect": "^0.1302.2",
"@angular-devkit/build-angular": "^13.2.2",
"@angular-devkit/core": "^13.2.2",
"@angular-devkit/schematics": "^13.2.2",
"@angular-eslint/eslint-plugin": "~1.0.0",
"@angular-eslint/eslint-plugin-template": "~1.0.0",
"@angular-eslint/template-parser": "~1.0.0",
"@angular/cli": "^13.2.2",
"@angular/compiler-cli": "^13.2.1",
"@angular/language-service": "^13.2.1",
Run Code Online (Sandbox Code Playgroud)

javascript angular

8
推荐指数
1
解决办法
2万
查看次数

使用 nextjs 时 CSS 未在生产模式下加载

问题

当构建并开始应用程序的生产构建时,不会加载任何CSS 。检查开发工具,我可以看到大量错误和警告:

控制台中的错误和警告的屏幕截图

可能的罪魁祸首

在开发模式下启动应用程序时,我没有遇到任何这些问题。此外,其他资源(例如图像或字体)也可以正确加载。我们使用scss并在_app.tsx中导入全局样式表,如下所示:

import "../styles/globals.scss";
Run Code Online (Sandbox Code Playgroud)

为了解决另一个库的问题,我们必须设置一个自定义的 webpack 配置:

module.exports = phase => ({
  webpack: (config, { isServer }) => {
    config.module.rules.push({
      test: /\.node$/,
      use: "node-loader"
    });

    config.module.rules.push({
      test: /\.(ts|js)x?$/,
      use: [
        {
          loader: "ts-loader",
          options: {
            transpileOnly: true,
            experimentalWatchApi: true,
            onlyCompileBundledFiles: true
          }
        }
      ],
      include: [path.resolve(__dirname, "node_modules/@private/")],
      exclude: [path.resolve(__dirname, "node_modules/@private/src/styleguide")]
    });

    if (!isServer) {
      config.module.rules.push({
        test: /\.s?[ac]ss$/i,
        use: [
          { loader: "style-loader" },
          { loader: "css-loader" },
          {
            loader: "resolve-url-loader",
            options: { …
Run Code Online (Sandbox Code Playgroud)

css sass webpack webpack-style-loader next.js

6
推荐指数
1
解决办法
1万
查看次数

Next-Auth getSession 在我的开发环境中返回 null

我在其中一个页面中使用以下代码:

export async function getServerSideProps(context) {
  const session = await getSession(context)
  return {
    props: { session }
  }
}
Run Code Online (Sandbox Code Playgroud)

并且会话返回空值。我收到以下错误:

[next-auth][error][client_fetch_error] [
  'http://localhost:3000/api/auth/session',
  FetchError: request to http://localhost:3000/api/auth/session failed, reason: read ECONNRESET
Run Code Online (Sandbox Code Playgroud)

如果我尝试在浏览器中导航到http://localhost:3000/api/auth/session,我会正常获取会话对象。此外,我的同事在他的机器上有相同的代码,对他来说工作正常。

我知道我的环境和他的环境之间的唯一区别是我使用的是 windows 而他使用的是 mac。不确定这是否会导致这里出现问题。

next.js next-auth

6
推荐指数
1
解决办法
538
查看次数

如何在 Svelte 中执行 window.scrollTo(0,0)

我正在使用 svelte 和 svelte-routing 创建一个网站,并在用户浏览时尝试滚动到页面顶部。在其他框架中,例如 React window.scrollTo(0, 0) 工作得很好。不幸的是,在 Svelte 中,以下代码没有执行任何操作:

import { onMount } from "svelte";

onMount(() => window.scrollTo(0,0));
Run Code Online (Sandbox Code Playgroud)

那么让这个工作成功的秘诀是什么?

javascript svelte

5
推荐指数
2
解决办法
1万
查看次数

链接的“as”和“href”不兼容值错误的解决方法

我在Next.js项目中创建了以下页面src/pages/brand1/[[...subpages]]:我正在使用增量静态再生,.next/server/pages/brand1.json在构建next.js项目后我有一个文件。在我的组件中,我想创建一个Link组件,单击该组件时,会在地址栏中显示带有空路径(例如 )的 URL ,并从路由(使用文件)page-domain.com呈现页面。我尝试了各种解决方案来实现这一目标,例如:/brand1brand1.json

<Link
  href={{
    pathname: '/brand1',
  }}
  as={'/'}
  shallow
>
  link
</Link>
Run Code Online (Sandbox Code Playgroud)

但我在浏览器中收到错误消息Error: The provided 'as' value (/) is incompatible with the 'href' value (/brand1/[[...subpages]])

我有以下解决方案,适用于不带空子页面的网址(例如page-domain.com/menu),但它不适用于我之前描述的根页面:

<Link
  href={{
    pathname: '/brand1/[[...subpages]]',
    query: { subpages: 'menu' },
  }}
  as={'/menu'}
  shallow
>
  link
</Link>
Run Code Online (Sandbox Code Playgroud)

我的问题是如何创建一个可以显示带有空路径的 URL 的链接page-domain.com,并从路由中获取页面/brand1

javascript frontend reactjs next.js

5
推荐指数
0
解决办法
677
查看次数

在 Remix 中部署 Solidity 合约时如何修复/调试错误(无效的 arrayify 值)

问题

我正在尝试通过Remix部署智能合约。不幸的是,它失败并显示一条非常无用的错误消息。

错误信息

创建 MyContract 出错:编码参数时出错:错误:无效的 arrayify 值(参数 =“值”,值 =“”,代码=INVALID_ARGUMENT,版本=字节/5.5.0)

代码

这是使用的构造函数contract

struct RRSet {
    uint32 inception;
    uint32 expiration;
    bytes20 hash;
}

constructor(bytes memory _anchors) {
    // Insert the 'trust anchors' - the key hashes that start the chain
    // of trust for all other records.
    anchors = _anchors;
    rrsets[keccak256(hex"00")][DNSTYPE_DS] = RRSet({
        inception: uint32(0),
        expiration: uint32(3767581600), // May 22 2089 - the latest date we can encode as of writing this
        hash: bytes20(keccak256(anchors))
    });
    emit RRSetUpdated(hex"00", anchors); …
Run Code Online (Sandbox Code Playgroud)

blockchain ethereum solidity smartcontracts remix

5
推荐指数
1
解决办法
8230
查看次数

当通过 Nextjs API 路由进行流式传输时,EventSource 一次获取所有块

问题

我正在尝试通过EventSources将数据流式传输到我的React Frontend ,这种方法可行。问题是我一次收到所有数据块,而不是一次又一次地收到。哪种方法违背了该方法的目的,因为它现在基本上是GET请求。

代码

我正在使用Next.js api 路由,这是我在此路由上的代码:

res.writeHead(200, {
  "Content-Type": "text/event-stream",
  "Cache-Control": "no-cache",
  Connection: "keep-alive",
});

answerStream.data
  .on("data", (chunk: string) => res.write(chunk))
  .on("error", (error: Error) => {
    console.error(error);
    res.end();
  })
  .on("end", () => res.end());
Run Code Online (Sandbox Code Playgroud)

这是前端中的代码:

  const eventSource = new EventSource(url);
  eventSource.addEventListener("message", e => {
    try {
      if (e.data == "[DONE]") eventSource.close();
      else {
        const messageObject = JSON.parse(e.data);
        setArticle(state => (state += messageObject?.choices[0]?.text));
      }
    } catch (error) {
      console.log(error);
    }
  });

  eventSource.addEventListener("close", e => { …
Run Code Online (Sandbox Code Playgroud)

javascript server-sent-events reactjs next.js

5
推荐指数
1
解决办法
1274
查看次数

TypeError: obj.hasOwnProperty 在调用 Graphql 突变时不是函数

我收到一个奇怪的错误,无法弄清楚我做错了什么。我写了一个graphql突变来调用一个api:

domainStuff: async (parent, { command, params }, { models }) => {
  console.log("Params:", params);
  const result = await dd24Api(command, params);
  return result;
}
Run Code Online (Sandbox Code Playgroud)

这是我调用的函数:

export default async (command, parameter) => {
  const args = _.merge({ params: parameter }, auth);
  // Eleminate copying mistakes
  console.log(typeof args);
  const properCommand = command + "Async";
  const result = await soap
    .createClientAsync(apiWSDL)
    .then(client => {
       return client[properCommand](args)
         .then(res => {
            console.log(res[command + "Result"]);
          return res[command + "Result"];
    })
    .catch(err => {
      console.log(err);
      return err; …
Run Code Online (Sandbox Code Playgroud)

node.js node-soap graphql graphql-js

4
推荐指数
1
解决办法
7306
查看次数