<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>Forem: Jefferson </title>
    <description>The latest articles on Forem by Jefferson  (@jeffersonnnn).</description>
    <link>https://forem.com/jeffersonnnn</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F97453%2F160a1531-2cac-47d3-ba3f-27a0b26b8d49.jpeg</url>
      <title>Forem: Jefferson </title>
      <link>https://forem.com/jeffersonnnn</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/jeffersonnnn"/>
    <language>en</language>
    <item>
      <title>Unbundling Content Delivery Network Architecture: How CDN Work</title>
      <dc:creator>Jefferson </dc:creator>
      <pubDate>Sat, 09 Nov 2024 08:05:56 +0000</pubDate>
      <link>https://forem.com/jeffersonnnn/unbundling-content-delivery-network-architecture-how-cdn-work-539e</link>
      <guid>https://forem.com/jeffersonnnn/unbundling-content-delivery-network-architecture-how-cdn-work-539e</guid>
      <description>&lt;p&gt;In today's rapidly changing digital world, delivering content quickly and reliably is more important than ever. Whether it's streaming high-definition videos or ensuring smooth access to dynamic web applications, the speed and efficiency of content delivery can make or break the user experience. At the heart of this seamless distribution is the Content Delivery Network (CDN). This article explores the complexities of CDN architecture, breaking down its components to understand how CDNs operate. We'll also dive into practical implementations with code examples in Node.js and Python to demonstrate CDN integration.&lt;/p&gt;

&lt;h2&gt;
  
  
  Table of Contents
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;Introduction&lt;/li&gt;
&lt;li&gt;What is a CDN?&lt;/li&gt;
&lt;li&gt;Traditional CDN Architecture&lt;/li&gt;
&lt;li&gt;
Unbundling CDN Architecture

&lt;ul&gt;
&lt;li&gt;Edge Servers vs. Origin Servers&lt;/li&gt;
&lt;li&gt;Caching Strategies&lt;/li&gt;
&lt;li&gt;Load Balancing&lt;/li&gt;
&lt;li&gt;DNS Resolution&lt;/li&gt;
&lt;li&gt;Security Features&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
How a CDN Works

&lt;ul&gt;
&lt;li&gt;Request Flow&lt;/li&gt;
&lt;li&gt;Caching Mechanism&lt;/li&gt;
&lt;li&gt;Content Delivery&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
Implementing CDN Integration

&lt;ul&gt;
&lt;li&gt;Using CDN with Node.js&lt;/li&gt;
&lt;li&gt;Using CDN with Python&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
Advanced CDN Features

&lt;ul&gt;
&lt;li&gt;Edge Computing and Serverless Functions&lt;/li&gt;
&lt;li&gt;Real-Time Analytics and Monitoring&lt;/li&gt;
&lt;li&gt;Protocol Enhancements: HTTP/2 and HTTP/3&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;Advantages and Challenges&lt;/li&gt;
&lt;li&gt;Future of CDNs&lt;/li&gt;
&lt;li&gt;Conclusion&lt;/li&gt;
&lt;li&gt;References&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  Introduction
&lt;/h2&gt;

&lt;p&gt;Content Delivery Networks (CDNs) are the unsung heroes of the modern internet, ensuring that users around the globe can access digital content swiftly and reliably. By spreading content across a network of geographically dispersed servers, CDNs cut down on latency, reduce bandwidth usage, and boost overall user satisfaction. As the demand for faster and more efficient content delivery skyrockets, understanding how CDNs are built and function becomes crucial for developers and businesses alike.&lt;/p&gt;

&lt;h2&gt;
  
  
  What is a CDN?
&lt;/h2&gt;

&lt;p&gt;A Content Delivery Network (CDN) is a network of distributed servers designed to deliver web content and other digital assets to users based on their geographic location, the origin of the content, and the type of content delivery server. The main goal of a CDN is to minimize latency and improve load times by serving content from servers that are physically closer to the end-user.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Key Functions of a CDN:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Content Caching:&lt;/strong&gt; Storing copies of content in multiple locations to ensure quick access.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Load Balancing:&lt;/strong&gt; Distributing user requests efficiently across multiple servers to prevent any single server from becoming overwhelmed.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Security:&lt;/strong&gt; Protecting against Distributed Denial of Service (DDoS) attacks and ensuring data transmission is secure.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Optimization:&lt;/strong&gt; Enhancing content delivery speed through techniques like compression and minification.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Traditional CDN Architecture
&lt;/h2&gt;

&lt;p&gt;Traditional CDNs are composed of several key components that work together to deliver content efficiently and securely:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Origin Server:&lt;/strong&gt; The main server where the original content is stored.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Edge Servers:&lt;/strong&gt; Distributed servers located closer to end-users that cache and deliver content.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;DNS Servers:&lt;/strong&gt; Route user requests to the nearest edge server.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Load Balancers:&lt;/strong&gt; Distribute incoming traffic across multiple servers to prevent overload.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Proxy Servers:&lt;/strong&gt; Act as intermediaries for client requests seeking resources from other servers.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  Unbundling CDN Architecture
&lt;/h2&gt;

&lt;p&gt;To truly grasp how CDNs operate, it's helpful to break down their architecture into individual components. This approach clarifies the role each part plays in ensuring efficient content delivery.&lt;/p&gt;

&lt;h3&gt;
  
  
  Edge Servers vs. Origin Servers
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Origin Servers:&lt;/strong&gt; These are the central hubs where the original content resides. When an edge server doesn’t have the requested content cached, it reaches out to the origin server to fetch it.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Edge Servers:&lt;/strong&gt; Strategically placed across various geographic locations, edge servers store cached content closer to end-users, which significantly reduces latency and improves load times.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Caching Strategies
&lt;/h3&gt;

&lt;p&gt;Caching is the cornerstone of CDN functionality, determining how and where content is stored and served. Common caching strategies include:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Static Content Caching:&lt;/strong&gt; This involves storing unchanging resources like images, CSS, and JavaScript files.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Dynamic Content Caching:&lt;/strong&gt; More complex and involves content that changes frequently. Techniques like &lt;strong&gt;Edge Side Includes (ESI)&lt;/strong&gt; are used to cache parts of dynamic content.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Time-to-Live (TTL):&lt;/strong&gt; Defines how long content remains cached before it’s refreshed. Typically, dynamic content has shorter TTLs, while static content enjoys longer TTLs.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Node.js Example: Setting Cache-Control Headers&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const express = require('express');
const app = express();

app.use('/static', express.static('public', {
  maxAge: '1y', // Cache static assets for one year
}));

app.get('/dynamic', (req, res) =&amp;gt; {
  res.set('Cache-Control', 'no-cache');
  res.send('&amp;lt;h1&amp;gt;Dynamic Content&amp;lt;/h1&amp;gt;');
});

app.listen(3000, () =&amp;gt; console.log('Server running on port 3000'));
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;em&gt;Figure 2: Cache-Control Headers in Node.js&lt;/em&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Load Balancing
&lt;/h3&gt;

&lt;p&gt;Load balancing ensures that incoming traffic is spread evenly across multiple servers, preventing any single server from becoming a bottleneck. Common load balancing techniques include:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Round Robin:&lt;/strong&gt; Distributes requests in a sequential manner.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Least Connections:&lt;/strong&gt; Directs traffic to the server with the fewest active connections.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;IP Hashing:&lt;/strong&gt; Assigns requests based on the client's IP address.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Python Example: Simple Load Balancer with Flask&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;from flask import Flask, request
import requests

app = Flask(__name__)

servers = ['http://localhost:5001', 'http://localhost:5002']
current = 0

@app.route('/')
def load_balance():
    global current
    server = servers[current]
    current = (current + 1) % len(servers)
    response = requests.get(server + request.path)
    return response.content

if __name__ == '__main__':
    app.run(port=5000)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;em&gt;Figure 3: Basic Load Balancer in Python&lt;/em&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  DNS Resolution
&lt;/h3&gt;

&lt;p&gt;The Domain Name System (DNS) is crucial for CDNs as it directs user requests to the nearest edge server. When a user requests content, the DNS resolver identifies the optimal edge server based on factors like geographic proximity and current server load.&lt;/p&gt;

&lt;h3&gt;
  
  
  Security Features
&lt;/h3&gt;

&lt;p&gt;CDNs enhance security through various mechanisms:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;DDoS Protection:&lt;/strong&gt; Absorbs and mitigates Distributed Denial of Service attacks.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Web Application Firewall (WAF):&lt;/strong&gt; Filters and monitors HTTP traffic between a web application and the Internet.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;SSL/TLS:&lt;/strong&gt; Encrypts data between the user and the CDN, ensuring secure transmission.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  How a CDN Works
&lt;/h2&gt;

&lt;p&gt;Understanding the workflow of a CDN helps explain how its architectural components interact to deliver content efficiently.&lt;/p&gt;

&lt;h3&gt;
  
  
  Request Flow
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;User Request:&lt;/strong&gt; A user accesses a website or application.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;DNS Lookup:&lt;/strong&gt; The request triggers a DNS query to resolve the domain name to an IP address.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Routing to Edge Server:&lt;/strong&gt; Based on the DNS response, the user is directed to the nearest edge server.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Cache Check:&lt;/strong&gt; The edge server checks if it has the requested content cached.

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Cache Hit:&lt;/strong&gt; Content is delivered directly to the user.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Cache Miss:&lt;/strong&gt; The edge server fetches content from the origin server.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Content Delivery:&lt;/strong&gt; The content is served to the user, and the edge server caches it for future requests.&lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;
  
  
  Caching Mechanism
&lt;/h3&gt;

&lt;p&gt;Caching involves storing copies of content on edge servers to speed up delivery. The CDN determines the caching policy based on headers like &lt;code&gt;Cache-Control&lt;/code&gt; and &lt;code&gt;Expires&lt;/code&gt;. Dynamic content requires more sophisticated caching strategies, often involving partial caching or real-time content generation.&lt;/p&gt;

&lt;h3&gt;
  
  
  Content Delivery
&lt;/h3&gt;

&lt;p&gt;Once cached, content delivery is swift because resources are served from locations closer to the user. This proximity not only reduces latency but also eases the load on origin servers, ensuring scalability during traffic spikes.&lt;/p&gt;

&lt;h2&gt;
  
  
  Implementing CDN Integration
&lt;/h2&gt;

&lt;p&gt;Integrating a CDN into your application can significantly boost performance and reliability. Here are some practical examples demonstrating how to set up and utilize CDNs in Node.js and Python applications.&lt;/p&gt;

&lt;h3&gt;
  
  
  Using CDN with Node.js
&lt;/h3&gt;

&lt;p&gt;Node.js applications can easily integrate with CDNs to serve static assets efficiently. Here's how to set up a simple Express server to utilize a CDN for serving static files.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import logo from './logo.svg';
import './App.css';

function App() {
  return (
    &amp;lt;div className="App"&amp;gt;
      &amp;lt;header className="App-header"&amp;gt;
        &amp;lt;img src={logo} className="App-logo" alt="logo" /&amp;gt;
        &amp;lt;p&amp;gt;
          Edit &amp;lt;code&amp;gt;src/App.js&amp;lt;/code&amp;gt; and save to reload.
        &amp;lt;/p&amp;gt;
        &amp;lt;a
          className="App-link"
          href="https://reactjs.org"
          target="_blank"
          rel="noopener noreferrer"
        &amp;gt;
          Learn React
        &amp;lt;/a&amp;gt;
      &amp;lt;/header&amp;gt;
    &amp;lt;/div&amp;gt;
  );
}

export default App;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;em&gt;Figure 4: Express Server Serving Static Files via CDN&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Integrating with a CDN Provider&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;To connect with a CDN provider like Cloudflare or AWS CloudFront, you'll typically update your DNS settings to point your domain to the CDN. This setup allows the CDN to handle the distribution of your content. Here's an example of how to configure AWS CloudFront with a Node.js application:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const express = require('express');
const app = express();
const path = require('path');

const CDN_URL = 'https://your-cloudfront-distribution.cloudfront.net';

app.use('/static', express.static(path.join(__dirname, 'public'), {
  maxAge: '1d',
  setHeaders: (res, path) =&amp;gt; {
    if (path.endsWith('.html')) {
      res.setHeader('Cache-Control', 'no-cache');
    }
  },
}));

app.get('/', (req, res) =&amp;gt; {
  res.redirect(`${CDN_URL}/index.html`);
});

app.listen(3000, () =&amp;gt; console.log('Server running on port 3000'));
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;em&gt;Figure 5: Redirecting to CDN-Hosted Content in Node.js&lt;/em&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Using CDN with Python
&lt;/h3&gt;

&lt;p&gt;Python applications, especially those built with frameworks like Flask or Django, can also take advantage of CDNs to serve static and media files efficiently.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Flask Example: Serving Static Files via CDN&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;!DOCTYPE html&amp;gt;
&amp;lt;html lang="en"&amp;gt;
&amp;lt;head&amp;gt;
    &amp;lt;meta charset="UTF-8"&amp;gt;
    &amp;lt;title&amp;gt;CDN Integration Example&amp;lt;/title&amp;gt;
    &amp;lt;link rel="stylesheet" href="{{ cdn_url }}/css/styles.css"&amp;gt;
&amp;lt;/head&amp;gt;
&amp;lt;body&amp;gt;
    &amp;lt;h1&amp;gt;Welcome to CDN-Integrated Flask App&amp;lt;/h1&amp;gt;
    &amp;lt;img src="{{ cdn_url }}/images/logo.png" alt="Logo"&amp;gt;
    &amp;lt;script src="{{ cdn_url }}/js/scripts.js"&amp;gt;&amp;lt;/script&amp;gt;
&amp;lt;/body&amp;gt;
&amp;lt;/html&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;em&gt;Figure 6: HTML Template Referencing CDN-hosted Assets&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Flask Application Code&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;from flask import Flask, render_template

app = Flask(__name__)

CDN_URL = 'https://your-cdn-domain.com/static'

@app.route('/')
def home():
    return render_template('index.html', cdn_url=CDN_URL)

if __name__ == '__main__':
    app.run(debug=True)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;em&gt;Figure 7: Flask Application Integrating CDN for Static Files&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Django Example: Configuring Static Files with CDN&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;In Django, integrating a CDN involves setting the &lt;code&gt;STATIC_URL&lt;/code&gt; to point to the CDN.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# settings.py

STATIC_URL = 'https://your-cdn-domain.com/static/'
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Run the following command to collect static files:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;python manage.py collectstatic
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;em&gt;Figure 8: Django Settings for CDN Integration&lt;/em&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Advanced CDN Features
&lt;/h2&gt;

&lt;p&gt;Modern CDNs offer a range of advanced features that go beyond basic content delivery, enhancing performance, security, and scalability.&lt;/p&gt;

&lt;h3&gt;
  
  
  Edge Computing and Serverless Functions
&lt;/h3&gt;

&lt;p&gt;CDNs are increasingly integrating edge computing capabilities, allowing developers to run serverless functions closer to end-users. This not only reduces latency but also enables real-time data processing.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Example: Deploying a Serverless Function with AWS Lambda@Edge&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Lambda@Edge allows you to execute code in response to events generated by CloudFront, such as viewer requests or origin responses. Here's a simple example of a Lambda function that modifies HTTP headers to enhance security:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;exports.handler = async (event) =&amp;gt; {
    const response = event.Records[0].cf.response;
    const headers = response.headers;

    // Add security headers
    headers['strict-transport-security'] = [{ key: 'Strict-Transport-Security', value: 'max-age=63072000; includeSubDomains; preload' }];
    headers['content-security-policy'] = [{ key: 'Content-Security-Policy', value: "default-src 'self'" }];
    headers['x-content-type-options'] = [{ key: 'X-Content-Type-Options', value: 'nosniff' }];
    headers['x-frame-options'] = [{ key: 'X-Frame-Options', value: 'DENY' }];
    headers['x-xss-protection'] = [{ key: 'X-XSS-Protection', value: '1; mode=block' }];

    return response;
};
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;em&gt;Figure 9: AWS Lambda@Edge Function to Modify HTTP Headers&lt;/em&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Real-Time Analytics and Monitoring
&lt;/h3&gt;

&lt;p&gt;Modern CDNs provide comprehensive analytics dashboards that offer insights into traffic patterns, cache performance, and security threats. By integrating these analytics, businesses can make data-driven decisions to optimize content delivery.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Python Example: Fetching CDN Analytics with AWS SDK&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import boto3
from datetime import datetime, timedelta

def fetch_cdn_metrics(distribution_id):
    client = boto3.client('cloudfront')
    end_time = datetime.utcnow()
    start_time = end_time - timedelta(hours=1)

    response = client.get_distribution_metrics(
        DistributionId=distribution_id,
        StartTime=start_time,
        EndTime=end_time,
        MetricNames=[
            'BytesDownloaded',
            'TotalErrorRate',
        ],
        Period=300,  # 5 minutes
    )

    return response['Metrics']

if __name__ == '__main__':
    distribution_id = 'YOUR_DISTRIBUTION_ID'
    metrics = fetch_cdn_metrics(distribution_id)
    print(metrics)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;em&gt;Figure 10: Fetching CDN Metrics with AWS SDK in Python&lt;/em&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Protocol Enhancements: HTTP/2 and HTTP/3
&lt;/h3&gt;

&lt;p&gt;CDNs leverage advanced protocols like HTTP/2 and HTTP/3 to enhance performance through features like multiplexing, header compression, and improved connection management. These protocols reduce latency and increase the efficiency of resource loading.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Node.js Example: Enabling HTTP/2 in an Express Server&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const fs = require('fs');
const http2 = require('http2');
const express = require('express');

const app = express();

// Serve static files
app.use('/static', express.static('public'));

// Premium content route
app.get('/premium', (req, res) =&amp;gt; {
  res.send('Premium Content');
});

// Load SSL certificates
const options = {
  key: fs.readFileSync('server.key'),
  cert: fs.readFileSync('server.crt')
};

// Create HTTP/2 server
const server = http2.createSecureServer(options, app);

server.listen(3000, () =&amp;gt; {
  console.log('HTTP/2 Server running on port 3000');
});
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;em&gt;Figure 11: Enabling HTTP/2 in Node.js with Express&lt;/em&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Advantages and Challenges
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Advantages of CDNs
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Reduced Latency:&lt;/strong&gt; Serving content from servers closer to users decreases the time it takes for data to reach them.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Scalability:&lt;/strong&gt; CDNs handle large volumes of traffic effortlessly, accommodating spikes without compromising performance.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Enhanced Security:&lt;/strong&gt; Built-in security features protect against common web threats and attacks.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Cost Efficiency:&lt;/strong&gt; Offloading traffic to edge servers reduces bandwidth costs and lowers the load on origin servers.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Challenges of CDNs
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Initial Setup Complexity:&lt;/strong&gt; Configuring and optimizing a CDN requires a solid understanding of its architecture and settings.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Cache Invalidation:&lt;/strong&gt; Ensuring outdated content is refreshed promptly can be tricky, especially for dynamic content.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Dependency on Providers:&lt;/strong&gt; Relying on third-party CDN providers can introduce dependencies that might not align with specific application requirements.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Costs at Scale:&lt;/strong&gt; While CDNs are cost-effective up to a point, very high traffic volumes can lead to substantial expenses, especially with bandwidth-intensive applications.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Future of CDNs
&lt;/h2&gt;

&lt;p&gt;The future of CDNs is being shaped by the integration of Internet of Things (IoT), edge computing, and Web3 technologies. Decentralized approaches are gaining momentum, offering alternatives to traditional centralized models. Additionally, advancements in edge computing are enabling more complex processing tasks to be offloaded to edge servers, further enhancing performance and capabilities.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Emerging Trends:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Serverless Edge Computing:&lt;/strong&gt; Combining serverless architectures with edge computing allows developers to deploy functions that run closer to users, reducing latency and enhancing scalability.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;AI-Driven Optimization:&lt;/strong&gt; Leveraging artificial intelligence to predict traffic patterns, optimize caching strategies, and bolster security measures in real-time.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Blockchain Integration:&lt;/strong&gt; Utilizing blockchain for decentralized CDN management, transparency in content delivery, and incentivizing node participation.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Decentralized CDNs:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Decentralized Content Delivery Networks (dCDNs) distribute content across a network of nodes operated by various participants, rather than relying on a single provider's edge servers. This approach enhances resilience, reduces dependency on single points of failure, and often leverages blockchain technologies for coordination and incentives.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Web3 Examples:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;IPFS (InterPlanetary File System):&lt;/strong&gt; A peer-to-peer protocol designed to make the web faster, safer, and more open by distributing content across numerous nodes. IPFS identifies files based on their content rather than their location, ensuring that once a file is added, it can be retrieved from multiple nodes.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Filecoin:&lt;/strong&gt; Built on top of IPFS, Filecoin incentivizes users to provide storage space in exchange for tokens. This creates a decentralized storage network where content is persistently stored and retrievable from various nodes.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Arweave:&lt;/strong&gt; A decentralized storage network that provides permanent data storage by leveraging a novel blockchain-like structure called the Blockweave. Arweave ensures that content remains accessible indefinitely without relying on centralized servers.&lt;br&gt;
&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;pragma solidity ^0.8.0;

contract FileMetadata {
    struct File {
        string cid;
        address uploader;
        uint256 timestamp;
    }

    mapping(uint256 =&amp;gt; File) public files;
    uint256 public fileCount;

    function uploadFile(string memory _cid) public {
        fileCount += 1;
        files[fileCount] = File(_cid, msg.sender, block.timestamp);
    }

    function getFile(uint256 _fileId) public view returns (string memory, address, uint256) {
        File memory file = files[_fileId];
        return (file.cid, file.uploader, file.timestamp);
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;em&gt;Figure 12: Filecoin Smart Contract Example&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;In this example, a simple smart contract allows users to upload and retrieve file metadata, linking it to the content-addressed CID (Content Identifier) in IPFS.&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;Content Delivery Networks are the backbone of modern internet infrastructure, ensuring that digital content is delivered swiftly, securely, and reliably to users worldwide. By breaking down CDN architecture, we've gained a clearer understanding of how each component contributes to overall performance and efficiency. Integrating CDNs into applications, whether built with Node.js or Python, can significantly enhance user experience by reducing latency and improving load times.&lt;/p&gt;

&lt;p&gt;As technology continues to advance, so do CDNs. They are evolving to offer new opportunities for optimization and decentralization. The rise of decentralized CDN models aligns with the growing emphasis on Web3 technologies, providing resilient and scalable alternatives to traditional centralized systems. Whether through established CDN providers or innovative decentralized networks, CDNs will remain at the forefront of optimizing and safeguarding digital content delivery.&lt;/p&gt;

&lt;h2&gt;
  
  
  References
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;&lt;a href="https://www.cloudflare.com/learning/cdn/what-is-a-cdn/" rel="noopener noreferrer"&gt;What is a CDN? - Cloudflare&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/Introduction.html" rel="noopener noreferrer"&gt;AWS CloudFront Documentation&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://expressjs.com/" rel="noopener noreferrer"&gt;Express.js Official Website&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://flask.palletsprojects.com/" rel="noopener noreferrer"&gt;Flask Official Documentation&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://docs.djangoproject.com/" rel="noopener noreferrer"&gt;Django Documentation&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://ipfs.io/" rel="noopener noreferrer"&gt;IPFS Official Website&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://filecoin.io/" rel="noopener noreferrer"&gt;Filecoin Official Website&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.arweave.org/" rel="noopener noreferrer"&gt;Arweave Official Website&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.contentstack.com/blog/cms-technology/ipfs-vs-cdns/" rel="noopener noreferrer"&gt;IPFS vs CDNs - An Analysis&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://docs.aws.amazon.com/lambda/latest/dg/lambda-edge.html" rel="noopener noreferrer"&gt;AWS Lambda@Edge Documentation&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://httpwg.org/specs/rfc7540.html" rel="noopener noreferrer"&gt;HTTP/2 Explained&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://httpwg.org/specs/rfc9114.html" rel="noopener noreferrer"&gt;HTTP/3 Overview&lt;/a&gt;&lt;/li&gt;
&lt;/ol&gt;

</description>
      <category>webdev</category>
      <category>javascript</category>
      <category>beginners</category>
      <category>programming</category>
    </item>
    <item>
      <title>Solving Inheritance Compatibility Issues Between LayerZero's NonblockingLzApp and OpenZeppelin's Ownable</title>
      <dc:creator>Jefferson </dc:creator>
      <pubDate>Mon, 04 Nov 2024 08:43:43 +0000</pubDate>
      <link>https://forem.com/jeffersonnnn/solving-inheritance-compatibility-issues-between-layerzeros-nonblockinglzapp-and-openzeppelins-ownable-3nae</link>
      <guid>https://forem.com/jeffersonnnn/solving-inheritance-compatibility-issues-between-layerzeros-nonblockinglzapp-and-openzeppelins-ownable-3nae</guid>
      <description>&lt;h2&gt;
  
  
  Table of Contents
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;&lt;a href="//notion://www.notion.so/Articles-127d9457552e8090bff1dc5e154e8e47#introduction"&gt;Introduction&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;
&lt;a href="//notion://www.notion.so/Articles-127d9457552e8090bff1dc5e154e8e47#background"&gt;Background&lt;/a&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="//notion://www.notion.so/Articles-127d9457552e8090bff1dc5e154e8e47#layerzeros-nonblockinglzapp"&gt;LayerZero's NonblockingLzApp&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="//notion://www.notion.so/Articles-127d9457552e8090bff1dc5e154e8e47#openzeppelins-ownable"&gt;OpenZeppelin's Ownable&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;&lt;a href="//notion://www.notion.so/Articles-127d9457552e8090bff1dc5e154e8e47#the-problem"&gt;The Problem&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="//notion://www.notion.so/Articles-127d9457552e8090bff1dc5e154e8e47#analyzing-the-incompatibility"&gt;Analyzing the Incompatibility&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="//notion://www.notion.so/Articles-127d9457552e8090bff1dc5e154e8e47#solution-creating-lzappadaptersol"&gt;Solution: Creating LzAppAdapter.sol&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;
&lt;a href="//notion://www.notion.so/Articles-127d9457552e8090bff1dc5e154e8e47#implementation-details"&gt;Implementation Details&lt;/a&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="//notion://www.notion.so/Articles-127d9457552e8090bff1dc5e154e8e47#lzappadaptersol"&gt;LzAppAdapter.sol&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="//notion://www.notion.so/Articles-127d9457552e8090bff1dc5e154e8e47#savingsgrouppocsol"&gt;SavingsGroupPoC.sol&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="//notion://www.notion.so/Articles-127d9457552e8090bff1dc5e154e8e47#ownablesol"&gt;Ownable.sol&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;a href="//notion://www.notion.so/Articles-127d9457552e8090bff1dc5e154e8e47#code-walkthrough"&gt;Code Walkthrough&lt;/a&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="//notion://www.notion.so/Articles-127d9457552e8090bff1dc5e154e8e47#lzappadaptersol-1"&gt;LzAppAdapter.sol&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="//notion://www.notion.so/Articles-127d9457552e8090bff1dc5e154e8e47#savingsgrouppocsol-1"&gt;SavingsGroupPoC.sol&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;&lt;a href="//notion://www.notion.so/Articles-127d9457552e8090bff1dc5e154e8e47#testing-the-adapter"&gt;Testing the Adapter&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="//notion://www.notion.so/Articles-127d9457552e8090bff1dc5e154e8e47#benefits-of-the-adapter-pattern"&gt;Benefits of the Adapter Pattern&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="//notion://www.notion.so/Articles-127d9457552e8090bff1dc5e154e8e47#potential-issues-and-considerations"&gt;Potential Issues and Considerations&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="//notion://www.notion.so/Articles-127d9457552e8090bff1dc5e154e8e47#conclusion"&gt;Conclusion&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="//notion://www.notion.so/Articles-127d9457552e8090bff1dc5e154e8e47#references"&gt;References&lt;/a&gt;&lt;/li&gt;
&lt;/ol&gt;




&lt;h2&gt;
  
  
  Introduction
&lt;/h2&gt;

&lt;p&gt;Very recently, I became interested in Chain Abstraction in Web3. You see, I entered the industry in 2020 with my first job as a Technical Writer at Polygon, helping to create documentation on understanding Ethereum scaling. Back then, it was Polygon and a few other scaling solutions, all built on the world’s decentralized computer, Ethereum. That was the state of Ethereum. Today, things are vastly different—everything is evolving rapidly. In the current blockchain landscape, integrating multiple libraries and frameworks is commonplace, but such integrations can sometimes lead to compatibility issues, especially when different libraries have overlapping functionalities or differing implementations. This article delves into a specific compatibility problem encountered when combining LayerZero’s NonblockingLzApp contract with OpenZeppelin’s Ownable contract. We explore the nature of the problem, the underlying causes, and the elegant solution implemented through an adapter pattern.&lt;/p&gt;

&lt;h2&gt;
  
  
  Background
&lt;/h2&gt;

&lt;h3&gt;
  
  
  LayerZero's NonblockingLzApp
&lt;/h3&gt;

&lt;p&gt;LayerZero is an Omnichain Interoperability Protocol designed to facilitate seamless communication and interactions across different blockchain networks. At its core, LayerZero provides contracts like &lt;code&gt;LzApp&lt;/code&gt; and &lt;code&gt;NonblockingLzApp&lt;/code&gt; to handle message passing, ensuring reliability and security in cross-chain transactions.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;LzApp.sol&lt;/strong&gt;: This contract serves as a generic receiver implementation, allowing contracts to handle incoming messages from other chains. It inherits from OpenZeppelin's &lt;code&gt;Ownable&lt;/code&gt; contract to manage ownership privileges.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;NonblockingLzApp.sol&lt;/strong&gt;: An extension of &lt;code&gt;LzApp&lt;/code&gt;, this abstract contract modifies the default blocking behavior of message handling. Instead of halting the message pathway upon encountering a failed message, it attempts to catch failures and store them locally for future retries, thereby ensuring non-blocking communication.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  OpenZeppelin's Ownable
&lt;/h3&gt;

&lt;p&gt;OpenZeppelin is a widely-adopted library providing secure and community-vetted smart contract components. Among its offerings, the &lt;code&gt;Ownable&lt;/code&gt; contract is fundamental, facilitating the management of ownership and access control within contracts.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Ownable.sol&lt;/strong&gt;: This contract module defines an owner account with exclusive access to specific functions. It employs constructor parameters to set the initial owner, which can later be transferred or renounced.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  The Problem
&lt;/h2&gt;

&lt;p&gt;When integrating LayerZero's &lt;code&gt;NonblockingLzApp&lt;/code&gt; with OpenZeppelin's &lt;code&gt;Ownable&lt;/code&gt;, a compatibility issue arises due to differing implementations of the &lt;code&gt;Ownable&lt;/code&gt; contract. Specifically:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Constructor Parameter Mismatch&lt;/strong&gt;: LayerZero's &lt;code&gt;LzApp&lt;/code&gt; inherits from an older version of OpenZeppelin's &lt;code&gt;Ownable&lt;/code&gt; that does not accept constructor parameters, whereas the latest versions of OpenZeppelin's &lt;code&gt;Ownable&lt;/code&gt; require the initial owner to be set via constructor arguments.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Multiple Inheritance Conflicts&lt;/strong&gt;: Directly inheriting from both &lt;code&gt;NonblockingLzApp&lt;/code&gt; and the latest &lt;code&gt;Ownable&lt;/code&gt; can lead to inheritance order conflicts and constructor argument mismatches, resulting in compilation errors or unintended behavior.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;This incompatibility necessitates an intermediary mechanism to bridge the gap between the two libraries, ensuring smooth integration without sacrificing the functionalities provided by either.&lt;/p&gt;

&lt;h2&gt;
  
  
  Analyzing the Incompatibility
&lt;/h2&gt;

&lt;p&gt;To comprehend the root of the issue, let's dissect the inheritance structures:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;LayerZero's LzApp&lt;/strong&gt;:&lt;br&gt;
&lt;/p&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;abstract contract LzApp is Ownable {
    constructor(address _endpoint) {
        lzEndpoint = ILayerZeroEndpoint(_endpoint);
    }
    // Additional functionalities...
}

&lt;/code&gt;&lt;/pre&gt;

&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;OpenZeppelin's Ownable (Latest Version)&lt;/strong&gt;:&lt;br&gt;
&lt;/p&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;abstract contract Ownable is Context {
    address private _owner;

    constructor(address initialOwner) {
        require(initialOwner != address(0), "Ownable: owner is the zero address");
        _owner = initialOwner;
    }

    // Ownership management functions...
}

&lt;/code&gt;&lt;/pre&gt;

&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;In the latest &lt;code&gt;Ownable&lt;/code&gt;, the constructor expects an &lt;code&gt;initialOwner&lt;/code&gt; parameter, ensuring that ownership is explicitly set upon deployment. Conversely, older versions used by LayerZero's &lt;code&gt;LzApp&lt;/code&gt; did not require such parameters, implicitly setting the deployer as the owner.&lt;/p&gt;

&lt;p&gt;This discrepancy leads to conflicts when attempting to combine both contracts, as Solidity cannot reconcile the differing constructor signatures during contract initialization.&lt;/p&gt;

&lt;h2&gt;
  
  
  Solution: Creating LzAppAdapter.sol
&lt;/h2&gt;

&lt;p&gt;To resolve the incompatibility, we introduce an adapter contract named &lt;code&gt;LzAppAdapter.sol&lt;/code&gt;. This adapter serves as a bridge, harmonizing the constructor parameters and inheritance hierarchy, thereby enabling seamless integration between LayerZero's &lt;code&gt;NonblockingLzApp&lt;/code&gt; and OpenZeppelin's &lt;code&gt;Ownable&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Key Objectives of LzAppAdapter.sol&lt;/strong&gt;:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Inherit from NonblockingLzApp&lt;/strong&gt;: Maintain LayerZero's message handling capabilities.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Initialize Ownable Correctly&lt;/strong&gt;: Ensure that the correct owner is set using the latest OpenZeppelin &lt;code&gt;Ownable&lt;/code&gt; constructor.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Facilitate Smooth Integration&lt;/strong&gt;: Enable subsequent contracts to inherit from &lt;code&gt;LzAppAdapter&lt;/code&gt; without encountering inheritance conflicts.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  Implementation Details
&lt;/h2&gt;

&lt;h3&gt;
  
  
  LzAppAdapter.sol
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;

import "@layerzerolabs/solidity-examples/contracts/lzApp/NonblockingLzApp.sol";

abstract contract LzAppAdapter is NonblockingLzApp {
    constructor(address _endpoint) NonblockingLzApp(_endpoint) Ownable(msg.sender) {}
}

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Explanation&lt;/strong&gt;:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Inheritance&lt;/strong&gt;: &lt;code&gt;LzAppAdapter&lt;/code&gt; inherits from &lt;code&gt;NonblockingLzApp&lt;/code&gt;, ensuring that all LayerZero functionalities are retained.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Constructor&lt;/strong&gt;: The adapter's constructor takes an &lt;code&gt;_endpoint&lt;/code&gt; address, passing it to &lt;code&gt;NonblockingLzApp&lt;/code&gt;. Simultaneously, it explicitly initializes &lt;code&gt;Ownable&lt;/code&gt; with &lt;code&gt;msg.sender&lt;/code&gt;, ensuring that the deployer is set as the initial owner, conforming to the latest OpenZeppelin standards.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  SavingsGroupPoC.sol
&lt;/h3&gt;

&lt;p&gt;This contract demonstrates how to inherit from the &lt;code&gt;LzAppAdapter&lt;/code&gt; to leverage both LayerZero's cross-chain messaging and OpenZeppelin's ownership management.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;

import "./LzAppAdapter.sol";
import "@openzeppelin/contracts/token/ERC20/IERC20.sol";

/**
 * @title SavingsGroupPoC
 * @dev A Proof of Concept contract for Savings Groups utilizing LayerZero for cross-chain interactions.
 */
contract SavingsGroupPoC is LzAppAdapter {
    IERC20 public stablecoin;

    struct Group {
        uint256 contributionAmount;
        uint256 cycleLength;
        uint256 maxMembers;
        mapping(address =&amp;gt; bool) members;
        uint256 memberCount;
    }

    mapping(uint256 =&amp;gt; Group) public groups;
    uint256 public nextGroupId;

    uint16 constant MSG_CONTRIBUTE = 1;
    uint16 constant MSG_PAYOUT = 2;

    /**
     * @notice Constructor for SavingsGroupPoC
     * @param _lzEndpoint Address of the LayerZero endpoint
     * @param _stablecoin Address of the stablecoin ERC20 token
     */
    constructor(
        address _lzEndpoint,
        address _stablecoin
    ) LzAppAdapter(_lzEndpoint) {
        stablecoin = IERC20(_stablecoin);
    }

    // Additional functionalities...
}

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Ownable.sol
&lt;/h3&gt;

&lt;p&gt;Ensure that you are using the latest version of OpenZeppelin's &lt;code&gt;Ownable&lt;/code&gt; contract, which requires an initial owner to be set via the constructor.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (access/Ownable.sol)

pragma solidity ^0.8.20;

import {Context} from "../utils/Context.sol";

/**
 * @dev Contract module which provides a basic access control mechanism, where
 * there is an account (an owner) that can be granted exclusive access to
 * specific functions.
 *
 * The initial owner is set to the address provided by the deployer. This can
 * later be changed with {transferOwnership}.
 *
 * This module is used through inheritance. It will make available the modifier
 * `onlyOwner`, which can be applied to your functions to restrict their use to
 * the owner.
 */
abstract contract Ownable is Context {
    address private _owner;

    /**
     * @dev The caller account is not authorized to perform an operation.
     */
    error OwnableUnauthorizedAccount(address account);

    /**
     * @dev The owner is not a valid owner account. (eg. `address(0)`)
     */
    error OwnableInvalidOwner(address owner);

    event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);

    constructor(address initialOwner) {
        if (initialOwner == address(0)) {
            revert OwnableInvalidOwner(initialOwner);
        }
        _transferOwnership(initialOwner);
    }

    /**
     * @dev Throws if called by any account other than the owner.
     */
    modifier onlyOwner() {
        _checkOwner();
        _;
    }

    /**
     * @dev Returns the address of the current owner.
     */
    function owner() public view virtual returns (address) {
        return _owner;
    }

    /**
     * @dev Revert with custom message if the caller is not the owner.
     */
    function _checkOwner() internal view virtual {
        if (owner() != _msgSender()) {
            revert OwnableUnauthorizedAccount(_msgSender());
        }
    }

    /**
     * @dev Transfers ownership to a new account (`newOwner`).
     * Can only be called by the current owner.
     */
    function transferOwnership(address newOwner) public virtual onlyOwner {
        if (newOwner == address(0)) {
            revert OwnableInvalidOwner(newOwner);
        }
        _transferOwnership(newOwner);
    }

    /**
     * @dev Internal function to transfer ownership.
     */
    function _transferOwnership(address newOwner) internal virtual {
        address oldOwner = _owner;
        _owner = newOwner;
        emit OwnershipTransferred(oldOwner, newOwner);
    }
}

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Code Walkthrough
&lt;/h2&gt;

&lt;h3&gt;
  
  
  LzAppAdapter.sol
&lt;/h3&gt;

&lt;p&gt;The &lt;code&gt;LzAppAdapter&lt;/code&gt; serves as a crucial intermediary between LayerZero's messaging contracts and OpenZeppelin's ownership model.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;

import "@layerzerolabs/solidity-examples/contracts/lzApp/NonblockingLzApp.sol";

abstract contract LzAppAdapter is NonblockingLzApp {
    constructor(address _endpoint) NonblockingLzApp(_endpoint) Ownable(msg.sender) {}
}

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Inheritance&lt;/strong&gt;: By inheriting from &lt;code&gt;NonblockingLzApp&lt;/code&gt;, the adapter retains all functionalities related to non-blocking cross-chain messaging.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Constructor Logic&lt;/strong&gt;: The constructor takes an &lt;code&gt;_endpoint&lt;/code&gt; address required by &lt;code&gt;NonblockingLzApp&lt;/code&gt; and simultaneously initializes &lt;code&gt;Ownable&lt;/code&gt; by passing &lt;code&gt;msg.sender&lt;/code&gt; as the initial owner. This dual initialization resolves the constructor parameter mismatch issue.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  SavingsGroupPoC.sol
&lt;/h3&gt;

&lt;p&gt;This contract exemplifies how &lt;code&gt;SavingsGroupPoC&lt;/code&gt; leverages the adapter to utilize both LayerZero's and OpenZeppelin's features seamlessly.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;

import "./LzAppAdapter.sol";
import "@openzeppelin/contracts/token/ERC20/IERC20.sol";

/**
 * @title SavingsGroupPoC
 * @dev A Proof of Concept contract for Savings Groups utilizing LayerZero for cross-chain interactions.
 */
contract SavingsGroupPoC is LzAppAdapter {
    IERC20 public stablecoin;

    struct Group {
        uint256 contributionAmount;
        uint256 cycleLength;
        uint256 maxMembers;
        mapping(address =&amp;gt; bool) members;
        uint256 memberCount;
    }

    mapping(uint256 =&amp;gt; Group) public groups;
    uint256 public nextGroupId;

    uint16 constant MSG_CONTRIBUTE = 1;
    uint16 constant MSG_PAYOUT = 2;

    /**
     * @notice Constructor for SavingsGroupPoC
     * @param _lzEndpoint Address of the LayerZero endpoint
     * @param _stablecoin Address of the stablecoin ERC20 token
     */
    constructor(
        address _lzEndpoint,
        address _stablecoin
    ) LzAppAdapter(_lzEndpoint) {
        stablecoin = IERC20(_stablecoin);
    }

    function createGroup(
        uint256 _contributionAmount,
        uint256 _cycleLength,
        uint256 _maxMembers
    ) external returns (uint256) {
        uint256 groupId = nextGroupId++;
        Group storage group = groups[groupId];
        group.contributionAmount = _contributionAmount;
        group.cycleLength = _cycleLength;
        group.maxMembers = _maxMembers;
        group.members[msg.sender] = true;
        group.memberCount = 1;
        return groupId;
    }

    function _nonblockingLzReceive(
        uint16 _srcChainId,
        bytes memory _srcAddress,
        uint64 _nonce,
        bytes memory _payload
    ) internal override {
        (uint16 messageType, uint256 groupId, address member, uint256 amount) =
            abi.decode(_payload, (uint16, uint256, address, uint256));

        if (messageType == MSG_CONTRIBUTE) {
            // Handle contribution received from another chain
            Group storage group = groups[groupId];
            if (!group.members[member] &amp;amp;&amp;amp; group.memberCount &amp;lt; group.maxMembers) {
                group.members[member] = true;
                group.memberCount++;
            }
        }
    }

    function contribute(uint256 _groupId, uint16 _dstChainId) external payable {
        Group storage group = groups[_groupId];
        require(group.members[msg.sender], "Not a member");

        // Transfer stablecoins to this contract
        stablecoin.transferFrom(msg.sender, address(this), group.contributionAmount);

        bytes memory payload = abi.encode(
            MSG_CONTRIBUTE,
            _groupId,
            msg.sender,
            group.contributionAmount
        );

        _lzSend(
            _dstChainId,
            payload,
            payable(msg.sender),
            address(0x0),
            bytes(""),
            msg.value
        );
    }

    // View functions
    function getGroup(uint256 _groupId) external view returns (
        uint256 contributionAmount,
        uint256 cycleLength,
        uint256 maxMembers,
        uint256 memberCount
    ) {
        Group storage group = groups[_groupId];
        return (
            group.contributionAmount,
            group.cycleLength,
            group.maxMembers,
            group.memberCount
        );
    }
}

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Key Components&lt;/strong&gt;:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Stablecoin Integration&lt;/strong&gt;: The contract interacts with an ERC20 stablecoin, facilitating contributions across chains.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Group Management&lt;/strong&gt;: Implements functionality to create and manage savings groups, ensuring members contribute the requisite amounts.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Cross-Chain Messaging&lt;/strong&gt;: Utilizes LayerZero's messaging capabilities to handle contributions received from other chains, maintaining the integrity and membership limits of each group.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Ownable.sol
&lt;/h3&gt;

&lt;p&gt;Adhering to the latest OpenZeppelin standards, the &lt;code&gt;Ownable&lt;/code&gt; contract ensures secure ownership management.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (access/Ownable.sol)

pragma solidity ^0.8.20;

import {Context} from "../utils/Context.sol";

/**
 * @dev Contract module which provides a basic access control mechanism, where
 * there is an account (an owner) that can be granted exclusive access to
 * specific functions.
 *
 * The initial owner is set to the address provided by the deployer. This can
 * later be changed with {transferOwnership}.
 *
 * This module is used through inheritance. It will make available the modifier
 * `onlyOwner`, which can be applied to your functions to restrict their use to
 * the owner.
 */
abstract contract Ownable is Context {
    address private _owner;

    /**
     * @dev The caller account is not authorized to perform an operation.
     */
    error OwnableUnauthorizedAccount(address account);

    /**
     * @dev The owner is not a valid owner account. (eg. `address(0)`)
     */
    error OwnableInvalidOwner(address owner);

    event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);

    constructor(address initialOwner) {
        if (initialOwner == address(0)) {
            revert OwnableInvalidOwner(initialOwner);
        }
        _transferOwnership(initialOwner);
    }

    /**
     * @dev Throws if called by any account other than the owner.
     */
    modifier onlyOwner() {
        _checkOwner();
        _;
    }

    /**
     * @dev Returns the address of the current owner.
     */
    function owner() public view virtual returns (address) {
        return _owner;
    }

    /**
     * @dev Revert with custom message if the caller is not the owner.
     */
    function _checkOwner() internal view virtual {
        if (owner() != _msgSender()) {
            revert OwnableUnauthorizedAccount(_msgSender());
        }
    }

    /**
     * @dev Transfers ownership to a new account (`newOwner`).
     * Can only be called by the current owner.
     */
    function transferOwnership(address newOwner) public virtual onlyOwner {
        if (newOwner == address(0)) {
            revert OwnableInvalidOwner(newOwner);
        }
        _transferOwnership(newOwner);
    }

    /**
     * @dev Internal function to transfer ownership.
     */
    function _transferOwnership(address newOwner) internal virtual {
        address oldOwner = _owner;
        _owner = newOwner;
        emit OwnershipTransferred(oldOwner, newOwner);
    }
}

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Key Features&lt;/strong&gt;:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Constructor Parameter&lt;/strong&gt;: Requires an explicit &lt;code&gt;initialOwner&lt;/code&gt;, aligning with modern best practices for ownership initialization.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Ownership Transfers&lt;/strong&gt;: Facilitates secure transfers of ownership, ensuring that only valid addresses can be set as new owners.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Access Control Modifier&lt;/strong&gt;: The &lt;code&gt;onlyOwner&lt;/code&gt; modifier restricts function access exclusively to the owner, enhancing security.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Testing the Adapter
&lt;/h2&gt;

