Kadena
Building dApps with
What is Blockchain?
A blockchain is a type of digital ledger
-
Data Storage: Primarily for transactional data (e.g., financial transactions, sales records). Not ideal for bulk file storage.
-
Replication: Data is replicated in real-time across numerous systems. Public blockchains (e.g., Chainweb, Bitcoin, Ethereum) are fully transparent, broadcasting data to all participants.
- Decentralization: Unlike typical web client-server architecture, blockchains use a distributed network of nodes. Information spreads via "gossiping" rather than central broadcasting.
What is Blockchain?
A blockchain is a type of digital ledger
-
Consensus Mechanisms: To validate data, nodes use mechanisms like Proof of Work (PoW) and Proof of Stake (PoS). These are crucial for network integrity and security.
-
Cryptography: Utilizes digital signatures for ownership and authenticity, and cryptographic hashes for data reference and tamper detection.
- Smart Contracts: Self-executing programs stored on-chain. Similar to database-stored procedures, they read and write data based on set rules. Essential for web3 applications, they require gas fees for execution.
Blockchain Concepts and Applications
Text
-
Combination of Technologies: Blockchain is not a single technology but a blend of various technologies and techniques, aiming for decentralization, scalability, and security.
-
Selective Application: Not all applications require blockchain. It's most beneficial for digital currencies, decentralized finance, and decentralized ownership records (NFTs).
-
Diverse Implementations: Multiple blockchain platforms exist, each with unique approaches to data storage, real-time data replication, consensus mechanisms, and balancing decentralization, security, and scalability.
Blockchain Concepts and Applications
-
Trade-offs in Design: Each blockchain platform makes different trade-offs, particularly in aspects like gas fees for smart contracts.
-
Integration with Traditional Web Technologies: While some web3 applications are predominantly blockchain-based, many still utilize web servers and databases due to blockchains' compromises in certain desirable properties.
-
Limitations in Processing and Storage: Smart contracts can be slow to process (15 seconds to 1.5 minutes) due to the need for network-wide consensus. Also, blockchains are inefficient for general data storage as replication across the network is slow, costly, and permanent, making it unsuitable for data not requiring high security.
Kadena ?
Kadena
-
Chainweb, a public, proof-of-work blockchain with low gas fees and a unique multi-chain architecture that allows for high transaction throughput.
-
Pact, a smart contract programming language that emphasizes security and correctness.
- Kadena.js, a collection of JavaScript libraries for interacting with Chainweb nodes and working with Pact code.
Chainweb
Architecture and Functionality
-
Multi-Chain Architecture: Chainweb is Kadena's public blockchain, notable for its multiple parallel blockchains allowing high transaction throughput.
-
Public Blockchain Nature: It operates as a public blockchain with a network of distributed nodes, each storing data and executing smart contracts.
- Proof-of-Work System: Chainweb uses a proof-of-work mechanism, where miners solve mathematical problems to write blocks and secure the network.
Chainweb
Architecture and Functionality
-
Smart Contract Execution: Smart contracts are executed through Pact code, sent as transactions to nodes, eventually becoming part of the blockchain’s official history.
- High Transaction Throughput: Despite individual chains writing blocks every 30 seconds, the parallel nature allows Chainweb to handle a high volume of transactions (up to 480,000 transactions per second as of 2020).
Chainweb
Cost-Efficiency and User Interaction
-
Gas Fees: Users pay for smart contract execution with gas fees, which are relatively low on Chainweb (e.g., $0.00007 USD for a KDA transfer).
-
Free Read-Only Requests: Chainweb supports "local" read-only requests for free, such as account queries.
- User Accounts and Transactions: Transactions require a sender with a 'k:' prefixed account, sufficient KDA balance, and a signed transaction using the associated private key.
Pact
-
Human-Readable Code: Pact code is stored directly on-chain, unlike languages like Solidity that compile to bytecode. This enhances security verification.
-
Turing-Incomplete: Disallows recursion and loops, preventing infinite loops and associated blockchain hang-ups.
-
Formal Verification: Built-in support for type checking and formal verification using the Z3 theorem prover, eliminating many potential bugs.
- Atomic Execution: In case of an error, the entire transaction is rolled back, ensuring state consistency.
Pact
-
Built-in Data Storage: Pact includes native database support within smart contracts, with controlled access.
-
Multi-Sig and Keysets: Supports simple and multi-signature authorization, with customizable rules.
-
Zero-Knowledge Primitives: Incorporates primitives for working with zero-knowledge proofs, enhancing privacy and off-chain computations.
-
Scoped Access Control: Allows transaction signatures to be scoped to specific code sections, improving security.
- Pacts Feature: Facilitates safe state transfers between chains, crucial for Chainweb's scalability.
Pact
Deployment of Pact Smart Contracts
-
Deployment Process: Smart contracts are deployed by sending a Pact module as a transaction. Once mined, the contract becomes public.
-
Upgradable Modules: Unlike other blockchains, Pact modules can be upgraded based on governance rules, allowing bug fixes and updates.
- Module Governance Variability: Some modules are immutable, others allow administrator-driven upgrades, and some use decentralized voting for changes.
Pact
Deployment of Pact Smart Contracts
- Interaction with Chainweb: Once live on Chainweb, smart contracts can be interacted with via the public API of a Chainweb node, using the module name for function calls.
; example.pact
(module coin ...
(defun my-function ()
...)
)
; after deploying you can call it using chainweb-node api (usually done vai a client library)
(coin.my-function)Kadena.js
Bridging Kadena and Web Frontends
-
Integration of Chainweb and Pact: Kadena.js serves as a toolkit for applications built on Kadena, integrating Chainweb and Pact, the core technologies for smart contract development on the Kadena platform.
- User-Friendly Interface: Aimed at providing a user-friendly interface, it allows users to interact with smart contracts through a typical web frontend in JavaScript, rather than directly engaging with the contracts.
Pact in X minutes
;; hello-world.pact
;; All Pact modules must exist within a namespace on Chainweb,
;; except for basic contracts provided by Kadena.
;; There are two namespaces available for anyone'free' and 'user'
(namespace 'free )
;; Define `hello-world` module with the `G` capability
(module hello-world G
(defcap G () true)
(defun say-hello(name:string)
(format "Hello, {}!" [name])
)
)
Hello world
Hello world
;; hello-world.repl
;; pact code expects to be run on a chainweb enviroment
;; for testing purposes, we can use the pact repl to simulate a chainweb environment
;; begin-tx and commit-tx simulate a transaction
(begin-tx "Load modules")
;; set transaction JSON data
(env-data {
'hello-ks: { "keys": [], "pred": "keys-all" }
})
(define-namespace "free" (read-keyset "hello-ks") (read-keyset "hello-ks"))
;; load hello-world
(load "hello-world.pact")
;; run hello-world say-hello
(print (hello-world.say-hello "Salama"))
;; commit the transaction
(commit-tx)
Hello world
brew install kadena-io/pact/pact
# create hello-world.pact and hello-world.repl then run pact cli
pact hello-world.repl
Hello, Salama!
Load successfulDevnet Demo
Build dApps with kadena
By Salama Ashoush
Build dApps with kadena
- 233