You can have regular addresses, used by people
These addresses have a balance in ether that can transfer to any other address
There's also contract addresses, created when you deploy a new contract
These addresses also have a balance, but they cannot initiate a tx by their own
They also contain code and memory to persist data
Each Ethereum block contains transactions
A transactions is made basically by:
Each operation costs gas
Each transaction defines how much ether is willing to pay per gas consumed
Higher the price, the tx will be mined faster
Lower the price, the tx will be mined slower, or not mined at all
import { Company } from './company.sol';
contract Employee {
enum Roles { frontend, backend, scrum }
struct Skill {
string name;
int8 level;
}
uint public salary;
uint8 private age;
string name;
boolean active;
Company company;
address account;
Employee[] bosses;
Skills[] skills;
Roles role;
function Employee(address companyAddress, address employeeAddress) public {
salary = 100;
age = 26;
name = 'Diego';
active = true;
company = Company(companyAddress);
account = employeeAddress;
role = Roles.frontend;
}
}
contract Employee {
string public name;
string lastName;
uint8 age;
boolean updatedOnce = false;
function getFullName() constant public returns (string _name, string _lastName) {
_name = name;
_lastName = lastName;
}
function multiply(uint a, uint b) pure public returns (uint) {
return a * b;
}
modifier updateOnce() {
if (!updatedOnce) {
_;
}
updatedOnce = true;
}
modifier adult(uint8 _age) {
if (_age > 18) {
_;
}
}
function setAge(uint8 _age) adult(_age) updateOnce public {
age = _age;
}
}
npm install truffle ganache-cli
npx truffle unbox metacoin
# or
./node_modules/.bin/truffle unbox metacoin
# Start the dev node
npx ganache
# Build the contracts
npx truffle build
# Run the unit tests
npx truffle test
# Run the console of the dev node
npx truffle console