小编udi*_*r11的帖子

web3Modal 在初始化 web3Modal 实例时给出“窗口未定义”错误

我正在使用 Nextjs + Reactjs + Typescript。如果没有 Typescript,它可以完美工作,但在使用 Typescript 时出现此错误。

顺便说一下,我useMemo在这里使用,但我尝试在函数之外初始化它。在这两种情况下,我都遇到了相同的错误。

这是我当前正在使用的代码片段

const INFURA_ID = process.env.REACT_APP_INFURA_ID;

const initWeb3 = (provider: any) => {
  const web3 = new Web3(provider);

  web3.eth.extend({
    methods: [
      {
        name: "chainId",
        call: "eth_chainId",
        outputFormatter: web3.utils.hexToNumber as any,
      },
    ],
  });

  return web3;
};

export function Web3UtilityProvider() {
  const [walletAddress, setWalletAddress] = useState(null);
  const { user, authDispatch } = useAuth();

  const dAppClient = useMemo(() => new DAppClient({ name: "Beacon Docs" }), []);

  const web3Modal = useMemo(() => …
Run Code Online (Sandbox Code Playgroud)

typescript ethereum

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

我们如何使用嵌套 if else 和 #define 预处理器

#define len(a) if (a == 8)   1       \
               else if (a == 3) 0    \
               else -1
Run Code Online (Sandbox Code Playgroud)

这段代码只是一个例子,我们如何使用嵌套的 if else。我不想使用三元运算符,因为在这种情况下我不能使用 else if 语句。

c c++ c-preprocessor

3
推荐指数
1
解决办法
208
查看次数

标签 统计

c ×1

c++ ×1

c-preprocessor ×1

ethereum ×1

typescript ×1