focus on providing information and resources to users. rather than allowing users to actively contribute or interact with the content on websites.
Allowed users to create, share, and exchange information and content online in a more interactive and collaborative way.
Issues like Denial of Service(Dos) attacks, censorship, third-party interference, downtime, etc.
The data and content are centralized in a small group of companies referred to the "Big Tech".
Big Four, Google, Amazon, Fackbook, Apple, known as GAFA. GAMA, cause facebook rebranded itself as Meta.
Big Five, GAMA add Microsoft.
The term Web 3.0 (also known as Web3) was coined by Polkadot's and Ethereum's cofounder Gavin Wood in 2014, referring to the "Decentralized online ecosystem based on blockchain."
Ethereum is a blockchain-based implementation of Web3. It's a platform that runs smart contracts.
EVM prevents DOS attacks and ensures taht programs do not have access to each other's states, ensuring the ability to establish without any potential interference.
Ethereum introduced smart contracts, which are considered the building blocks of decentralized finance(DeFi) and are associated with cryptocurrencies.
Smart contracts dismiss the need for intermediates and arbitration costs, and exclude the possibility of fraud.
Solidity is a high-level, object and contract-oriented language influenced by C++, JavaScript, and Python.
It works with Ethereum Virtual Machine (EVM).
use command `node scripts/run.js` or
~/projects/github/educative/develop-web3-apps-using-solidity-react/partnerly-contract$ npm run dev
> [email protected] dev
> node scripts/run.js
Nothing to compile
Partnership contract deployed
Partnership deployed to: 0x5FbDB2315678afecb367f032d93F642f64180aa3
as the result uppper, I completed my first contract
Add split ratios to contract and add test
Test first, TDD, test drive development.
A pure
function means that the operation inside the function doesn’t rely on any external state.
Split ratios in smart contracts typically refer to the way funds or tokens are distributed among different parties or addresses. This concept is often used in various blockchain applications, such as revenue sharing, token distribution, or automatic payments
contract ChallengeRatiosSplit {
uint256[] public splitRatios;
constructor(uint256[] memory _splitRatios) {
require(
_splitRatios.length > 2,
"More than two address should be provided to establish a partnership"
);
checkSplitRatios(_splitRatios);
splitRatios = _splitRatios;
console.log("Constract is deployed");
}
function checkSplitRatios(uint256[] memory _splitRatios) private pure {
for (uint256 i = 0; i < _splitRatios.length; i++) {
require(
_splitRatios[i] > 5,
"Split ratio should be greater than five"
);
}
}
}
code in js
await owner.sendTransaction({
to: contractAddress,
value: ethers.parseEther('5.0')
});
code in .sol
receive() external payable {}
code in js
partnership.withdraw()
code in .sol
function withdraw() public {
uint256 balance = getBalance();
uint256 addressesLength = addresses.length;
// console.log("before Balance: %s", balance);
require(balance > 0, "Insufficient balance");
require(balance >= splitRatiosTotal, "Balance should be greater than the total split ratio");
for (uint256 i = 0; i < addressesLength; i++) {
addresses[i].transfer(
(balance/splitRatiosTotal) * splitRatios[i]
);
}
// console.log("after Balance: %s", getBalance());
}
- Through upper, what we have known:
- Permanently store data
- Securely receive transactions
- Store funds
- Transfer those funds to specified accounts (wallet addresses)
use nextjs create a new project
npx create-next-app@latest
const checkIfWalletIsConnected = () => {
return Boolean((window as any).ethereum);
};