Anxo Rodriguez
    • Create new note
    • Create a note from template
      • Sharing URL Link copied
      • /edit
      • View mode
        • Edit mode
        • View mode
        • Book mode
        • Slide mode
        Edit mode View mode Book mode Slide mode
      • Customize slides
      • Note Permission
      • Read
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Write
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Engagement control Commenting, Suggest edit, Emoji Reply
    • Invite by email
      Invitee
    • Publish Note

      Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

      Your note will be visible on your profile and discoverable by anyone.
      Your note is now live.
      This note is visible on your profile and discoverable online.
      Everyone on the web can find and read all notes of this public team.
      See published notes
      Unpublish note
      Please check the box to agree to the Community Guidelines.
      View profile
    • Commenting
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
      • Everyone
    • Suggest edit
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
    • Emoji Reply
    • Enable
    • Versions and GitHub Sync
    • Note settings
    • Engagement control
    • Transfer ownership
    • Delete this note
    • Save as template
    • Insert from template
    • Import from
      • Dropbox
      • Google Drive
      • Gist
      • Clipboard
    • Export to
      • Dropbox
      • Google Drive
      • Gist
    • Download
      • Markdown
      • HTML
      • Raw HTML
Menu Note settings Versions and GitHub Sync Sharing URL Create Help
Create Create new note Create a note from template
Menu
Options
Engagement control Transfer ownership Delete this note
Import from
Dropbox Google Drive Gist Clipboard
Export to
Dropbox Google Drive Gist
Download
Markdown HTML Raw HTML
Back
Sharing URL Link copied
/edit
View mode
  • Edit mode
  • View mode
  • Book mode
  • Slide mode
