首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Ride4Dapps: TypeError无法读取invokeScript中未定义的属性“长度”

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

Stack Overflow用户
提问于 2019-04-10 08:58:57
回答 1查看 74关注 0票数 1

我正在尝试执行wallet.ride示例,我对此有一些问题:

广播(invokeScript({contractAddress: address(env.accounts1),call:{function:“定金”,args:[]},支付:{contractAddress: 300000000,资产:null}))

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

怎么解决这个问题?

代码语言:javascript
复制
# 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
}
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2019-04-10 11:54:34

解决了!看看:= 100000000,dappAddress代替dappAddress

代码语言:javascript
复制
# 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)
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/55608582

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档