&lt;p&gt;To ensure that the &lt;code&gt;LzAppAdapter&lt;/code&gt; seamlessly integrates LayerZero's messaging with OpenZeppelin's ownership, comprehensive testing is essential. Here's a step-by-step guide to testing the adapter:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Setup Development Environment&lt;/strong&gt;:

&lt;ul&gt;
&lt;li&gt;Install necessary dependencies using &lt;code&gt;yarn&lt;/code&gt; or &lt;code&gt;npm&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;Configure your development environment to include both LayerZero and OpenZeppelin contracts.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Deploy Contracts&lt;/strong&gt;:

&lt;ul&gt;
&lt;li&gt;Deploy the &lt;code&gt;LzAppAdapter&lt;/code&gt; with the appropriate LayerZero endpoint.&lt;/li&gt;
&lt;li&gt;Deploy the &lt;code&gt;SavingsGroupPoC&lt;/code&gt; contract, ensuring that the adapter is correctly initialized.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Ownership Verification&lt;/strong&gt;:

&lt;ul&gt;
&lt;li&gt;Verify that the deployer of &lt;code&gt;SavingsGroupPoC&lt;/code&gt; is correctly set as the owner.&lt;/li&gt;
&lt;li&gt;Test ownership transfer functionalities to ensure that the &lt;code&gt;transferOwnership&lt;/code&gt; function works as intended.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Cross-Chain Messaging&lt;/strong&gt;:

&lt;ul&gt;
&lt;li&gt;Simulate cross-chain messages to verify that &lt;code&gt;NonblockingLzApp&lt;/code&gt; functions correctly within the &lt;code&gt;SavingsGroupPoC&lt;/code&gt; context.&lt;/li&gt;
&lt;li&gt;Ensure that contributions from other chains are handled appropriately without blocking the message pathway.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Error Handling&lt;/strong&gt;:

&lt;ul&gt;
&lt;li&gt;Attempt to initialize contracts with invalid owner addresses (e.g., &lt;code&gt;address(0)&lt;/code&gt;) to confirm that the contract reverts as expected.&lt;/li&gt;
&lt;li&gt;Test access-restricted functions to ensure that only the owner can execute them.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Integration Tests&lt;/strong&gt;:

&lt;ul&gt;
&lt;li&gt;Create test scenarios where multiple groups are created, and members contribute across different chains.&lt;/li&gt;
&lt;li&gt;Validate that member counts and contributions are accurately tracked and managed.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;By following these testing steps, developers can confidently integrate &lt;code&gt;LzAppAdapter&lt;/code&gt; into their projects, leveraging the strengths of both LayerZero and OpenZeppelin without running into ownership conflicts.&lt;/p&gt;

&lt;h2&gt;
  
  
  Benefits of the Adapter Pattern
&lt;/h2&gt;

&lt;p&gt;Implementing an adapter like &lt;code&gt;LzAppAdapter&lt;/code&gt; offers several advantages:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Separation of Concerns&lt;/strong&gt;: Isolates the compatibility logic between LayerZero and OpenZeppelin, making the codebase cleaner and more maintainable.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Reusability&lt;/strong&gt;: The adapter can be reused across multiple contracts that require similar integrations, promoting DRY (Don't Repeat Yourself) principles.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Flexibility&lt;/strong&gt;: Facilitates easy upgrades or changes in either library without necessitating widespread modifications across dependent contracts.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Enhanced Security&lt;/strong&gt;: By centralizing the compatibility logic, it's easier to audit and ensure that ownership and access controls are correctly implemented, reducing the risk of vulnerabilities.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Simplified Inheritance&lt;/strong&gt;: Prevents complex multiple inheritance scenarios that can lead to ambiguous behavior or constructor conflicts.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  Potential Issues and Considerations
&lt;/h2&gt;

&lt;p&gt;While the adapter pattern provides a robust solution, i find that developers should be mindful of the following:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Inherited Functionalities&lt;/strong&gt;: Ensure that the adapter doesn't inadvertently override or interfere with functionalities provided by either LayerZero or OpenZeppelin.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Constructor Arguments&lt;/strong&gt;: Maintain consistency in constructor arguments across all inherited contracts to prevent initialization issues.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Future Updates&lt;/strong&gt;: Stay updated with both LayerZero's and OpenZeppelin's contract updates to ensure ongoing compatibility. Changes in either library will only naturally necessitate adjustments in the adapter.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Gas Optimization&lt;/strong&gt;: While in general, adapters promote clean code, they can introduce additional layers that might slightly impact gas costs. It's essential to monitor and optimize where possible.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Comprehensive Testing&lt;/strong&gt;: Given the critical role of ownership and cross-chain messaging, rigorous testing is paramount to ensure that both systems interact as intended without conflicts.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;Web3 has advanced significantly, with Layer 2 solutions (L2s) becoming the de rigueur for scaling the world computer. However, silos and fragmentation are the inevitable consequences of this new paradigm. Integrating multiple smart contract libraries in such a fragmented ecosystem presents unique challenges, particularly when dealing with overlapping functionalities like ownership management. The compatibility issue between LayerZero’s &lt;code&gt;NonblockingLzApp&lt;/code&gt; and OpenZeppelin’s &lt;code&gt;Ownable&lt;/code&gt; serves as a prime example of these challenges. By employing the adapter pattern through &lt;code&gt;LzAppAdapter.sol&lt;/code&gt;, we effectively bridged the constructor parameter mismatch and inheritance conflicts, ensuring seamless integration of cross-chain messaging with secure ownership controls.&lt;/p&gt;

&lt;p&gt;This approach not only resolves the immediate compatibility issue but also sets a foundation for scalable and maintainable contract architectures in future developments. As the blockchain ecosystem continues to grow, such design patterns will be invaluable in navigating the complexities of integrating diverse libraries and frameworks.&lt;/p&gt;

&lt;h2&gt;
  
  
  References
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://docs.layerzero.network/" rel="noopener noreferrer"&gt;LayerZero Documentation&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://github.com/OpenZeppelin/openzeppelin-contracts" rel="noopener noreferrer"&gt;OpenZeppelin Contracts&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://soliditylang.org/" rel="noopener noreferrer"&gt;Solidity&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://github.com/LayerZero-Labs/solidity-examples" rel="noopener noreferrer"&gt;LayerZero GitHub Repository&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://docs.openzeppelin.com/contracts/" rel="noopener noreferrer"&gt;OpenZeppelin Documentation&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

</description>
    </item>
    <item>
      <title>Introducing PolyForge: Empowering Polygon Developers with a Robust CLI Tool</title>
      <dc:creator>Jefferson </dc:creator>
      <pubDate>Wed, 14 Aug 2024 23:49:34 +0000</pubDate>
      <link>https://forem.com/jeffersonnnn/introducing-polyforge-empowering-polygon-developers-with-a-robust-cli-tool-44h</link>
      <guid>https://forem.com/jeffersonnnn/introducing-polyforge-empowering-polygon-developers-with-a-robust-cli-tool-44h</guid>
      <description>&lt;h2&gt;
  
  
  Revolutionizing Smart Contract Development on Polygon
&lt;/h2&gt;

&lt;p&gt;Dear Polygon Community,&lt;/p&gt;

&lt;p&gt;I'm thrilled to announce the launch of PolyForge, a powerful new CLI tool designed to streamline and enhance the development experience for Polygon developers. PolyForge is set to revolutionize how we deploy, interact with, and test smart contracts across various Polygon networks.&lt;/p&gt;

&lt;h2&gt;
  
  
  The Challenge: Simplifying Polygon Development
&lt;/h2&gt;

&lt;p&gt;As the Polygon ecosystem continues to grow, developers face increasing complexity in managing deployments, interactions, and testing across multiple networks. The need for a unified, efficient toolset has become more apparent than ever. Current solutions often require juggling multiple tools or writing custom scripts, leading to inefficiencies and potential errors.&lt;/p&gt;

&lt;h2&gt;
  
  
  Enter PolyForge: Your All-in-One Polygon Development Companion
&lt;/h2&gt;

&lt;p&gt;PolyForge addresses these challenges head-on by providing a comprehensive, easy-to-use CLI tool that simplifies the entire development workflow. From seamless contract deployment to intuitive interaction and robust testing capabilities, PolyForge is designed to be the go-to tool for Polygon developers of all experience levels.&lt;/p&gt;

&lt;h2&gt;
  
  
  Key Features That Set PolyForge Apart
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Multi-Network Support&lt;/strong&gt;: Deploy and interact with contracts on various Polygon networks (PoS, Amoy, zkEVM, zkEVM Testnet) with ease.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Streamlined Deployment&lt;/strong&gt;: Deploy your smart contracts with a single command, handling all the complexities behind the scenes.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Interactive Contract Calls&lt;/strong&gt;: Easily interact with deployed contracts, supporting complex parameter types and payable functions.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Integrated Testing Framework&lt;/strong&gt;: Run comprehensive tests for your smart contracts directly from the CLI.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Secure Key Management&lt;/strong&gt;: Safely store and manage your private keys for different networks.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Network Switching&lt;/strong&gt;: Effortlessly switch between different Polygon networks for testing and deployment.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  Technical Deep Dive
&lt;/h2&gt;

&lt;p&gt;PolyForge is built with a focus on developer experience and robustness. Let's explore some of its core functionalities:&lt;/p&gt;

&lt;h3&gt;
  
  
  Deployment Made Simple
&lt;/h3&gt;

&lt;p&gt;Deploying a contract is as easy as:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;polyforge deploy ./path/to/YourContract.json &lt;span class="nt"&gt;-n&lt;/span&gt; pos &lt;span class="nt"&gt;-k&lt;/span&gt; mykey
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Behind the scenes, PolyForge handles network configuration, gas estimation, and transaction signing, ensuring a smooth deployment process.&lt;/p&gt;

&lt;h3&gt;
  
  
  Intuitive Contract Interaction
&lt;/h3&gt;

&lt;p&gt;Interacting with deployed contracts is straightforward:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;polyforge interact 0x1234...5678 ./Contract.json someMethod param1 param2 &lt;span class="nt"&gt;-n&lt;/span&gt; zkevm &lt;span class="nt"&gt;-k&lt;/span&gt; mykey
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;PolyForge automatically parses complex parameters, handles type conversions, and supports payable functions, making contract interaction a breeze.&lt;/p&gt;

&lt;h3&gt;
  
  
  Robust Testing Framework
&lt;/h3&gt;

&lt;p&gt;PolyForge's integrated testing framework allows you to write and run tests effortlessly:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;describe('SimpleStorage Contract', () =&amp;gt; {
  let contract;
  let signer;

  beforeEach(async () =&amp;gt; {
    const provider = new ethers.JsonRpcProvider('http://localhost:8545');
    signer = await provider.getSigner();
    const factory = new ethers.ContractFactory([], [], signer);
    contract = await factory.deploy();
    await contract.waitForDeployment();
  });

  it.skip('should deploy successfully', async () =&amp;gt; {
    const address = await contract.getAddress();
    expect(ethers.isAddress(address)).toBe(true);
  });

  it('should set value correctly', async () =&amp;gt; {
    const testValue = 42;
    await contract.setValue(testValue);
    const value = await contract.getValue();
    expect(value).toEqual(BigInt(testValue));
  });

  it('should get value correctly', async () =&amp;gt; {
    const testValue = 42;
    await contract.setValue(testValue);
    const value = await contract.getValue();
    expect(value).toEqual(BigInt(testValue));
  });
});
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This test suite demonstrates how easy it is to write comprehensive tests for your smart contracts using PolyForge.&lt;/p&gt;