Edit mode View mode Book mode Slide mode
Customize slides
Note Permission
Read
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Write
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Engagement control Commenting, Suggest edit, Emoji Reply
  • Invite by email
    Invitee
  • Publish Note

    Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

    Your note will be visible on your profile and discoverable by anyone.
    Your note is now live.
    This note is visible on your profile and discoverable online.
    Everyone on the web can find and read all notes of this public team.
    See published notes
    Unpublish note
    Please check the box to agree to the Community Guidelines.
    View profile
    Engagement control
    Commenting
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    • Everyone
    Suggest edit
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    Emoji Reply
    Enable
    Import from Dropbox Google Drive Gist Clipboard
       owned this note    owned this note      
    Published Linked with GitHub
    Subscribed
    • Any changes
      Be notified of any changes
    • Mention me
      Be notified of mention me
    • Unsubscribe
    Subscribe
    # 🐮 Build on top of CoW Protocol ## 🏁 Get started This document provides some quick start information for integrating to CoW Protocol. You will find an introduction to the protocol, it's tools, resources, and documentation, along with some convenient coding examples. ### What is CowSwap & CoW Protocol CowSwap is a Decentralized Application (DApp) and Protocol allowing users to **exchange digital assets directly (peer-to-peer) and via existing trading decentralized exchanges**. Its novel design maximizes trade efficiency and provides a competitive way to ensure best prices. One of the core ideas is executing **trades in batches**, where users will trade directly using what is known as **“Coincidence of Wants”** (hence the name CoW). In the context of blockchains, batch auctions are a superior mechanism compared to continuous time trading, as they already execute transactions in discrete “blocks” every few seconds. In consequence CowSwap **protects users from front-running and other value extraction (known as MEV)**. The mechanism also leverages the concept of “ring trades” to boost liquidity in highly fragmented and long-tail token markets. Additionally, CowSwap allows for an improved user experience by facilitating gasless trades, not paying for failed transactions and adaptive routing in case of volatility. ### Get familiar with CowSwap CowSwap uses CoW protocol. One easy way to get familiar with the protocol is by doing one trade in CowSwap: * [https://cowswap.exchange](https://cowswap.exchange/) You can use it in **Rinkeby** test net if you want. Otherwise, it is avaiable in **Mainnet** and **Gnosis Chain**. > 💡 If you need Rinkeby Ether, you can use this [Faucet](https://www.rinkeby.io/#faucet) ### Some basics: Place an order Trading in CowSwap is done by signing off-chain transactions using your web3 wallet and positing them to an API. You will need to: - 1. **Enable token for trading**: (only one time) Similarly to other protocols like Uniswap, you need to set an allowance. After this, you can trade. Learn more [here](https://docs.cow.fi/tutorials/how-to-submit-orders-via-the-api/1.-set-allowance-for-the-sell-token) - 2. **Get a price/fee quote from the API**: Fees are only payed if the trade is executed (you don't pay for failed transactions). So this fees covers the settlement of the transaction on-chain. Learn more [here](https://docs.cow.fi/tutorials/how-to-submit-orders-via-the-api/2.-query-the-fee-endpoint) - 3. **Sign the order using your wallet**: Orders are just your signed intent to trade at a desired price or better before some expiration time. You sign orders with your web3 wallet. Learn more [here](https://docs.cow.fi/tutorials/how-to-submit-orders-via-the-api/4.-signing-the-order) - 4. **Post the signed order to the API**: Signed orders are posted to the API, so the order can be executed. Read more [here](https://docs.cow.fi/tutorials/how-to-submit-orders-via-the-api/5.-placing-the-order) > 💡 **TIP**: One easy way to understand the steps above is to see the [DEMO: SDK Examples](https://vigilant-heisenberg-dba3c1.netlify.app/) or check the [SDK documents](https://docs.cow.fi/cow-sdk) ### Check order status Orders are identified by an unique identifier (`UID`). This UID is a deterministic hash derived from the order information. It is returned by the API when you post a new order (it can also be calculated locally deriving it from the order data). This UID would allow you to get information about the status of the order. You can do this in two different ways: * **API**: Get the order details and it's status from the `UID` (`GET /orders/{UID}`, see the [Swagger docs](https://api.cow.fi/docs/#/default/get_api_v1_orders__UID_)) * **Smart Contract**: You can watch the [Trade](https://github.com/cowprotocol/contracts/blob/main/src/contracts/GPv2Settlement.sol#L50) event. It's worth mentioning that, if you build a tool or UI that creates trades, it's very convenient to provide the user a way to see the details of the trade that was just created. One simple way to do this, is by creating a link to the explorer: * `https://explorer.cow.fi/orders/{UID}` ### CoW Explorer The explorer is a web that allows you to explore the protocol data. It's the "Etherscan" for CoW protocol, so you will be able to find, among other things: * **Order details, with trading status**: You can get detailed information about executed, expired, or pending orders. This page is very convenient for directing users once they post an order. i.e. [Example order](https://explorer.cow.fi/orders/0xa64f3559e33edebd2a1701050db6dff8089c7c42c4d2d842669466c4693d698100000000005ef87f8ca7014309ece7260bbcdaeb61f0377d) * **Order for a given account**: You can get detailed information about executed, expired, or pending orders for a given trader (i.e. [Exaple orders for trader](https://explorer.cow.fi/address/0x00000000005ef87f8ca7014309ece7260bbcdaeb)) * **Orders for a batch**: Given the transaction hash of a settlement hash, you can see all the trades in it [Example orders in batch](https://explorer.cow.fi/tx/0xd25f7457f4a2ce993a3314858f50f0144606e0c3afe7b3da6416814598afb87b) ### Signing orders The protocol requires valid signed orders. There's different ways in which someone could sign an order: * **Off-chain signing** (`EIP-712`): Allow gass-less trading for EOA like Metamask. Learn [how to sign orders](https://docs.cow.fi/tutorials/how-to-submit-orders-via-the-api/4.-signing-the-order) * **Presign**: Sign an order using an ethereum transaction. Convenient for Smart Contract integrations. See the [setPresign](https://github.com/cowprotocol/contracts/blob/7842d494c63224387e7e67f75bcd31775543098c/src/contracts/mixins/GPv2Signing.sol#L86) solidity function for more details * **Smart Contract Signing** (`EIP-1271`): Gass-less signing for smart contracts. Part of the protocol, but not implemented in API for now. For more information on Signed orders, read [here](https://docs.cow.fi/overview/signed-orders). ## 💡Resources ### Dev Documentation Start here your journey to learn about CoW Protocol https://docs.cow.fi/ ### API The API allows you to get an easy access to the CoW protocol. The documentation is exposed using Swagger docs: * https://api.cow.fi/docs The API is available in 3 different Networks: **Mainnet**, **Gnosis Chain** and **Rinkeby** testnet. For more information about the API, learn more [here](https://docs.cow.fi/tutorials/how-to-submit-orders-via-the-api/5.-placing-the-order) ### SDK The SDK is a Javascript library that provides an easy access to the API and some utilities like order signing. It is written in Typescript, making it simpler to use for both Typescript and plain Javascript project. More info in [SDK documents](https://docs.cow.fi/cow-sdk) or see an example on how to use it [here](https://github.com/anxolin/cow-examples/blob/main/src/pages/api/Orders.js#L6) ### The graph CoW Protocol graph provides an alternative way to consume protocol information. More info in [https://github.com/cowprotocol/subgraph](https://github.com/cowprotocol/subgraph) ## Examples of simple integrations * **CoW Protocol integration examples**: Web app that shows how to integrate with CoW Protocol using the SDK [https://github.com/anxolin/cow-examples](https://github.com/anxolin/cow-examples) * **NodeJS Trading Bot**: Basic bot that creates a random trade: [https://github.com/cowprotocol/trading-bot](https://github.com/cowprotocol/trading-bot) * **Python Trading script**: [https://pastebin.com/cKXUz0SW](https://pastebin.com/cKXUz0SW) * **Go Trading script**: [https://pastebin.com/r787C2wT](https://pastebin.com/r787C2wT) # 👩‍🌾 Bonus: Join the team! There's currently open positions for CoW Protocol. If you are looking for new challenges and opportunities, consider our [Open Positions](https://cow.fi/jobs).

    Import from clipboard

    Paste your markdown or webpage here...

    Advanced permission required

    Your current role can only read. Ask the system administrator to acquire write and comment permission.

    This team is disabled

    Sorry, this team is disabled. You can't edit this note.

    This note is locked

    Sorry, only owner can edit this note.

    Reach the limit

    Sorry, you've reached the max length this note can be.
    Please reduce the content or divide it to more notes, thank you!

    Import from Gist

    Import from Snippet

    or

    Export to Snippet

    Are you sure?

    Do you really want to delete this note?
    All users will lose their connection.

    Create a note from template

    Create a note from template

    Oops...
    This template has been removed or transferred.
    Upgrade
    All
    • All
    • Team
    No template.

    Create a template

    Upgrade

    Delete template

    Do you really want to delete this template?
    Turn this template into a regular note and keep its content, versions, and comments.

    This page need refresh

    You have an incompatible client version.
    Refresh to update.
    New version available!
    See releases notes here
    Refresh to enjoy new features.
    Your user state has changed.
    Refresh to load new user state.

    Sign in

    Forgot password

    or

    By clicking below, you agree to our terms of service.

    Sign in via Facebook Sign in via Twitter Sign in via GitHub Sign in via Dropbox Sign in with Wallet
    Wallet ( )
    Connect another wallet

    New to HackMD? Sign up

    Help

    • English
    • 中文
    • Français
    • Deutsch
    • 日本語
    • Español
    • Català
    • Ελληνικά
    • Português
    • italiano
    • Türkçe
    • Русский
    • Nederlands
    • hrvatski jezik
    • język polski
    • Українська
    • हिन्दी
    • svenska
    • Esperanto
    • dansk

    Documents

    Help & Tutorial

    How to use Book mode

    Slide Example

    API Docs

    Edit in VSCode

    Install browser extension

    Contacts

    Feedback

    Discord

    Send us email

    Resources

    Releases

    Pricing

    Blog

    Policy

    Terms

    Privacy

    Cheatsheet

    Syntax Example Reference
    # Header Header 基本排版
    - Unordered List
    • Unordered List
    1. Ordered List
    1. Ordered List
    - [ ] Todo List
    • Todo List
    > Blockquote
    Blockquote
    **Bold font** Bold font
    *Italics font* Italics font
    ~~Strikethrough~~ Strikethrough
    19^th^ 19th
    H~2~O H2O
    ++Inserted text++ Inserted text
    ==Marked text== Marked text
    [link text](https:// "title") Link
    ![image alt](https:// "title") Image
    `Code` Code 在筆記中貼入程式碼
    ```javascript
    var i = 0;
    ```
    var i = 0;
    :smile: :smile: Emoji list
    {%youtube youtube_id %} Externals
    $L^aT_eX$ LaTeX
    :::info
    This is a alert area.
    :::

    This is a alert area.

    Versions and GitHub Sync
    Get Full History Access

    • Edit version name
    • Delete

    revision author avatar     named on  

    More Less

    Note content is identical to the latest version.
    Compare
      Choose a version
      No search result
      Version not found
    Sign in to link this note to GitHub
    Learn more
    This note is not linked with GitHub
     

    Feedback

    Submission failed, please try again

    Thanks for your support.

    On a scale of 0-10, how likely is it that you would recommend HackMD to your friends, family or business associates?

    Please give us some advice and help us improve HackMD.

     

    Thanks for your feedback

    Remove version name

    Do you want to remove this version name and description?

    Transfer ownership

    Transfer to
      Warning: is a public team. If you transfer note to this team, everyone on the web can find and read this note.

        Link with GitHub

        Please authorize HackMD on GitHub
        • Please sign in to GitHub and install the HackMD app on your GitHub repo.
        • HackMD links with GitHub through a GitHub App. You can choose which repo to install our App.
        Learn more  Sign in to GitHub

        Push the note to GitHub Push to GitHub Pull a file from GitHub

          Authorize again
         

        Choose which file to push to

        Select repo
        Refresh Authorize more repos
        Select branch
        Select file
        Select branch
        Choose version(s) to push
        • Save a new version and push
        • Choose from existing versions
        Include title and tags
        Available push count

        Pull from GitHub

         
        File from GitHub
        File from HackMD

        GitHub Link Settings

        File linked

        Linked by
        File path
        Last synced branch
        Available push count

        Danger Zone

        Unlink
        You will no longer receive notification when GitHub file changes after unlink.

        Syncing

        Push failed

        Push successfully