Javascript 椭圆:TypeError:将循环结构转换为JSON

Javascript 椭圆:TypeError:将循环结构转换为JSON,javascript,blockchain,Javascript,Blockchain,开始之前的相关信息:我已经搜索了stackoverflow,并发现了类似的标题问题,但我不认为它们与我的相同,因为它们有一个关键的区别,它们似乎有包含对自身引用的对象,从而导致了圆圈。我没有 我已经找到了答案,原来椭圆只允许你使用十六进制字符串。。。因此,我的钱包代码中的更改使其生效,如下所示: this.keyPair.sign(dataHash).toHex(); 而不是 this.keyPair.sign(dataHash); 很难说您的console.log()的哪个部分是循环的,但

开始之前的相关信息:我已经搜索了stackoverflow,并发现了类似的标题问题,但我不认为它们与我的相同,因为它们有一个关键的区别,它们似乎有包含对自身引用的对象,从而导致了圆圈。我没有 我已经找到了答案,原来椭圆只允许你使用十六进制字符串。。。因此,我的钱包代码中的更改使其生效,如下所示:

this.keyPair.sign(dataHash).toHex();
而不是

this.keyPair.sign(dataHash);

很难说您的
console.log()
的哪个部分是循环的,但通常我会说,您可以自己手动控制将对象转换为JSON兼容的结构,只使用原语(数字、浮点数、布尔值、空值、数组、对象)。您并不真的想依靠所有内部数据结构来保持兼容性,而且泄漏无关数据太容易了。很可能重复出现在
EDDSE
BN
中。您是否假设
签名
属性为字符串?现在不是这样,我假设事实上,是的,我注意到它有一个“签名”类型,这让我很困惑,因为我的代码中没有“签名”自定义类型…你必须有一个
.sign
方法,不是吗?这就是返回签名结构的原因。@James我确实有一个.sign方法,我以为我在问题中粘贴了它,但我不小心遗漏了它,我现在已经添加了它,但我看不出它会做什么太奇怪的事情?你看到什么了吗?谢谢你迄今为止的帮助!
TypeError: Converting circular structure to JSON
// Endpoint that a user accesses (the start of the event)
app.post("/transact", (req, res) => {
  const { to, amount, type } = req.body;
  const transaction = wallet.createTransaction(
    to,
    amount,
    type,
    blockchain,
    transactionPool
  );

  res.redirect("/transactions");
});
  createTransaction(to, amount, type, blockchain, transactionPool) {
    this.balance = this.getBalance(blockchain);
    if (amount > balance) {
      console.log(
        `Amount: ${amount} exceeds the current balance: ${this.balance}`
      );
      return;
    }
    let transaction = Transaction.newTransaction(this, to, amount, type);
    transactionPool.addTransaction(transaction);
    return transaction;
  }
  static newTransaction(senderWallet, to, amount, type) {
    if (amount + TRANSACTION_FEE > senderWallet.balance) {
      console.log(`Not enough balance`);
      return;
    }

    return Transaction.generateTransaction(senderWallet, to, amount, type);
  }
  static generateTransaction(senderWallet, to, amount, type) {
    const transaction = new this();
    transaction.type = type;
    transaction.output = {
      to: to,
      amount: amount - TRANSACTION_FEE,
      fee: TRANSACTION_FEE
    };
    Transaction.signTransaction(transaction, senderWallet);
    return transaction;
  }
  static signTransaction(transaction, senderWallet) {
    transaction.input = {
      timestamp: Date.now(),
      from: senderWallet.publicKey,
      signature: senderWallet.sign(ChainUtil.hash(transaction.output))
    };
  }
static hash(data){
    return SHA256(JSON.stringify(data)).toString();
}
  sign(dataHash){
    return this.keyPair.sign(dataHash);
  }
this.keyPair.sign(dataHash).toHex();
this.keyPair.sign(dataHash);