# Encode Club NEAR Bootcamp 2 - DAY 2 [18/01/2022] --- ## [Day 2 Recording](https://youtu.be/UVq7kKcomEE) --- # Questions: --- ## How to validate a data Inputs coming into function and cost of running additional lines? **[Validate a Data Inputs](https://youtu.be/UVq7kKcomEE?t=1460)** -- Every line of code that executes is going to cost some gas on instruction by instruction basics. ![](https://i.imgur.com/aftNlIw.png) -- There are some validation happening in terms of datatype that you choose it doesn't have to be primitives or also create a data structure and call it has something that matches the structure ![](https://i.imgur.com/USPiPqh.png) -- Every time you see this export function in smart contract it is piece of code that compiling[preparing the computer to run it] like taking the text compile into code that computer can run it and put it into the virtual machine the network so it can be run on **NEAR** lets say the export function just means i have got 3 handles sticking out from the code one called "hello world","read","write"this are just a pieces of data that send whenever you flip the little switch. -- So, what does a Validation mean it is based on the datatype or use assert() statements. The assert statement allow us to really control what we want to do. In Assert statement when you add two pieces of data the assert eg:(true,"everything is fine") it evalvates to true {boolean logic concept}. so whatever be the first value if its true it evalvate and if its false than it explode. Eg: ![](https://i.imgur.com/U4Y0E7j.png) -- The first value "key.legnth>=10&& key.length<=30" In the statement the key length has to be between 10 and 30 so this is an assert statement. ![](https://i.imgur.com/vjHXXLo.png) -- This example only "carlos.near" its a near account so only carlos.near can call the method. so the contact sender is reaching out to the register and checks if its carlos than it continue. ![](https://i.imgur.com/iLl4XVJ.png) -- Here the "context.predecessor==context.sender" is in NEAR the concept of cross-contact calls like contract can call as many as contact like chain contract calling each other. so predecessor just means the one before or step before and context.sender is originator who ever signed the original transaction. -- so this means only you can call the function directly by signing the transaction as a user and calling it you can't have middle man in between. It is like login NEAR and use that login and try to call other contact to take NFTs or any stuff. --- ## How to look at NEAR in terms of architecture? **[NEAR in_terms of architecture](https://youtu.be/UVq7kKcomEE?t=2099)** * NEAR is a layer one blockchain equivalent to other blockchains. * NEAR has an EVM on it running through aurora. * Group of developers created aurora.dev which is a EVM running as a contract on NEAR account. -- so you can basically instread of deploying ethereum contract to other testnets or mainnet you can deploy it on auroua and get ethereum compatible virtual machine with ethereum native tokens in one second block time and 100x or 1000x cheaper. -- Then NEAR is also connected with octopus networks which gives IBC compartible interface. -- Basically NEAR is both EVM compartible and IBC compartible interface that has one sec block time,fastest finality,low gas fees and username account model(Ens baked) --- ## Is Simulation testing is similar to assembly scripts/coding is economical possible each code cost some gas fee? - Simulation technique repo is outdated so not prioritise on testing it but recommand it on testnet or krutosis which builds local environment so can automate and control the account also execute simulation testing. An upcoming simulation techique **NEAR-sdk-sim** that would be helpful for testing. **[NEAR-sdk-sim](https://crates.io/crates/near-sdk-sim)** -- Some production examples to know how it works (conway's game life on chain) Best way is to deploy a contract or it on testnet or krutosis to see the gas cost and modify the code deploy it again to check it that better way were the cycle to deploy and run it will couple of seconds. --- ## Does Assert() statement works same way in rust as it does in solidity? **[Assert statement](https://youtu.be/UVq7kKcomEE?t=2613)** -- Assert() statement is depends on asserting but it has to consume gas.Not aware of any non-gas spending equivalent. -- Check out the **NEAR-sdk-rs** documentation which has ton of documentation if you are familar with rust everything is wide open so here we have only assert. **[near_sdk](https://docs.rs/near-sdk/latest/near_sdk)** --- ## Why create-near-app is not recommended / how to connect contact that compiles front end? **[Create-near-app](https://youtu.be/UVq7kKcomEE?t=2687)** -- Nothing wrong in the create-near-app but it was develop by several people in course of 6months and the project was started by junior dev so if you try to use it some choices feel awkward,conventions are bit strange and if you edit the contract entire project rebuilds and it will take time so its not recommanded and noone glad about it. -- If you take a look at the link shared in the readme channel there 2 files which has L1 project(back-end),L2 project (Fornt-end) they all written in language like react or vue also adding angular and Svelte.so there is service layer that's factored out that basically mimics the contract interface in the fornt-end(there is some contract interface which plugin by service layer that used like a vue called as composable or in react it called as hook).we are building the thing that users see on the top of smart contract the web application and how does that communicate with contract. --- ## What would be a good smart contract reach/popular to people? Definitely if a smart contract has a value or potential target to reach people. Its an ROI calculation how much energy it will take and how much likely be the prize. --- ## What is the recommanded way to debug a contact? **[Debug a contact](https://youtu.be/UVq7kKcomEE?t=3221)** > Sketch out the methods and put a bunch of shortcuts to the return value that expexting in the cases.Add some couple branches in there to switch into contract.Write some unit test to get the basic shape of the application then dive in and start building a specific methods if you are running into a problem in assembly scipt you can printout aspect as a function called log that's not available if you are compiling the contract but if you running the unit test the log function is available on the global scope so you can printout what ever you want and see what's going on. but in some cases there might be problem a little more complicated you can attach to the running process step through the basics and boot strap the aspect then step through the code and debugging any node process that's on assembly script. > In Rust you can step through the code and debugging like you expect it got all the tools of mature language and mature development environment,you can break points and step through the code and do whatever you want in rust. --- ## How wallets work in NEAR relation with smartcontract? **[NEAR relation with smartcontract](https://youtu.be/UVq7kKcomEE?t=3746)** -- Using NEAR you can create a account and choose to deploy a contact to that account(like o and 1 contract on the account). If you have full access keys than anything can be done with the account including overwriting the contract,deleting the account,transfering money. but if you have function call access keys than you can only call funtions which depends on the access keys one of those two kinds and ofcouse you can delete access keys check to see a contract is permissionless. you can check there is no full access keys on account and you can read the source code make sure it can't modify itself -- Wallet is some piece of sofware or hardware/ledger that holds the private key there and gives you the way to manage it like sign transaction thats called wallet --- ## Is there is public RPC node to consider There are number of RPC node every validators is recommanded to run an RPC node also a 10% of devlopers in infura.io(beta version) --- ## login wallet in NEAR-cli? When you type near login in command line basically you are creating a local key(public-private key pair)then creating a transaction to add that public key to full access key on your account and closing the browser then near-cli saves the file to system that process of NEAR login. > An account can have only max zero or one contract per account --- ## View and deploy contract? It not possible on NEAR block explorer like etherscan but you can check out [stats gallery](https://stats.gallery) is the website like etherscan were you can grap the contract call function on it you can't view the code of it but its viewing the code in order to generate that interface dynamically. --- ## Multisig with NEAR The best way to look out is sputnikDAO "sputnikDAO v2" also check out AstroDAO for a front end. --- ## Multiple contract If you have multiple contract you can deploy to multiple accounts eg: yourproject.near in NEAR on mainnet and app1,2,3.project in to V1,2,3 subaccounts. --- ## Signout Account Signout Account is basically deleting the private key in your browser. if you created an account on NEAR you have to copy the seedphrase somewhere or recover email than you can clear your browser or cookies to signout account. > If you lose the private key than no way to get back the account. --- ## Can a contract deploy another contract Definitely contract can deploy another contract check out example like nearly neighbours,meme museum,sputnikDAO that as factory contract which has embedded init another contract that it deploys dynamically. --- ## Deploy address -- If you are using NEAR dev it deploy something based on timestamp and a random numbers it will consistenly do it as long as same NEAR dev folder there it will use same account -- If deploying with NEAR deploy then you need to tell it which account to deploy then you definitely know were its going before deploying. --- ## How do you verify the originality or ownership of NFT if copy smart contract/ipfs files and making own smart contract and redeploy it? You can check to see which contract controls the NFT and verify it. --- ## How to verify the github link is the actual code thats on chain? -- Any meaningful project will publish there source code somewhere you will able to link with github see their security audits and read the source of contract. Then you will find typically reference to docker image an environment for deterministic compiles so you can go there take the source code compile it you will get is same code hash eg:base 58 encoded sha256 digest of the byte code of contract so you will able to compare and see just like fingerprint of contract code. But need a deterministic compiles to get the some docker container to get same binary.if you compile on different machines the architectures are different will be different code hash. -- Check out [AwesomeNEAR](https://awesomenear.com/) to find different project source code,security audits, any reference to deterministic compiles it. --- ###### tags: `bootcamp transcripts`