Skip to content
This repository has been archived by the owner on Jun 23, 2020. It is now read-only.

Improve comments in template 01 #247

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions templates/01-hello-username/assembly/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,15 @@ export function sayHi(): void {
// context.sender is the account_id of the user who sent this call to the contract
// It's provided by the Blockchain runtime. For now we just store it in a local variable.
let sender = context.sender;
// `near` class contains some helper functions, e.g. logging.

// `near-runtime-ts` contains some helper classes, e.g. `logging`
// Logs are not persistently stored on the blockchain, but produced by the blockchain runtime.
// It's helpful to use logs for debugging your functions or when you need to get some info
// from the change methods (since change methods don't return values to the front-end).
logging.log(sender + " says \"Hi!\"");

// storage is a helper class that allows contracts to modify the persistent state
// and read from it. setString allows you to persitently store a string value for a given string key.
// We'll store the last sender of this contract who called this method.
storage.setString(LAST_SENDER_KEY, sender);
}

Expand Down
2 changes: 0 additions & 2 deletions templates/01-hello-username/assembly/model.ts

This file was deleted.

2 changes: 1 addition & 1 deletion templates/01-hello-username/src/config.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
(function() {
const CONTRACT_NAME = 'near-hello-devnet'; /* TODO: fill this in! */
const CONTRACT_NAME = 'near-hello-devnet';
const DEFAULT_ENV = 'development';

function getConfig(env) {
Expand Down
8 changes: 5 additions & 3 deletions templates/01-hello-username/src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,14 @@ async function initContract() {
// is hosted at https://wallet.nearprotocol.com
window.walletAccount = new nearlib.WalletAccount(window.near);

// Getting the Account ID. If unauthorized yet, it's just empty string.
// Getting the Account ID. If currently unauthorized, it's just empty string.
window.accountId = window.walletAccount.getAccountId();

// Initializing our contract APIs by contract name and configuration.
window.contract = await near.loadContract(nearConfig.contractName, {
// NOTE: This configuration only needed while NEAR is still in development
// See https://github.com/nearprotocol/NEPs/pull/3

// View methods are read only. They don't modify the state, but usually return some value.
viewMethods: ['whoSaidHi'],
// Change methods can modify the state. But you don't receive the returned value when called.
Expand All @@ -38,7 +40,7 @@ async function doWork() {
function signedOutFlow() {
// Displaying the signed out flow container.
Array.from(document.querySelectorAll('.signed-out')).forEach(el => el.style.display = '');
// Adding an event to a sing-in button.
// Adding an event to a sign-in button.
document.getElementById('sign-in').addEventListener('click', () => {
window.walletAccount.requestSignIn(
// The contract name that would be authorized to be called by the user's account.
Expand All @@ -65,7 +67,7 @@ function signedInFlow() {
window.contract.sayHi().then(updateWhoSaidHi);
});

// Adding an event to a sing-out button.
// Adding an event to a sign-out button.
document.getElementById('sign-out').addEventListener('click', e => {
e.preventDefault();
walletAccount.signOut();
Expand Down