import {
Name,
Contract,
print,
} from "asm-chain";
@table("counter")
class Counter {
public key: u64;
public count: u64;
constructor(count: u64=0) {
this.count = count;
this.key = Name.fromString("counter").N;
}
@primary
get primary(): u64 {
return this.key;
}
}
@contract
class MyContract extends Contract {
constructor(receiver: Name, firstReceiver: Name, action: Name) {
super(receiver, firstReceiver, action);
}
@action("inc")
inc(): void {
let mi = Counter.new(this.receiver);
let it = mi.find(Name.fromString("counter").N);
let count: u64 = 0;
let payer: Name = this.receiver;
if (it.isOk()) {
let counter = mi.get(it);
counter.count += 1;
mi.update(it, counter, payer);
count = counter.count;
} else {
let counter = new Counter(1);
mi.store(counter, payer);
count = 1;
}
print(`++++++++count:${count}`);
}
}
There is a smart contracts template for quick starting your smart contracts project:
Boilerplate to build your own contract + testing: https://github.com/ProtonProtocol/typescript-smart-contracts
npm i asm-contract
python3 -m venv ~/env
source ~/env/bin/activate
python3 -m pip install --upgrade pip
python3 -m pip install ipyeos
cd examples
npm run test:hello
transform is based on patractlabs/ask-lang