Web IDE, powered by Nujan, is your ultimate browser-based IDE designed to simplify the journey of writing, testing, compiling, deploying, and interacting with smart contracts on TON. Write smart contracts from anywhere, No setups, no downloads, just pure convenience and versatility.
import "@stdlib/deploy"; // for Deployable trait
fun mapTest(): Int {
let m: map<Int, Cell> = emptyMap();
m.set(1, beginCell().storeUint(100, 16).endCell());
m.set(2, beginCell().storeUint(200, 16).endCell());
m.set(3, beginCell().storeUint(300, 16).endCell());
m.set(4, beginCell().storeUint(400, 16).endCell());
let sum: Int = 0;
foreach (k, v in m) {
let s: Slice = v.beginParse(); // convert Cell to Slice
sum += s.loadUint(16); // sum the Slice values
}
return sum; // 1000
}
contract ForeachExample with Deployable {
// notice the lack of explicit empty init() -- a feature of Tact 1.3.0
get fun mapTest(): Int {
return mapTest();
}
}
gives non-descriptive error message while building: Error while building. Removing the foreach loop runs the build. Additionally, local compilation of such code works too, with or without foreach.
For example, the following:
gives non-descriptive error message while building:
Error while building
. Removing theforeach
loop runs the build. Additionally, local compilation of such code works too, with or without foreach.