-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtask_2.ts
26 lines (22 loc) · 819 Bytes
/
task_2.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
import { storage, Context } from "near-sdk-as"
// return the string 'hello world'
export function helloWorld(name: string): string {
return 'hello ' + name
}
// read the given key from account (contract) storage
export function read(key: string): string {
if (storage.hasKey(key)) {
return `✅ Key [ ${key} ] has value [ ${storage.getString(key)!} ]`
} else {
return `🚫 Key [ ${key} ] not found in storage. ( ${storageReport()} )`
}
}
// write the given value at the given key to account (contract) storage
export function write(key: string, value: string): string {
storage.set(key, value)
return `✅ Data saved. ( ${storageReport()} )`
}
// private helper method used by read() and write() above
function storageReport(): string {
return `storage [ ${Context.storageUsage} bytes ]`
}