&lt;h2&gt;
  
  
  Real-World Use Cases
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;DeFi Protocol Development&lt;/strong&gt;: Rapidly deploy and test complex DeFi protocols across multiple Polygon networks.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;NFT Project Launches&lt;/strong&gt;: Streamline the process of deploying and testing NFT smart contracts.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Cross-Chain Applications&lt;/strong&gt;: Easily manage deployments and interactions for applications spanning multiple Polygon networks.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Automated Testing Pipelines&lt;/strong&gt;: Integrate PolyForge into CI/CD workflows for automated contract testing and deployment.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  Benefits to the Polygon Community
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Accelerated Development&lt;/strong&gt;: Reduce development time and increase productivity.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Improved Code Quality&lt;/strong&gt;: Comprehensive testing capabilities lead to more robust smart contracts.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Lower Entry Barrier&lt;/strong&gt;: Make Polygon development more accessible to newcomers.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Standardization&lt;/strong&gt;: Promote best practices and standardization in the development process.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Enhanced Security&lt;/strong&gt;: Secure key management and thorough testing reduce the risk of vulnerabilities.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  Looking Ahead: The PolyForge Roadmap
&lt;/h2&gt;

&lt;p&gt;I'm committed to continually improving PolyForge to meet the evolving needs of the Polygon community. My future roadmap includes:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Gas optimization features&lt;/li&gt;
&lt;li&gt;Contract verification support&lt;/li&gt;
&lt;li&gt;Integration with popular IDEs (VS Code, IntelliJ)&lt;/li&gt;
&lt;li&gt;Support for batch operations&lt;/li&gt;
&lt;li&gt;Enhanced analytics and monitoring capabilities&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  Join the PolyForge Revolution
&lt;/h2&gt;

&lt;p&gt;I invite the Polygon community to embrace PolyForge and experience the future of smart contract development. Here's how you can get involved:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Try PolyForge&lt;/strong&gt;: Install and start using PolyForge today. Your feedback is invaluable!&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Contribute&lt;/strong&gt;: PolyForge is open-source. I welcome contributions from the community to make it even better.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Spread the Word&lt;/strong&gt;: Share your experience with PolyForge and help grow the community.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Provide Feedback&lt;/strong&gt;: Your insights will shape the future of PolyForge.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;To get started, visit the GitHub repository: &lt;a href="https://github.com/jeffersonnnn/polyforge" rel="noopener noreferrer"&gt;PolyForge GitHub&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;PolyForge is more than just a tool; it's a step towards a more efficient, secure, and collaborative Polygon development ecosystem. Join me in this exciting journey as we forge the future of Polygon development together&lt;/p&gt;

</description>
    </item>
    <item>
      <title>2024 in Learning and Building</title>
      <dc:creator>Jefferson </dc:creator>
      <pubDate>Mon, 19 Feb 2024 19:02:31 +0000</pubDate>
      <link>https://forem.com/jeffersonnnn/2024-in-learning-and-building-6ao</link>
      <guid>https://forem.com/jeffersonnnn/2024-in-learning-and-building-6ao</guid>
      <description>&lt;p&gt;Since writing my first line of code in my second year of a liberal arts degree in college on freecodecamp, I have spent a significant portion of my days almost without fail writing what humans understand as machine-readable text to instruct a computer on what it needs to do for me. Code and later software engineering has been with me through highs and lows, through the hobbyist phase to being paid to increase shareholder value and so much more. Understanding how the data flows through a codebase and the implications of moving, first fiat now magic internet money, has moved me from frontend lead to developer relations director in my career, but entering into my 11th year writing all things web, I knew the inevitable was here. It was time to get bare metal.&lt;/p&gt;

&lt;p&gt;These days I care a lot about performant and predictable computing. I love the flow of data. I want to get as close as possible to tweaking bits of the machine for the perfect human/computer communication. I love the dream of engineering highly scalable projects that do not break under pressure. So when I crash back to earth and I'm asked to come consult - as seems to be my thing these days - on creating and implementing a developer relations battle plan for a new project, I've on very few occasions come away with engineering concerns. We cannot promise the developers lightning-fast tps, fast network finality, or ethereum equivalence if the very system developed does not do what it promises to do or even worse, does it and fails at crucial points for developers. That is a leakage in the developer interest, acquisition, and retention paradigm. I also care about cryptographic tools. I love topics like Hash Functions and Digital Signatures, Public Key Infrastructure (PKI), Cryptographic Protocols based on zk-SNARKs or zk-STARKs et.al. But as always, I'm in love with this web3 space we're land stage&lt;/p&gt;

&lt;p&gt;So I have drawn up a plan for 2024 to learn all my interests as a product and software engineer and speak on things that excite me as a developer relations engineer in this space&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Learning&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Stage 1 -  Rust Programming Language Beginner&lt;/em&gt;&lt;br&gt;
This is where I am right now and the plan here is to finish The Rust Book as found here. Full disclosure, at the time of publication, I am 5 chapters deep in here presently toying with the concept of Structs. The book is an amazing compendium of the concepts that make Rust the right language for the type of code I want to write at this stage of my career. Provided I can wrap my head around Lifetimes, Borrowing, Ownership et.al. Lovely read and I will be providing updates under a hashtag on my beginner learnings with Rust. &lt;/p&gt;

&lt;p&gt;My project here will be a basic rust utility that performs basic arithmetic operations.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Stage 2 - Rust Programming Language Intermediate&lt;/em&gt;&lt;br&gt;
Next up I'll work through "Rust by Example" to deepen my understanding of Rust features. I'll be exploring concurrency with threads and asynchronous programming in Rust. &lt;/p&gt;

