gpt4 book ai didi

typescript - 是否可以在 TypeScript 中使用 @truffle/contract?

转载 作者:行者123 更新时间:2023-12-04 13:54:27 29 4
gpt4 key购买 nike

Here is the package I would like to use
如何在 TypeScript 文件中导入它(不使用 require)
什么是正确的语法?
这些都不起作用:

import contract from "@truffle/contract";
import Contract from "@truffle/contract";
import TruffleContract from "@truffle/contract";

import { contract } from "@truffle/contract";
import { Contract } from "@truffle/contract";
import { TruffleContract } from "@truffle/contract";

import * as contract from "@truffle/contract";
import * as Contract from "@truffle/contract";
import * as TruffleContract from "@truffle/contract";
import * as alias from "@truffle/contract";

最佳答案

试试这个方法:

const truffle = require("@truffle/contract");
const res = await fetch('/contract.json'); //contract.json - is your compiled contract
const artifact = await res.json();
const contract = truffle(artifact); //here will be TruffleContract object
...

关于typescript - 是否可以在 TypeScript 中使用 @truffle/contract?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65118433/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com