# Encode Club NEAR Bootcamp - DAY 5 [21/01/2022]
---
## [Day 5 Recording](https://youtu.be/o_ixf8pUiCg)
---
# Questions:
---
## Approch on NCD.L1.Sample--thanks contract
[Sample--thanks](https://github.com/Learn-NEAR/NCD.L1.sample--thanks)
-- Making the sample--thanks contract run yarn to install the dependencies.

-- After installation openup code editor. The project is basically to run these commands and node environment for testing and simulation.

-- In code is in the src folder --> thanks --> assembly--> index.ts gives the code file.

-- The goal of the application is build way to receive thankyou gratitude messages from other people.The idea is to build a program that deploy a contract to own account like giving thanks to your account for something yourname.testnet.

-- So the goal is to capture some message,so its model as class and stored on blockchain `export class Message`.
-- `max_length` is used to control the data to stop people from storing huge data and stop the contract from running out of space.so when you deploy the contract you need enough money in account so that message thanks works.
--`public sender: Accountid` to capture who send the message.The accountid is import form utils(helper) were accountid is just a string.

-- The Constructor is special kind of funciton which setup the class or data or model for the program.
-- It has few parameter like `public text` which is message or text.
-- `anonymous` is a piece of information which is boolean.
-- `public contribution` which is amount of money that attached
--`this.sender` the set of sender will be depending on if statement. if the sender is anonymous it will use value given to it otherwise use `context.sender` which is ternary operator.

-- To keep the messages `vector` its a collection of message in form of array.
-- In model.js the vector class which extending persistent vector `vector<T>extends persistentvector<T>`.The presistent vector means that wraps the storage to make it array from outside with the methods.

-- The idea of adding presistent vector to get the last bunch of messages.
-- Here we are going to attach the deposit and update it with contributions deposit so need to track the contribution.

-- Later need to track the contribution recived are greater than zero otherwise no funds to be transfer. now when the trasfer is complete it get record in contribution.The idea of contribution track and get record the transfer.

-- `context.sender`- Always the account that signed the transaction (Ethereum:EOA).
-- `context.predecessor` - Always the account BEFORE this account (if i sign the transaction and call the method in thanks contract directly then iam the sender,iam the predecessor, and contract name is thanks.yourname.testnet)
-- `context.contractName` - Always this account.(if i signin the transaction and call the other contract and that contract calls the thanks contract then iam the sender,other contract is predecessor,and this is contractName)
-- `this.assert_list` so only owner can do this and in retun`get_last`.To summarize messages in the contract.
--`transfer():void` also only owner can do this and make sure the contribution are not zero.

--`to_self` is going to contract name
--`to_owner` is the promiseBatch that used make a cross contract call.In this case calling the contract ourself.
-- `assert_single_promise_success` To check the results of the promise call and it get succeeded and once it get complete it get record the transfer.

---
## How to calculate amount of NEAR need for cover storage?
Basically 1NEAR per 100 kilobytes or 10NEAR per megabyte so you need to charge a little bit of NEAR to leave the message that will be enough to cover data.
---
## Why @nearBindgen is used?

-- The client interface is software which calling the contract to do that you need nearBindgen so that i converted t json autmatically when it retun from a method.
-- When putting in storage you can serialize to the blockchain so whatever the data which return form contract or storage it needs nearBindgen.
-- Putting a data in blockchain from a contract or returning data to application there must be some serialization and deserialization happening inthe contract boundary.
---
## Query about memory pool how to get in by paying more gas and isit possible in NEAR?
So, this is not control by contract level it is control by transaction level. Basically to reduce the competition for gas price (EPI 1559).
In NEAR there is no validators have control over the memory pool so you cann't spend more gas and get ahead in transaction
---
> nonce: A number only used once its basically used to make sure don't have duplicates in system.Though nonce if you do something with key it gets increament and you don't have same transaction.
> contract Name has to be Unique.
> Swapping contract examples **Ref-finance github**
---
## Cross contract call
-- cross contract call is about to have 5 teragas per hop (1teragas - millisec)
Check [cross-contract calls](https://github.com/near-examples/cross-contract-calls)
low level interface

## In trasfer method will NEAR trasfer the contract stage changes happen in same block?
When making cross-contract calls its not going to happen in same block what happening is creating a receipt which will then be setup in next block you can see that in explorer --> Blocks there will be set of transactions and setof receipts that happened as a result of transaction.

---
## Limitation on NEAR for developing smart contract
--Everything is asynchronous can't have flash loans on NEAR because the block time is one second and each block per function is limited to 200 millisec of execution time so it means large contract have hard time running on NEAR example are ave contact.
---
## What happen transfer NEAR and without further update another transfer attempts?
-- If you call transfer multiple times within two successive block without receipts come back this may endup making a second transaction at the same time this may end up with bug.
-- We can protect this by implementing `assert_is_not_pending_transfer` this says the transfer in progress so wait till completion.
---
> Contract code is living in the account storage in blockchain. Go to [Nomicon](https://nomicon.io/DataStructures/Account) -->Data structure ---> Accounts for more details.
---
## Can a contract listen to an event emitted from another contract?
-- Theres is no events in NEAR but the standard event like logging is something a json object.
-- One contract call another contract but can't listen for example: contract a tells contract b that call me when you have specific information then contract look through the list of information and make a cross contract call,so you can set that up.
---
> The contract can have ZERO or ONE account that the limit.
---
## Bash is the only way to execute the contract?
-- No, its not the only way what you do to execute the contract once deploy you need to send the transaction to the network.

-- To call a contract method on call function called query view looks like this

-- NEAR Api are used to let you to call contract so to do this you could know any one of the languages such as dotnet, java, python,elixer or whatever itis you can make this calls yourself you dont have to use javascript library.
-- The javascript library is used for this rpc api which wrapped with near-cli command line application to let you make calls.
---
> **Indexer** helps to track the record of all the transaction and storing it to database so you can see it anytime for example: [stats.gallery](https://stats.gallery/)
---
###### tags: `bootcamp transcripts`