&lt;p&gt;Focus topics:&lt;br&gt;
Structs, Enums, and Patterns&lt;br&gt;
Generics and Lifetimes&lt;br&gt;
Concurrency with Threads&lt;br&gt;
Asynchronous Programming with async/await&lt;br&gt;
Testing in Rust&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Stage 3 - Rust Programming Language - Advanced&lt;/em&gt;&lt;br&gt;
Next up. Delve into "The Rustonomicon" to understand unsafe Rust, advanced ownership, and macros. My plan here is to learn about interfacing with C code and Foreign Function Interface (FFI).&lt;/p&gt;

&lt;p&gt;Focus topics:&lt;br&gt;
Unsafe Rust&lt;br&gt;
Advanced Ownership (Smart Pointers)&lt;br&gt;
Macros and Meta-Programming&lt;br&gt;
Interfacing with C code&lt;br&gt;
FFI (Foreign Function Interface)&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Stage 4 - Cryptography Basics and Zero-Knowledge Proofs&lt;/em&gt;&lt;br&gt;
Learning&lt;br&gt;
Study "Coursera Cryptography I" for basics. I'll be diving into resources on zero-knowledge proofs (e.g., "Zero Knowledge Proofs - An illustrated primer").&lt;br&gt;
Next up, complete "A Gentle Introduction to Zero Knowledge Proofs" to understand the basic concepts of zero-knowledge proofs.&lt;/p&gt;

&lt;p&gt;Focus topics:&lt;br&gt;
Hash Functions and Digital Signatures&lt;br&gt;
Public Key Infrastructure (PKI)&lt;br&gt;
Cryptographic Protocols&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Stage 5 - Zero-Knowledge Proofs&lt;/em&gt;&lt;br&gt;
Study "Zero Knowledge Proofs - An illustrated primer" for a deep dive into different types of zero-knowledge proofs (zk-SNARKs, zk-STARKs). I'll be learning how to construct and verify zero-knowledge proofs.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Stage 6 - Proof-of-Physical-Work Systems&lt;/em&gt;&lt;br&gt;
Research papers and literature on proof-of-physical-work systems. I'll be seeking to understand the principles and cryptographic techniques behind proof-of-physical work.&lt;/p&gt;

&lt;p&gt;Stage 7 - Advanced Cryptography and Security Topics_&lt;br&gt;
Explore relevant research papers and publications in advanced cryptography.&lt;br&gt;
Understand security considerations and vulnerabilities in the proposed system.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Writing&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;As you can imagine, every stage has a fair amount of knowledge that I shall be taking on. This of course means that there is a fair amount of articles I shall be taking on to spread out this knowledge. Every week will have a small run down of the learnings in Rust and Zero Knowledge proof distilled down for developers for the week. The aim is to create a knowledge base for the community from the concepts of Rust to writing that absolutely simplifies the internal architecture of what it takes to anonymize transactions on the blockchain.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Show and Tell on Youtube&lt;/strong&gt;&lt;br&gt;
For now, I can only think of one project each for the first three stages. My thinking here is at the end of each stage, I'll build out the project and then do a video walkthrough talking through the engineering and learning from the the mini-project.  &lt;/p&gt;

&lt;p&gt;&lt;em&gt;Stage One - Basic Rust Utility&lt;/em&gt;&lt;br&gt;
A simple command-line utility in Rust that performs basic arithmetic operations.&lt;br&gt;
Stage Two - Multi-threaded File Processing Tool&lt;br&gt;
Stage Three - Create a Rust library for a custom data structure or algorithm.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Web3 Protocol Deep Dives on Youtube&lt;/strong&gt;&lt;br&gt;
The 2024 bull run is almost here and I couldn't be more excited for the new narratives that are coming to the fore. From Account Abstraction to Sharding, Zero Knowledge proving systems, builders have been hunkered down and crafting the new paradigms that will lead to a more permissionless world for us all. And it's time to tell their stories. Starting from this week, every week I'll be picking up a narrative, and three or four leaders in the space and shooting tutorial videos on their individual offerings. &lt;/p&gt;

&lt;p&gt;In practice, that will mean alongside my learning with Rust, I shall start alphabetically with videos on deep dives about Account Abstraction -  an awesome new paradigm in our space that promises Smart Accounts instead of EOA, Social sign-in like web2 does, abstraction of gas, multi-call support et.al. &lt;/p&gt;

&lt;p&gt;I can't wait to explore the theory and the thinking behind these paradigms and then walk through the present offerings by a few of them. This year, to the builders I will be a builder, to the developer relations engineers, I will be a developer relations engineer and to the crab, I will be a crab. So adios! And see you in the first installment of learning and building!&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>rust</category>
      <category>beginners</category>
      <category>backend</category>
    </item>
    <item>
      <title>Object.entries in Javascript</title>
      <dc:creator>Jefferson </dc:creator>
      <pubDate>Fri, 17 Feb 2023 09:06:18 +0000</pubDate>
      <link>https://forem.com/jeffersonnnn/objectentries-in-javascript-22e1</link>
      <guid>https://forem.com/jeffersonnnn/objectentries-in-javascript-22e1</guid>
      <description>&lt;p&gt;&lt;code&gt;Object.entries&lt;/code&gt; in javascript is the most fascinating thing I’ve come across this week. Historically, iterating over objects hasn’t always been the sexiest thing to do. As a comparison, beginner javascript engineers deal with &lt;code&gt;for&lt;/code&gt; loops over arrays on a regular basis, but objects have not always had that same je ne se quios about them. Ofcourse with ECMAScript6, the &lt;code&gt;for...in&lt;/code&gt; loop came to be and life became a little easier. &lt;code&gt;Object.entries&lt;/code&gt; however, is a welcome progression down this path of iterating over objects, and over this article I'll be showing you just how elegant this tool is for crunching your objects in JS. Let’s dive in. &lt;/p&gt;

&lt;h3&gt;
  
  
  Syntax
&lt;/h3&gt;

&lt;p&gt;Getting syntax out of the way is how I like to go, so this is how that works&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;inevitableObj&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;rain&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;tax&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nb"&gt;Object&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;entries&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;inevitableObj&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Where &lt;code&gt;inevitableObj&lt;/code&gt; is an object we are looking to work through with. &lt;/p&gt;

&lt;h3&gt;
  
  
  Usage
&lt;/h3&gt;

&lt;p&gt;Using &lt;code&gt;Object.entries&lt;/code&gt; to iterate over an object is as easy as this&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;inevitableObj&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;rain&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;tax&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="k"&gt;for &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;key&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;value&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="k"&gt;of&lt;/span&gt; &lt;span class="nb"&gt;Object&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;entries&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;inevitableObj&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;`this is key: &lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;key&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;. this is value: &lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;value&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;. use this information wisely`&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This is particularly great because you can isolate the key and value for use as you wish without needing to write anything more complicated than is up there. &lt;/p&gt;

&lt;p&gt;With great power, comes great responsibility, so before you wield this tool, there are a couple of things you should know &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;According to &lt;a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/entries" rel="noopener noreferrer"&gt;the MDN docs&lt;/a&gt; here, &lt;code&gt;Object.entries&lt;/code&gt; returns “An array of the given object's own enumerable string-keyed property key-value pairs. Each key-value pair is an array with two elements: the first element is the property key (which is always a string), and the second element is the property value”. This is fancy talk for saying that the an object will be convert into a nested array of values with each key value pair in an array all wrapped with an main array. &lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Randomised strings used as keys in objects will be arranged into what javascript considers to be hierarchical order. This just means that &lt;code&gt;Object.entries&lt;/code&gt; will reorder an object with random key pairings.&lt;br&gt;
&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="c1"&gt;// So this &lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;randomKeys&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="mi"&gt;332&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;object&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;211&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;in&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;12&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;keys&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;9&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;ordered&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt; &lt;span class="p"&gt;};&lt;/span&gt; 

&lt;span class="c1"&gt;// passes through this &lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;Object&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;entries&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;randomKeys&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt; 

&lt;span class="c1"&gt;// to become this&lt;/span&gt;
&lt;span class="c1"&gt;//[ ['9', 'ordered'], ['12', 'keys'], ['211', 'in'], ['332', 'object'] ]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Careful, as non-objects will be coerced into objects. Strings will be split into characters, assigned a 0-index numbering and then made into a nested array. It looks like this.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;Object&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;entries&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;fuego&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="c1"&gt;// [['0', 'f'], ['1', 'u'], ['2', 'e'], ['3', 'g'], ['5', 'o']]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;One final thing. Now this one, I haven't used in development but I can’t wait to use it. The &lt;code&gt;Object.entries&lt;/code&gt; operator is allows a conversion from an &lt;code&gt;Object&lt;/code&gt; to a &lt;code&gt;Map&lt;/code&gt; allowing even more versatility around how data is presented. This is particularly useful because Maps have built-in methods like &lt;code&gt;forEach&lt;/code&gt;, values, keys, and entries, which make it easy to iterate over the keys and values, get arrays of keys or values, or manipulate the map's content. While objects have methods, they are not built into the object and they need to be accessed through the Object constructor.&lt;/p&gt;

&lt;p&gt;So that’s it! Object cherrypicking, rearrangement and an undue amount of coercion done just right all through &lt;code&gt;Object.entries&lt;/code&gt;. This was a quick brain dump so please let me know what you think in the comments or my socials. Cheers and do have a fantastic day.&lt;/p&gt;

</description>
    </item>
  </channel>
</rss>
