<?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: nohehf</title>
    <description>The latest articles on Forem by nohehf (@nohehf).</description>
    <link>https://forem.com/nohehf</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%2F829757%2Fb89f0eaf-9449-4756-ac04-cb374c697f4a.png</url>
      <title>Forem: nohehf</title>
      <link>https://forem.com/nohehf</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/nohehf"/>
    <language>en</language>
    <item>
      <title>Introducing Goctopus: open-source, state-of-the-art GraphQL endpoint discovery &amp; fingerprinting tool.</title>
      <dc:creator>nohehf</dc:creator>
      <pubDate>Thu, 10 Aug 2023 16:18:17 +0000</pubDate>
      <link>https://forem.com/escape/introducing-goctopus-open-source-state-of-the-art-graphql-endpoint-discovery-fingerprinting-tool-mg1</link>
      <guid>https://forem.com/escape/introducing-goctopus-open-source-state-of-the-art-graphql-endpoint-discovery-fingerprinting-tool-mg1</guid>
      <description>&lt;p&gt;&lt;a href="https://escape.tech/blog/introducing-goctopus/" rel="noopener noreferrer"&gt;Read this article more comfortably on Escape Blog&lt;/a&gt;_&lt;/p&gt;

&lt;p&gt;In the fast-evolving domain of APIs, GraphQL has emerged as a powerful, data-oriented language. As its adoption soars, so does the need for robust tools to discover and fingerprint these APIs. Enter Goctopus, a Golang-based solution we developed at Escape to provide comprehensive, fast, and interoperable endpoint discovery and fingerprinting for GraphQL APIs. Engineered to overcome the limitations of existing tools, Goctopus extends its arms into realms of subdomain enumeration, route brute-force, authentication detection, schema introspection, and more, all while maintaining optimum speed and resource management. In this article, we dive into why we created Goctopus, what it does, and how it's pushing the boundaries of API security.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;TL;DR: We built an open-source&lt;/em&gt; GraphQL endpoint discovery &amp;amp; fingerprinting tool: &lt;em&gt;&lt;a href="https://github.com/Escape-Technologies/goctopus" rel="noopener noreferrer"&gt;check out Goctopus on Github&lt;/a&gt;.&lt;/em&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Unmasking  APIs: The Importance of API Discovery &amp;amp; Fingerprinting
&lt;/h2&gt;

&lt;p&gt;In the expansive realm of APIs, two practices stand out in their ability to shed light on the intricacies of your online presence: API Discovery and Fingerprinting.&lt;/p&gt;

&lt;p&gt;API Discovery is the process of finding all the APIs an organization has in its ecosystem. The aim here is to unveil the totality of the digital surface that can be interacted with. In the era of microservices and distributed systems, discovering all your API endpoints is crucial for both maintaining service interoperability and ensuring security.&lt;/p&gt;

&lt;p&gt;API Fingerprinting, on the other hand, takes this a step further. Once the endpoints are discovered, they're scanned to find specific information about them: technologies used, configuration, authentication details...&lt;/p&gt;

&lt;p&gt;Endpoint discovery &amp;amp; fingerprinting are crucial tools in offensive and defensive security to: &lt;/p&gt;

&lt;ol&gt;
&lt;li&gt; &lt;strong&gt;Detecting Attack Surface&lt;/strong&gt;: By understanding what endpoints exist and how they operate, you get an accurate view of your potential attack surface. This gives you the upper hand in securing your system, as you can preemptively locate and address vulnerabilities.&lt;/li&gt;
&lt;li&gt; &lt;strong&gt;Internet-wide Research&lt;/strong&gt;: If you're a security researcher or an organization keen on understanding the landscape of what's exposed on the internet, fingerprinting can give you a macro view. It helps to gather data about technologies, configurations, and security practices being used across various domains.&lt;/li&gt;
&lt;li&gt; &lt;strong&gt;Classifying endpoints&lt;/strong&gt;: Being able to determine which technologies and configurations are used on APIs is usually the first step in any security process (offensive or defensive).&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;For REST APIs there are a myriad of tools to perform those tasks. However, for GraphQL this is not the same story, as you will see in the next paragraph.&lt;/p&gt;

&lt;h2&gt;
  
  
  Identifying the Void: Why We Needed Goctopus
