In the early days of blockchain, many of us imagined crypto currency being used for micro-payments and e-commerce. While crypto currency has been used for payments, the network costs of blockchains like Bitcoin and Ethereum have become too expensive and impractical for most goods. In the last few years, the driver of growth has been DeFi -- lending and borrowing, trading pools, and NFTs. Through all this hype, many people forgot about the original visions. The good news is that while DeFi exploded, other lower cost blockchains like Avalanche, Matic, and BSC advanced ahead, and services like Chain Link and Moralis made progress too. Finally, we have the tools and low cost networks to revisit using crypto currency for general payments and e-commerce. Our app uses the Avalanche network due to its fast speeds and low costs, but it could be used on any similar EVM. As the global economy enters a temporary slowdown, we believe now is the best time to release and develop an e-commerce solution facilitated by smart contracts to protect consumers and make blockchain the backbone of the future digital economy.

What it does

Meta4Swap is a web3 marketplace deployed on the AVAX Test net. Merchants can create and list their items and save them on the blockchain. Items are saved in IPFS and priced in USD using Chain Link. Merchants can edit and update their Item info and make their items Live or not. Buyers can create orders against any Item as long as its status is Live. In most dapps today, users need to approve the app to transfer their money, creating a 2-step process, and creating an annoying UX. We went back to first principles and coded payments to use the native asset for the blockchain. This way, buyers can pay in a single transaction. When a buyer creates an order, the payment is held in escrow. At this point, the order life cycle begins and can proceed in a few ways. Ideally, the merchant delivers the product/service, both parties are happy, and both sides mark the order as complete. When this happens, the escrow is released, the merchant receives the payment, and the dapp takes a small fee. If the merchant can't fulfill the order, they can cancel it. With many e-commerce transactions, one side of the order is unhappy. Although many claim that no-chargebacks in crypto is a good thing (and it is in many cases), for e-commerce, this means the merchant can more easily scam the buyer. This is why we've created the escrow. If a dispute is created by either side (buyers can abuse merchants too), the order is sent to arbitration. Meta4Swap also includes a DAO, and the DAO's role is to analyze disputes and choose what side deserves the money. For every successful transaction, a Meta4Swap token is minted for the buyer, the seller, and the company (our team). The tokens represent ownership in the DAO and are responsible for handling disputes. This creates an incentive to complete orders successfully. The DAO reserve is made from the transaction fees. We feel this is really unique especially given the collapse of UST and OHM. Our reserve is built by economic activity -- not by the idea that the price will rise if people buy more. The Meta4Swap token is based by transaction fees. As a token holder, you can vote on disputes and help generate more fees, or you can redeem your tokens for a share of the reserve. In short, the order life cycle ends with a completed transaction, a cancelled order, or a resolved dispute.

How we built it

We built the smart contracts using Solidity and Remix, and we referenced Open Zeppelin for smart contract ideas. We deployed 3 smart contracts -- the meta4swap marketplace, the meta4swap token, and the meta4swap dao. Each of these smart contracts communicate with each other. The merchant lists their items in USD and buyers pay in AVAX. This conversion is managed using Chainlink. On the create item form, the item image and meta data is uploaded to IPFS through the browser, and the hash is saved in the blockchain in the Item object. We're really excited by the integration with Moralis for events and database microservices. We made sure to emit events in our smart contract that could be used to inform our front end and build a quality user experience. Moralis has an event sync that saves our smart contract events almost instantly in a mongodb instance. The moralis SDK can be added in the front end to call the db and bring back item and order info for the front end.

Challenges we ran into

We encountered many challenges throughout the hackathon, but luckily we had the month to sleep on some issues and come back the next day with a solution. On the smart contract side, managing nearly 1,000 lines of code was difficult because it was easy to get lost in the logic. Creating the interfaces so that the contracts could call each other was another obstacle we had to overcome. The front end was definitely a challenge because our team is less experienced on this front. We were slowed down while integrating the web3 react library mostly because there isn't much help out there. The SDK evolves so much that answers from a few years ago weren't valid. We ran into issues trying to combine web3 and ethers. Setting up the Moralis DB took a few days because we had to learn about topics and how they work. We tripped over the fact that the event sync didn't like our parameters with an underscore in front, which caused errors. Overall, no challenge was too big that couldn't be resolved in 1-2 days.

Accomplishments that we're proud of

We're most proud of building our first functioning web3 app. We've built some apps that had meta mask connect in the past; we've built another hackathon project with smart contracts; we built a static web3 app that was very crude. But this was the first time we completed an end-to-end web3 app that uses react and events. The most powerful takeaway is learning how to use events. Once we understood what data should be saved on-chain and what should be saved in events, it really helped us nail down what business logic is necessary, and what info is useful for the front end. Although we used moralis because their event sync came with a database, we also learned how to process events ourselves using a python script.

What we learned

We learned how to use React and web3/ethers, how to emit, read, and use blockchain events, how to upload data to IPFS in the browser, how to create payable functions in solidity, and how to make a marketplace, token, and dao protocol work well together. We also learned more about the AVAX ecosystem and how it differs from the other blockchains we've deployed on previously.

What's next for Meta4Swap

We plan to turn this into a business. We're grateful for the opportunity in this hackathon to be challenged and be given a target to release a product, and learn about the tools available for startups. Right now our marketplace is very general, and our goal is to conduct more customer discovery and see what industry we should target. For example, should we focus on merchant selling clothes? Should we focus on freelancers offering services? We want the platform to remain flexible, but we want to know better who our first set of customers will be. We also want to build out the UI more so that it's easy for merchants to edit their items, and we want it easier for members of the DAO to vote and resolve disputes.

Built With

Share this project: