# Encode Club NEAR Bootcamp - DAY 7 [25/01/2022]
---
## [Day7 Recording](https://youtu.be/y6trfCome4Y)
---
# Questions:
---
## Difference between or change Simulation and Test in the docs and how to swap signers in the test for transaction?
-- Simulation is new mechanism but in test basically setting up the context for the text to be run.
-- In some cases its not possible to test some scenarious. so take a look and see what the constraints and look at the production contract with most sophisticated test do some kind of code or there examples so that probably solve it.
## Contribution to NEAR Community?
Generally there are eight things that can be done with NEAR from the outside(smart contract) and inside(In the context of an executing function).They are related to 3 categories,
* Identiy - Create Account,Delete Account,Add/Delete Key.
* Money - Stake and Transfer.
* Code - Deploy a contract and call a function.
-- So from outside things like by signing a transaction that includes one or more these action so can be patch together and send transaction to the network and it gets deployed and works by getting valid account,valid signature,money pay for transaction etc.,
-- This things also done inside the contract were transaction is running and want to transfer money, deploy some code or wants to call a function in another contract etc.,so for doing that need to dive-in.
---
## Process of Deployment in Rust?
-- In this application architecture grap the first layer(right side) is blockchain layer and next one rpc interface where send and receive which is wrapped(language bindings) with *near-api-js(javascript)/near-api-py(python)/near-api-rs(Rust)/near-api-es(elixir upcoming)/near-api-rb(ruby upcoming)* this wrap the rpc interface and make it easy to communicate.

**While deploying the contract which api it uses javascript or rust:**
NO difference,the NEAR CLI which wraps the near-api-js that wraps the RPC interface by making calls.

-- Its basically working with contract is part of the application you build it and deploy it to the account storage so its a contract language that get complied to wasm that you deploy.
-- communicating from the frontend using api-js and other language or building a rust application that going to communicate with RPC that make no difference.

> My recommendation is to keep your contract in one project/repository and any front-end in another repository then keep it away from creating your app until what its doing or predict aleast what its generates whatever the project until you see the bountries different the pieces.later then compile to web assembly and deploy it.
---
## Is there any limit on creating sub account in contract?
There is no limit in contract. Go to [nomicon.io](https://nomicon.io/) --> Data structures --> AccountID there are requirements for contract.

---
## Does Creating a contract on a account basically creates a subaccount?
NO,here you are writing to contract state or account state.Check out the post consists of thread for single account.

The project eg: near state sherif.testnet
has code hash value is `base58(sha256_digest(contract_bytecode))`
* byte - zero and one of contract.
* sha256_digest - Hashing algorithm takes all that data and turns it into consistent lenght string 256 byte worth of data.
* base58 - its like base 64 an encoding thats easy for people to read.
-- Its like a finger prints for the contract which is deployed and then compile the source code and check for finger print matches.
-- To find the contract deployed check the transaction history and get the binary code and look at the methods.
-- But to check version of contract need to recompile the contract on the same hardware.
-- Basically deploying a contract could be any account like subaccount,anotheraccount as long as if have full access key on account you can deploy a contract.
-- [Deploy example](https://youtu.be/y6trfCome4Y?t=1853) a clip for how a contract deployed.
-- near state ajax.testnet.This is default state of account for all the one's in code_hash(No contract deployed)

---
> When you compile your assembly script or rust to web assembly that can be deploy to blockchain.
---
## What return from blockchain?
Communicating with blockchain is basically communicating with contract it depends on how data encoded when it comes back in rust contract it return back as base64 or the interface given it depends on the contract.
---
## When upgrading how the data in the storage managed?
Need to figure out the version of storage inside the contract. so you can coded up that read the old version or migrate the new version for example: SputnikDAO contracts.
---
## Functions on the contract when its deployed?
Go to [stats.gallery](https://stats.gallery/) -->Any.Testnet --> contract.

---
## What value would be currency on the Blockchain?
[Concept behind currency in blockchain](https://youtu.be/y6trfCome4Y?t=2765)
> Its an application on the blockchain like a domain name that can be rent bascially on the technology that is internet.Money is like a value that presists over time.
---
## Why do we do cross-contract call whenever we send near to another account and update contact state/ why cant we do this.contribution.record.transfer() instread fo a xcc?
[Cross contract call ](https://youtu.be/y6trfCome4Y?t=3297)
[NCD.L1.sample--thanks
](https://github.com/Learn-NEAR/NCD.L1.sample--thanks)
-- The application sample--thanks is like let you to say a message that deploy to account that can be control then it say thanks in return by calling the function and attaching some deposit then track the deposit.
-- so bascially the way is context object gives the access to the virtual machine then code will wakes up and reches out one of the register based on virtual machine and the money accrues to the contract account and immediately recieve the attached contact.

-- On the above post shows that `transfer():void` method trasfer here. so i call as the owner after some money has moved into contract then i call this method and this contact will send the money of all the contributions recived.

and come back `to_self .function_call` it will make a function call on transafer complete which call the `"on_transfer_complete"` from outside.
[cross-contract-calls](https://github.com/near-examples/cross-contract-calls) - Link contain section about cross contract call also some good explanations,some examples,rust-syntax,near-sdk.io.
> For example: imagine if the owner is deleted before the transfer is call. so imagine if you send two immediate transaction one to call transfer that asserts the owner and another one that delete the owner account. so in one block we call the transfer function and then the `const promise = to_owner function(this.contributions.received ` call happens in next block. But the owner account is deleted there's is an error and that point i recorded the transfer is complete but it wont complete. so to chain this promise by saying once i call the trasfer function then i make owner transfer then to myself want to make a function call on transfer complete. basically two calls one which is transfer then it has action received attached to it saying whenever it is done call back then i call transfer complete which asserts calling myself the promise was success no failure so i record the transfer.
---
## What happen if Transaction failed?
-- If transaction failed money will return back so there'll a receipt generated to return the money back.Lets say transaction in a signed message and receipt is after the signature is verified and get inside the network passing around the block like a collection actions or details.So if it fails it come back to whoever send it.
-- Some gas will be cost even transaction gets failed.
---
## What if function call has many callbacks but only has 200 millisec to execute?
-- When you call a function it has 200 milliseconds to do work and gets shut down. Then 300 milliseconds to measure the gas eg: more or less 1Tera gas corresponds to 1 milliseconds. So 200 and 300 tera gas for cross contract call totally 500 tera gas the complete the process on a single block.
-- Once done it generates some receipts that go to next block then it have 200 tera gas and potentially generate 300 tera gas of additional work then move to next block and goes on.
---
## How to write a behavior of smart contract that gives message to AWS(lambda function)?
> You can't Reach out to the real world but you can store a message locally. Like you could have a smart contract where you do some work and then make a cross contract call to put data into some other contract that is waiting for some service to pull from outside. That fetch data and put in a queue.
---
## How to know what contract deployed in a transaction?
Go to [stats.gallery](https://stats.gallery/) -->Any.Testnet --> contract and you can call the methods.
---
## Why so many receipts in a transaction?
[Receipts in transaction](https://youtu.be/y6trfCome4Y?t=5304)
---
## How to start without using bash for deployment?
-- Use RPC api directly or use node and wrap api-js if you dont use near-cli or use near-cli using command line. The process is signing a transaction to deploy a contract and sending that transaction to RPC-api through api-js/near-cli in a bash script.
---
###### tags: `bootcamp transcripts`