&lt;/h2&gt;

&lt;p&gt;Regarding GraphQL APIs, we built &lt;a href="https://github.com/Escape-Technologies/graphinder" rel="noopener noreferrer"&gt;Grafinder&lt;/a&gt; a while ago, and it has been serving us well for a few years. However, when we decided to implement our &lt;a href="https://escape.tech/blog/graphql-api-catalog/" rel="noopener noreferrer"&gt;API Catalog&lt;/a&gt;, we needed a more robust, faster, all-in-one, and more interoperable solution.&lt;/p&gt;

&lt;p&gt;Grafinder had some shortcomings that were hard to ignore. It was slow, hard to use programmatically, often missed inputs, lacked options, and its Python basis wasn't our preferred choice for this specific task. Moreover, we found ourselves needing a tool that could offer more comprehensive and efficient discovery and fingerprinting capabilities:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;  Broad and efficient discovery capabilities: (Subdomain enumeration, brute-force, script analysis).&lt;/li&gt;
&lt;li&gt;  Precise, fast and complete fingerprinting of GraphQL APIs: (Technology, authentication, schema, field suggestion attack).&lt;/li&gt;
&lt;li&gt;  Easy to use and enjoyable CLI.&lt;/li&gt;
&lt;li&gt;  Complete Package for programmatic usage.&lt;/li&gt;
&lt;li&gt;  Service interoperability: communicate with external services via webhooks.&lt;/li&gt;
&lt;li&gt;  Portability: run easily anywhere at any scale.&lt;/li&gt;
&lt;li&gt;  Versatile inputs: take a variety of inputs, domains, URLs, and IP addresses.&lt;/li&gt;
&lt;li&gt;  Speed: scan thousands of domains in minutes.&lt;/li&gt;
&lt;li&gt;  Scale: run on larger machines or scale horizontally.&lt;/li&gt;
&lt;li&gt;  Network resources: send a minimum amount of necessary requests and maximize throughput.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;So, with those constraints in mind, we realized we needed a solution that could go beyond what was already there. A more holistic tool. A faster tool. A...well, better tool. We needed Goctopus.&lt;/p&gt;

&lt;h2&gt;
  
  
  Unleashing the Beast: Meet Goctopus
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fescape.tech%2Fblog%2Fcontent%2Fimages%2F2023%2F07%2Fgiphy.webp" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fescape.tech%2Fblog%2Fcontent%2Fimages%2F2023%2F07%2Fgiphy.webp"&gt;&lt;/a&gt;&lt;br&gt;&lt;br&gt;
‌&lt;br&gt;
Born out of the needs we've just discussed, Goctopus is our answer to the comprehensive, fast, and interoperable tool we need. Created with Golang for its superior speed and efficiency in networking, this octopus has its arms reaching everywhere. Let's delve into its various facets:&lt;/p&gt;

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

&lt;ul&gt;
&lt;li&gt;  &lt;strong&gt;Subdomain Enumeration&lt;/strong&gt;: Goctopus uses DNS records APIs via &lt;a href="https://github.com/projectdiscovery/subfinder" rel="noopener noreferrer"&gt;subfinder&lt;/a&gt; to enumerate subdomains. &lt;/li&gt;
&lt;li&gt;  &lt;strong&gt;Bruteforce&lt;/strong&gt;: We built a custom list of popular GraphQL routes so that Goctopus has the best odds of finding endpoints on every domain it tests.&lt;/li&gt;
&lt;li&gt;  &lt;strong&gt;Script Analysis (Work-In-Progress)&lt;/strong&gt;: With this in the pipeline, Goctopus will soon be able to sniff out hidden GraphQL endpoints from Javascript &amp;amp; HTML files across the web.&lt;/li&gt;
&lt;/ul&gt;

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

