BD Flashcards
(167 cards)
The difference between –save and –save-dev is
–save gets added to the dependencies and –save-dev gets added to devDependencies which is libraries you only need for your development environment
The Zsh equivalent of .bash_profile is
.zshenv
note: Zsh does not source .bash_profile, .bashrc
The first line in a solidity contract is
pragma solidity >=0.7.0 <0.9.0;
Contract names are written in
contract CapitalCase
To write a getter function in solidity, type
function get() public view returns(string) {
return var_name;
}
or
string public varName;
Note: Setters are not generated, only getters for public/external top level variables
Variable names are written in
camelCase
The 4 contract memory locations are
storage, memory, stack, calldata
storage: stored in the blockchain
memory: stored in memory and disappears after function runs, can be passed to other functions
stack: a variable that only exists inside a function and ceases to exist after function runs. A plain variable declaration in a function is automatically stored in stack.
calldata: Must be used for arguments to functions that are public or external. Like, literally data from a call.
To create an array, type
type[10]
arrays in solidity must all have the same type
To create a variable for an ethereum address type
address varName = “string”
Top level variables that have no memory location tag are automatically saved to
storage
To write a setter function in solidity, type
function set(string _paramName) external {
varName = _paramName;
}
The 4 function visibility keywords are
private: Only the smart contract can call the function (use underscore on func name as convention)
internal: Only the smart contract can call the function or the smart contract that inherited this function
external: Can only be called from outside the smart contract
public: Can be called from inside and outside the contract
The 4 function visibility keywords are
private, internal, external, public
private: Only the smart contract can call the function (use underscore on func name as convention)
internal: Only the smart contract can call the function or the smart contract inherited this function
external: Can only be called from outside the smart contract
public: Can be called from inside and outside the contract
Variables with no visibility keyword default to
private
Remix will not let me deploy without starting with
// SPDX-License-Identifier: GPL-3.0
People can only run your smart contract’s functions on ether scan if you
upload your source code
An interface is
A group of function signatures (everything before the curly braces) that match ones present in a different contract. You define them in order to be able to call that remote contract’s functions in your own contract.
Each interface only connects to one contract.
interface MyInterface {
function remoteFunc() external view returns (uint);
}
Then to call the remote function in my contract, type
MyInterface(remoteContractAddress).remoteFunc();
Note: For some reason, interface functions must be external even though the original function might be public and it still works.
I do not need to copy the virtual/override from the signature.
msg.sender is
the address of the person or contract calling your function. The msg variable is global.
msg.value is
the amount of gwei being sent to your contract from the person calling your function.
The difference between tx.origin and msg.sender is
tx.origin is the original person to initiate a transaction and msg.sender can be an intermediate contract triggered by the original person.
To throw an error if a value is negative, type
require(false, “Error message”)
To send ether to an address, type
(bool success, ) = address(“address”).call{value: 1 ether}(“”);
require(success);
For a smart contract to receive ether, it must have at least one function with
a payable tag
To make your contract able to receive ether, add the function
receive() external payable { … }
Or make any function payable, but that might require the sender to call it in a more sophisticated way (like in a UI or using an interface), rather than simple send from any wallet.
note: Contracts can only have one receive function