Playground— the real compiler, compiled to WebAssembly. Nothing leaves your browser.
.red → AssemblyScript · livesource.redloading engine…
// Edit me — the panels regenerate as you type.
abi ERC20 from "./abis/ERC20.json"
entity Account {
id: Id<Bytes>
balance: BigInt
label: Option<String> // nullable — there is no `null`
}
entity Transfer immutable {
id: Id<Bytes>
from: Account
to: Account
value: BigInt
timestamp: BigInt
}
source Token {
abi: ERC20
network: mainnet
address: 0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48
startBlock: 6082465
}
handler on Token.Transfer(event) {
let sender = Account.loadOrCreate(event.params.from, { balance: BigInt.zero })
let receiver = Account.loadOrCreate(event.params.to, { balance: BigInt.zero })
sender.balance = sender.balance - event.params.value
receiver.balance = receiver.balance + event.params.value
Transfer.create(event.id, {
from: event.params.from,
to: event.params.to,
value: event.params.value,
timestamp: event.block.timestamp,
})
}