&lt;ul&gt;
&lt;li&gt;  &lt;strong&gt;Authentication&lt;/strong&gt;: It quickly identifies which endpoints require authentication and which are publicly exposed.&lt;/li&gt;
&lt;li&gt;  &lt;strong&gt;GraphQL Schema/Introspection&lt;/strong&gt;: Goctopus checks if the schema is available or not.&lt;/li&gt;
&lt;li&gt;  &lt;strong&gt;Field Suggestions for Bruteforcing&lt;/strong&gt;: If the schema is unavailable, this clever cephalopod can even figure out if the schema can be brute-forced using field suggestions attacks.&lt;/li&gt;
&lt;li&gt;  &lt;strong&gt;Engine Fingerprinting (Work-In-Progress)&lt;/strong&gt;: Once this feature is added, Goctopus will be capable of understanding the tech stack behind an endpoint.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Dx &amp;amp; usage&lt;/strong&gt;:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;  &lt;strong&gt;CLI&lt;/strong&gt;: Goctopus is easily usable as a CLI for manual operations.&lt;/li&gt;
&lt;li&gt;  &lt;strong&gt;Go package&lt;/strong&gt;: It can be used as a Golang package programmatically to integrate into other tools.&lt;/li&gt;
&lt;li&gt;  &lt;strong&gt;Webhook&lt;/strong&gt;: With this feature, Goctopus can forward its results via a webhook so that other services can retrieve them.&lt;/li&gt;
&lt;li&gt;  &lt;strong&gt;Variety of inputs&lt;/strong&gt;: The tool accepts a wide variety of inputs: domains, URLs, and IP addresses.&lt;/li&gt;
&lt;/ul&gt;

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

&lt;ul&gt;
&lt;li&gt;  &lt;strong&gt;Speed&lt;/strong&gt;: Designed for speed, Goctopus can scan thousands of domains in minutes.&lt;/li&gt;
&lt;li&gt;  &lt;strong&gt;Scale&lt;/strong&gt;: This tool has no fear of the deep; it's built to scale on larger machines or spread horizontally across a cluster.&lt;/li&gt;
&lt;li&gt;  &lt;strong&gt;Network resources&lt;/strong&gt;: Goctopus is mindful of its requests, only sending what's necessary.&lt;/li&gt;
&lt;li&gt;  &lt;strong&gt;Rate limiting&lt;/strong&gt;: It also ensures not sending too many requests to a single endpoint concurrently to avoid rate limiting.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;In a nutshell, Goctopus is what we envisioned when we realized the limitations of existing tools. It's comprehensive, fast, flexible, and extensible.&lt;/p&gt;

&lt;h2&gt;
  
  
  Quick Hands-On: Meet Goctopus
&lt;/h2&gt;

&lt;p&gt;Interested in trying out Goctopus? Here's how to get started.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Installation&lt;/strong&gt;: You have two options here. If Go is installed on your machine, just run &lt;code&gt;go install -v github.com/Escape-Technologies/goctopus/cmd/goctopus@latest&lt;/code&gt; in your terminal. Prefer Docker? No problem, use &lt;code&gt;docker run --rm -it escapetech/goctopus:latest &amp;lt;options&amp;gt;&lt;/code&gt; to run the latest version of Goctopus in a docker container.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Usage Example&lt;/strong&gt;: Once installed, take Goctopus for a spin with this simple command &lt;code&gt;goctopus -a example.com&lt;/code&gt;. This will start the discovery process on the specified domain with all features enabled (&lt;code&gt;-a\&lt;/code&gt; flag stands for "all").&lt;/p&gt;

&lt;p&gt;For instance, running Goctopus on &lt;code&gt;rickandmortyapi.com&lt;/code&gt; will result in the following:&lt;/p&gt;

