NEAR 跨合约调用(允许一个账户将资金从托管账户释放到另一个账户)

NEAR cross-contract calls (allow an account to release funds from escrow to a different account)

我正在尝试学习如何允许 1 个帐户(“捐赠匹配器”)将资金存入第二个帐户(this contract,作为“托管”帐户),这是第三个然后允许帐户(常规“捐赠者”)发送到第四个帐户(“接收者”,例如慈善机构)。

我作为占位符编写的函数可能没有任何意义,因为我假设(按照当前编写的)它可能会从 caller/signer 而不是 escrow/self/contract 转移资金:

function transferFromEscrow(destinationAccount: AccountId, amount: u128): ContractPromiseBatch {
  // TODO: Fix this function!
  const toDestinationAccount = ContractPromiseBatch.create(destinationAccount);
  return toDestinationAccount.transfer(amount);
}

感谢您的帮助!

这个official NEAR repo led me to expect to see working examples in index.ts and 02.using-multiple-calls,但是我没看到。

我也把这个问题发到https://github.com/near-examples/cross-contract-calls/issues/13

如前所述,无法从其他帐户获得withdraw/transfer代币,因此您应该设计您的合约,要求用户将一些代币存入您的账户合同(通过类似存款的函数调用附加代币)。在核心合约中有这种模式的很好的例子:

  • lockup contract 根据时间表锁定资金
  • staking-pool 锁定委托权益的代币
  • multisig contract 使用带有未来调用所有参数的 add_request 函数和接受先前请求并执行它的 confirm 函数来启用 2FA