ExecutionError: Exceeded the prepaid gas -- when called from front end

ExecutionError: Exceeded the prepaid gas -- when called from front end

transfer() 函数在测试和通过 CLI 时工作得非常好。但是,当我尝试从前端调用它时,它 returns

Uncaught (in promise) Error: {"index":0,"kind":{"ExecutionError":"Exceeded the prepaid gas."}}

这不是一个复杂的调用,只涉及 1. 转移令牌 2. 更新存储中的值。谁能告诉我为什么会发生这种情况?

document.querySelector('#transfer-to-owner').onclick = () => {
    console.log("Transfer about to begin")
    
    try {
         window.contract.transfer({})
     } catch (e) {
         'Something went wrong! ' +
         'Check your browser console for more info.'
     } 
}

合同来自 this repo

  const XCC_GAS: Gas = 20_000_000_000_000;

  transfer(): void {
    this.assert_owner()

    assert(this.contributions.received > u128.Zero, "No received (pending) funds to be transferred")

    const to_self = Context.contractName
    const to_owner = ContractPromiseBatch.create(this.owner)

    // transfer earnings to owner then confirm transfer complete
    const promise = to_owner.transfer(this.contributions.received)
    promise.then(to_self).function_call("on_transfer_complete", '{}', u128.Zero, XCC_GAS)
  }

  @mutateState()
  on_transfer_complete(): void {
    assert_self()
    assert_single_promise_success()

    logging.log("transfer complete")
    // reset contribution tracker
    this.contributions.record_transfer()
  }

near-api-jsnear-shell 使用不同的气体默认值。

near-api-js:

const DEFAULT_FUNC_CALL_GAS = new BN('30_000_000_000_000');

near-shell:

        .option('gas', {
            desc: 'Max amount of gas this call can use (in gas units)',
            type: 'string',
            default: '100_000_000_000_000'
        })

我添加了 _s 以使其更清楚 near-shell 默认使用超过 3 倍的 gas 量。