&lt;p&gt;‌&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;goctopus -a rickandmortyapi.com
                  _
  __ _  ___   ___| |_ ___  _ __  _   _ ___
 / _` |/ _ \ / __| __/ _ \| '_ \| | | / __|
| (_| | (_) | (__| || (_) | |_) | |_| \__ \
 \__, |\___/ \___|\__\___/| .__/ \__,_|___/ v0.0.14
 |___/                    |_|
[INF] Enumerating subdomains for 'rickandmortyapi.com'
[INF] Found 5 subdomains for 'rickandmortyapi.com' in 15 seconds 276 milliseconds
INFO[0016] Done fingerprinting rickandmortyapi.com
INFO[0016] Found: {"authenticated":false,"domain":"rickandmortyapi.com","schema_status":"OPEN","source":"rickandmortyapi.com","url":"https://rickandmortyapi.com/graphql"}
INFO[0016] Done. Found 1 graphql endpoints
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;‌&lt;/p&gt;

&lt;p&gt;Visit our &lt;a href="https://github.com/Escape-Technologies/goctopus" rel="noopener noreferrer"&gt;GitHub repo&lt;/a&gt; for detailed documentation and the latest release notes.&lt;/p&gt;

&lt;h2&gt;
  
  
  The Future of Goctopus: Contributing and Roadmap
&lt;/h2&gt;

&lt;p&gt;We're actively looking for ways to enhance Goctopus, and we welcome contributions. Feel free to raise issues or PRs on our  &lt;a href="https://github.com/Escape-Technologies/goctopus" rel="noopener noreferrer"&gt;GitHub repo&lt;/a&gt;. We're excited to see where the community can take this project.&lt;/p&gt;

&lt;p&gt;Looking ahead, we've got big plans. Improved subdomain enumeration, more intelligent endpoint discovery, engine fingerprinting - the roadmap for Goctopus is packed with exciting updates.&lt;/p&gt;

&lt;h2&gt;
  
  
  Goctopus at Escape: Providing Top-Notch Security for Our Users
&lt;/h2&gt;

&lt;p&gt;Here at Escape, we're using Goctopus to provide enhanced security for our users.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;API Catalog&lt;/strong&gt;: We're utilizing Goctopus to provide users with detailed information about their attack surface. By continuously scanning for new APIs and updating our records, we can ensure an up-to-date vision and alert our users whenever they expose an unprotected API.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fescape.tech%2Fblog%2Fcontent%2Fimages%2F2023%2F07%2Fimage.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fescape.tech%2Fblog%2Fcontent%2Fimages%2F2023%2F07%2Fimage.png"&gt;&lt;/a&gt;  &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Suggestions&lt;/strong&gt;: Goctopus is also integrated into our application creation process to automatically suggest our user's endpoints to secure to make our platform as smooth to use as possible.&lt;/p&gt;

&lt;p&gt;‌&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fescape.tech%2Fblog%2Fcontent%2Fimages%2F2023%2F07%2Fimage-1.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fescape.tech%2Fblog%2Fcontent%2Fimages%2F2023%2F07%2Fimage-1.png"&gt;&lt;/a&gt;  &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Kraken&lt;/strong&gt;: We built an internal tool around Goctopus called Kraken to scale Goctopus to another level. It consists of an API, a database, and dozens of Goctopus instances managed by a Kubernetes cluster that allowed us to scan Millions of domains to gather data on +150k GraphQL endpoints. Stay tuned for an upcoming article on the topic!&lt;/p&gt;

&lt;p&gt;‌&lt;/p&gt;




&lt;p&gt;‌&lt;/p&gt;

&lt;p&gt;We invite you to join us in exploring what Goctopus can do. Try it out, contribute, and together, let's push the boundaries of API security! And don't forget to star the &lt;a href="https://github.com/YourOrganization/goctopus" rel="noopener noreferrer"&gt;Goctopus repo&lt;/a&gt; on GitHub.&lt;/p&gt;

&lt;p&gt;And if you want maximum security for your GraphQL APIs try out &lt;a href="https://app.escape.tech/register" rel="noopener noreferrer"&gt;Escape security platform&lt;/a&gt; for free!&lt;/p&gt;

</description>
      <category>opensource</category>
      <category>security</category>
      <category>go</category>
    </item>
    <item>
      <title>Handling multiple tokens, with a modern solidity architecture via Diamonds &amp; ERC1155.</title>
      <dc:creator>nohehf</dc:creator>
      <pubDate>Wed, 04 May 2022 18:58:48 +0000</pubDate>
      <link>https://forem.com/nohehf/handling-multiple-tokens-with-a-modern-solidity-architecture-via-diamonds-erc1155-1h7e</link>
      <guid>https://forem.com/nohehf/handling-multiple-tokens-with-a-modern-solidity-architecture-via-diamonds-erc1155-1h7e</guid>
      <description>&lt;h2&gt;
  
  
  Abstract:
&lt;/h2&gt;

&lt;p&gt;The diamond pattern is a pretty recent standard that offers a solution to a lot of solidity issues:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Single address for multiple contracts&lt;/li&gt;
&lt;li&gt;You can update your functions after contract deployment&lt;/li&gt;
&lt;li&gt;No 24kb size limit&lt;/li&gt;
&lt;li&gt;...
but it also has some downsides or let's say compromises.
One of those compromises is that you can't have multiple functions with the same footprint inside one diamond. 
This can make things complicated when you want to have several tokens under the same diamond (for example an ERC721 NFT contract with an ERC20 token contract).
To know more about the Diamonds standard check: &lt;a href="https://github.com/mudgen/awesome-diamonds" rel="noopener noreferrer"&gt;https://github.com/mudgen/awesome-diamonds&lt;/a&gt;
I came across this pattern because I needed some kind of proxy architecture to scale up Parcels contracts (Parcels is a game &amp;amp; company I'm co-founding: &lt;a href="https://twitter.com/parcelsgame" rel="noopener noreferrer"&gt;https://twitter.com/parcelsgame&lt;/a&gt;).
## The issue
Let me demonstrate what I mentioned above.
This is not possible:
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;//FacetA.sol
contract FacetA {
    function my_function(uint256 number) external {
        //... Some logic
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;//FacetB.sol
contract FacetB {
    function my_function(uint256 number) external {
        //... Some other logic, with the same footprint
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Because all facets functions will be exposed under one single contract address (the diamond address), it couldn't determine which one to use on a &lt;code&gt;diamond.my_function(number)&lt;/code&gt; call.&lt;/p&gt;

&lt;p&gt;For this example you could simply change footprints, like calling the functions respectively &lt;code&gt;functionA&lt;/code&gt; and &lt;code&gt;functionB&lt;/code&gt;, but you often need a presice footprint in order to implement standards &amp;amp; interfaces. This can for example happend with erc20 and erc721 that both have the same  &lt;code&gt;balanceOf(address _owner)&lt;/code&gt; function.&lt;/p&gt;

&lt;p&gt;However, this is possible:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;//FacetA.sol
contract FacetA {
    function function(uint256 number) external {
        //...
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;//FacetB.sol
contract FacetB {
    function function(uint256 number, string str) external {
        //...
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Because both functions now have a different footprint, because of the arguments, even under a common name. For those familiar with object-oriented programming, this is pretty similar to how you can declare multiple constructors in most languages.&lt;/p&gt;

&lt;p&gt;This means that you cannot have multiple facets implementing the same interface.&lt;br&gt;
But this goes even further as different standards can still clash partly, like ERC20 and ERC721, meaning you cannot implement both at the same time inside a common diamond.&lt;/p&gt;
&lt;h2&gt;
  
  
  The ERC1155 standard
&lt;/h2&gt;

&lt;p&gt;Fortunately, it happens to exist a standard that is designed to handle multiple token on one contract: ERC1155. &lt;br&gt;
Basically ERC1155 is storing balances behind two parameters: id and address. It is this id that allows us to have multiple tokens at the same time on this contract.&lt;br&gt;
These tokens can be fungible (if you allow minting more than one), or non-fungible (if you only allow one mint per id).&lt;br&gt;
In order to distiguish the different token types you can split the ids in ranges: &lt;br&gt;
Let's say we want an app where you have one tokens: $GLD (that would usually implement an ERC20 fungible token), and 1000 unique miners (that would usually implement an ERC721 non-fungible token). To implement these two tokens under our ERC1155 contract, we need to split the ids: One for the $GLD token and 1000 for the miners NFTs. What we can simply do here is assigning the first id (0) to $GLD, and set ids 1 - 1001 to the miners.&lt;br&gt;
More generally what you would do is define à "base constant" for each token type, so here you would have something like:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;uint256 constant GLD_ID = 0;
uint256 constant MINER_BASE_ID = 1;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;So that you can access to the miner n°&lt;code&gt;x&lt;/code&gt; with &lt;code&gt;balance(MINER_BASE_ID + x)&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;If you need multiple wide ranges (like two types of nfts) you can set the base id by shifting bits:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;uint256 constant GLD_ID = 0;
uint256 constant MINER_BASE_ID = 1;
uint256 constant OTHERNFT_BASE_ID = 1 &amp;lt;&amp;lt;&amp;lt; 128;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;For more information on the ERC1155 standard please refer to: &lt;a href="https://eips.ethereum.org/EIPS/eip-1155" rel="noopener noreferrer"&gt;https://eips.ethereum.org/EIPS/eip-1155&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Architecture
&lt;/h2&gt;

&lt;p&gt;To implement the ERC1155 I advice solidstate-solidity &lt;strong&gt;LINK&lt;/strong&gt; that is compatible with the diamond standard, or adapting OpenZepplin's ones rather than re-writing your own from scratch which could add vulnerabilities.&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ffplw7dg0qehfa9qwer6x.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ffplw7dg0qehfa9qwer6x.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;So, we now have a clear way of creating multiple tokens with our ERC1155 contract, but having all the functions in one single contract for every type of token would lead to messy code, and worse, could even be too much.&lt;br&gt;
To address that we will separate each token logic in it's own Facet contract (see diamond pattern to understand facets).&lt;br&gt;
But we will probably want to call funtions from one contract to another (for example you could want to access the $GLD balance to upgrade a miner). While this is possible by leaving the logic in separated facets, the best option is to move all the logic in Libraries, which simplifies calls. This also allows to only leave external getters / setters functions in the Facets, making the architecture even cleaner, as external exposed logic will be separated form internal logic (respectivly Facets &amp;amp; Libraries).&lt;/p&gt;

&lt;p&gt;A simple token ($GLD) + NFT (Miner) architecture would be something like this:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Facets only expose external functions: ERC1155Facet for standard ERC1155 functions, TokenFacet &amp;amp; NFTFacet for custom funtions (like &lt;code&gt;getGLDBalance(address of)&lt;/code&gt;).&lt;/li&gt;
&lt;li&gt;Libraries LibToken &amp;amp; LibNFT handle all the logic (that will be used as internal and external) so that it can be reused across facets &amp;amp; other libraries.&lt;/li&gt;
&lt;li&gt;LibStorage contains all the data that has to be stored which is not handled by ERC1155, &lt;em&gt;see AppStorage / DiamondStorage pattern.&lt;/em&gt;
&lt;/li&gt;
&lt;li&gt;LibERC1155Internal is a copy of the functions defined in solidstate's &lt;code&gt;ERC1155Internal.sol&lt;/code&gt; contract so that we can call internal functions across facets &amp;amp; libraries (like _mint, etc...).  You just have to add events from the &lt;code&gt;IERC1155Internal.sol&lt;/code&gt; interface and remove &lt;code&gt;virtual&lt;/code&gt; keywords from functions (as library functions cannot / would not be overwritten). See &lt;a href="https://gist.github.com/nohehf/3a1116e47d932bb9477bbc5332e61a9a" rel="noopener noreferrer"&gt;https://gist.github.com/nohehf/3a1116e47d932bb9477bbc5332e61a9a&lt;/a&gt; .&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This architecture makes sharing the logic across different parts of the application seamless while keeping concerns in separate codebases.&lt;/p&gt;
&lt;h2&gt;
  
  
  Snippets examples:
&lt;/h2&gt;

&lt;p&gt;So for our $GLD / Miner example we would have the folowing structure (based on the hardhat-diamond-3 starter):&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;contracts
    ├── Diamond.sol
    ├── facets
    │   ├── DiamondCutFacet.sol
    │   ├── DiamondLoupeFacet.sol
    │   ├── ERC1155Facet.sol 🔺
    │   ├── GLDFacet.sol 🔺
    │   ├── MinerFacet.sol 🔺
    │   └── OwnershipFacet.sol
    ├── interfaces
    │   ├── IDiamondCut.sol
    │   ├── IDiamondLoupe.sol
    │   ├── IERC165.sol
    │   └── IERC173.sol
    ├── libraries
    │   ├── LibDiamond.sol
    │   ├── LibERC1155Internal.sol 🔺
    │   ├── LibGLD.sol 🔺
    │   ├── LibMiner.sol 🔺
    │   └── LibStorage.sol 🔺
    └── upgradeInitializers
        └── DiamondInit.sol
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;em&gt;Only files marked with 🔺 are custom, the other ones are provided by the starter repo&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;ERC1155Facet.sol:&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: UNLICENCED
pragma solidity ^0.8.9;

import {ERC1155} from "@solidstate/contracts/token/ERC1155/ERC1155.sol";

contract ERC1155Facet is ERC1155 {}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;GLDFacet.sol:&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: UNLICENCED
pragma solidity ^0.8.9;
import "../libraries/LibGLD.sol";
import {LibStorage, AppStorage, ArtefactType} from "../libraries/LibStorage.sol";
import {Modifiers} from "../libraries/LibStorage.sol";

contract ArtefactFacet is Modifiers {
    // ----- GETTERS -----
    function getMyGLDBalance(address addr) external view returns (uint256) {
        return LibGLD._getBalance(msg.sender);
    }

    // ...

    // ----- SETTERS -----
    // ...

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

&lt;/div&gt;



&lt;p&gt;LibERC1155Internal.sol (see &lt;a href="https://gist.github.com/nohehf/3a1116e47d932bb9477bbc5332e61a9a" rel="noopener noreferrer"&gt;https://gist.github.com/nohehf/3a1116e47d932bb9477bbc5332e61a9a&lt;/a&gt;)&lt;/p&gt;

&lt;p&gt;LibGLD.sol:&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.9;

import {LibStorage, AppStorage, ArtefactType} from "./LibStorage.sol";
import "@solidstate/contracts/token/ERC1155/base/ERC1155BaseStorage.sol";
// import {ERC1155Facet} from "../facets/ERC1155Facet.sol";
import "../facets/ERC1155Facet.sol";
import "./LibERC1155Internal.sol";

// Handles all the $GLD token logic
library LibGLD {
    //CONSTANTS
    uint256 constant GLD_ID = 0;

    //STORAGE GETTERS:
    // common storage
    function s() internal pure returns (AppStorage storage) {
        return LibStorage.diamondStorage();
    }

    //erc1155 storage (NOTE: you should prefer calling LibERC1155, but it can be usefull)
    function s1155() internal pure returns (ERC1155BaseStorage.Layout storage) {
        return ERC1155BaseStorage.layout();
    }


    //GLD LOGIC
    function _getBalance(address addr) internal view returns (uint256) {
        return LibERC1155Internal._balanceOf(addr, GLD_ID);
    }

    function _mint(address to, uint256 amount) internal {
        LibERC1155Internal._mint(to, GLD_ID, amount, "");
    }

    // ...
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;em&gt;Note that I only made examples for The miner would be pretty similar to GLD&lt;/em&gt;&lt;/p&gt;

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

&lt;p&gt;Besides fixing the footprint colision problem between multiple tokens facets under the same diamond, this solitions provides a scalable, easy to use and test solution for multi-token Dapps. Calling the internal functions without having to rely on the deployed address of a contract is very handfull (and cheaper). Once established this pattern allowed me to run things smoothly and easly implement new features to each of my tokens, while keeping clean code &amp;amp; directories.&lt;/p&gt;

&lt;h2&gt;
  
  
  Possible improvements:
&lt;/h2&gt;

&lt;p&gt;-&amp;gt; solidstate-solidity could move all the logic to Libs so we won't have to copy-paste everything.&lt;br&gt;
-&amp;gt; Diamonds standard should remove the ERC165 implementation on the &lt;code&gt;DiamondLoupeFacet&lt;/code&gt;, which we currently have to remove to add an ERC1155 facet (which is IMO a bit problematic).&lt;br&gt;
-&amp;gt; Starter repo for ERC1155 &amp;amp; Diamonds.&lt;/p&gt;

&lt;p&gt;I'm also discussing with solidstate &amp;amp; diamonds creators to improve their docs, or even&lt;br&gt;
make a real framework with solidstate-solidity &amp;amp; diamonds along with step-by-step tutorial and docs, supporting natively this kinds of architectures.&lt;/p&gt;

&lt;p&gt;Thanks for reading, and please ask me on twitter if you want more details / want to contribute: &lt;a href="http://www.twitter.com/nohehf" rel="noopener noreferrer"&gt;www.twitter.com/nohehf&lt;/a&gt; .&lt;/p&gt;

</description>
      <category>solidity</category>
      <category>tutorial</category>
      <category>blockchain</category>
      <category>web3</category>
    </item>
  </channel>
</rss>
