简体   繁体   English

Ride4Dapps:TypeError 无法读取 invokeScript 中未定义的属性“长度”

[英]Ride4Dapps: TypeError Cannot read property 'length' of undefined in invokeScript

I'm trying to execute wallet.ride example and I've got some issue with this:我正在尝试执行 wallet.ride 示例,但遇到了一些问题:

broadcast(invokeScript({contractAddress: address(env.accounts[1]), call:{function:"deposit",args:[]}, payment: [{amount: 300000000, asset:null }]}))广播(invokeScript({contractAddress: address(env.accounts[1]), call:{function:"deposit",args:[]}, payment: [{amount: 300000000, asset:null }]}))

TypeError: Cannot read property 'length' of undefined类型错误:无法读取未定义的属性“长度”

How to fix that?如何解决?

# In this example multiple accounts can deposit their funds and safely take them back, no one can interfere with this.
# An inner state is maintained as mapping `address=>waves`.

# You can try this contract by following commands in the IDE (ide.wavesplatform.com)
# Run commands as listed below
# From account #0:
#      broadcast(transfer({recipient:address(env.accounts[1]), amount: 1000000000}))
#      broadcast(transfer({recipient:address(env.accounts[2]), amount: 1000000000}))
# From account #1:
#      deploy()
# From account #2:
#      broadcast(invokeScript({contractAddress: address(env.accounts[1]), call:{function:"deposit",args:[]}, payment: [{amount: 300000000, asset:null }]}))
#      # observe state and balance of account(1)
#      broadcast(invokeScript({contractAddress: address(env.accounts[1]), call:{function:"deposit",args:[]}, payment: [{amount: 200000000, asset:null }]}))
#      # observe state and balance of account(1)
#      broadcast(invokeScript({contractAddress: address(env.accounts[1]), call:{function:"withdraw",args:[{type:"integer", value: 600000000}]}, payment: []}))
#      # observe error, nothing changed
#      broadcast(invokeScript({contractAddress: address(env.accounts[1]), call:{function:"withdraw",args:[{type:"integer", value: 400000000}]}, payment: []}))
#      # observe state and balance of account(1)


{-# STDLIB_VERSION 3 #-}
{-# CONTENT_TYPE DAPP #-}
{-# SCRIPT_TYPE ACCOUNT #-}

@Callable(i)
func deposit() = {
   let pmt = extract(i.payment)
   if (isDefined(pmt.assetId)) then throw("can hodl waves only at the moment")
   else {
        let currentKey = toBase58String(i.caller.bytes)
        let currentAmount = match getInteger(this, currentKey) {
            case a:Int => a
            case _ => 0
        }
        let newAmount = currentAmount + pmt.amount
        WriteSet([DataEntry(currentKey, newAmount)])
   }
}

@Callable(i)
func withdraw(amount: Int) = {
        let currentKey = toBase58String(i.caller.bytes)
        let currentAmount = match getInteger(this, currentKey) {
            case a:Int => a
            case _ => 0
        }
        let newAmount = currentAmount - amount
     if (amount < 0)
            then throw("Can't withdraw negative amount")
    else if (newAmount < 0)
            then throw("Not enough balance")
            else ScriptResult(
                    WriteSet([DataEntry(currentKey, newAmount)]),
                    TransferSet([ScriptTransfer(i.caller, amount, unit)])
                )
    }


@Verifier(tx)
func verify() = {
    true
}

Solved!解决了! look at: fee = 100000000 and dappAddress instead contractAddress看看: fee = 100000000 和dappAddress而不是contractAddress

# You can try this contract by following commands in the IDE (ide.wavesplatform.com)
# Run commands as listed below
# From account #0:
#      broadcast(transfer({recipient:address(env.accounts[1]), amount: 100000000, fee: 100000000}))
#      broadcast(transfer({recipient:address(env.accounts[2]), amount: 100000000, fee: 100000000}))
# From account #1:
#      deploy()
# From account #2:
#      broadcast(invokeScript({dappAddress: address(env.accounts[1]), call:{function:"deposit",args:[]}, payment: [{amount: 300000000, asset:null }]}))
#      # observe state and balance of account(1)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Ride4dApps 中的 WriteSet、TransferSet 和 ContractResult 之间的主要区别是什么? - What is the main difference between WriteSet, TransferSet and ContractResult in Ride4dApps? 参数“i”在Ride4dApps中的可调用函数中表示什么? - What does the parameter “i” represent in the callable functions in Ride4dApps? Ride4dApps中的前三行是什么意思? - What does the first three lines in Ride4dApps mean? 在Ride4dApps中,充提dApp(Waves IDE中的例子)是如何处理延迟问题的? - In Ride4dApps, how does the deposit and withdraw dApp(the example in Waves IDE) handle the delay issue? TypeError:无法读取未定义的属性“长度”-使用安全帽进行部署时 - TypeError: Cannot read property 'length' of undefined - While deploying using hardhat TypeError:无法读取未定义的属性(读取“长度”) - Blockchain JS - TypeError: Cannot read properties of undefined (reading 'length') - Blockchain JS 正在获取TypeError:无法设置未定义的属性“数据” - Getting TypeError: Cannot set property 'data' of undefined TypeError:无法读取未定义的属性(读取“eth”) - TypeError: Cannot read properties of undefined (reading 'eth') 类型错误:无法读取 null 的属性“方法” - TypeError: Cannot read property 'methods' of null Azure 区块链,无法读取未定义的属性“uri” - Azure Blockchain , Cannot read property 'uri' of undefined
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM