Envs ndi gawo lofunikira. Chilengedwe chilichonse chimapangidwa motere:
REST API mapeto a node yomwe idzagwiritsidwe ntchito poyambitsa dApp ndi CHAIN_ID za netiweki.
Mawu achinsinsi a akaunti yomwe ili ndi zizindikiro zomwe zidzakhala magwero a zizindikiro zanu zoyesa.
Monga mukuwonera, surfboard.config.json imathandizira malo angapo mwachisawawa. Chosakhazikika ndi malo akumaloko (kiyi ya defaultEnv ndi parameter yosinthika).
Wallet-demo application
Gawoli silikunena za chilankhulo cha RIDE. M'malo mwake, yang'anani pulogalamu yomwe timayika ndikuyesa kuti timvetsetse bwino zomwe zikuchitika mu blockchain.
Tiyeni tiwone pulogalamu yosavuta ya Wallet-demo. Aliyense akhoza kutumiza zizindikiro ku adilesi ya dApp. Mutha kungochotsa ma WAVES anu. Ntchito ziwiri za @Callable zilipo kudzera pa InvokeScriptTransaction:
deposit()zomwe zimafuna malipiro ophatikizidwa mu WAVES
Alice amachotsa 4 WAVES
alice-adilesi β 100000000
bob-address β 200000000
Nayi code kuti mumvetse bwino zomwe zikuchitika:
# 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`.
{-# STDLIB_VERSION 3 #-}
{-# CONTENT_TYPE DAPP #-}
{-# SCRIPT_TYPE ACCOUNT #-}
@Callable(i)
func deposit() = {
let pmt = extract(i.payment)
if (isDefined(pmt.assetId))
then throw("works with waves only")
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() = false
Surfboard idzasonkhanitsa mafayilo oyesera mu ./test/foda ndikuyendetsa script pa node yomwe yakonzedwa mu surfboard.config.json. Pambuyo masekondi angapo mudzawona chonga ichi:
wallet test suite
Generating accounts with nonce: ce8d86ee
Account generated: foofoofoofoofoofoofoofoofoofoofoo#ce8d86ee - 3M763WgwDhmry95XzafZedf7WoBf5ixMwhX
Account generated: barbarbarbarbarbarbarbarbarbar#ce8d86ee - 3MAi9KhwnaAk5HSHmYPjLRdpCAnsSFpoY2v
Account generated: wallet#ce8d86ee - 3M5r6XYMZPUsRhxbwYf1ypaTB6MNs2Yo1Gb
Accounts successfully funded
Script has been set
β Can deposit (4385ms)
β Cannot withdraw more than was deposited
β Can withdraw (108ms)
3 passing (15s)