Crypto Token Escrow V2

Thank you again for purchasing Crypto Token Escrow. Crypto Token Escrow is a 100% decentralized Web3 Escrow application supporting any type of ERC20, BEP20, TRC20 and similar tokens following those standards. You don't need to be the token owner. This application/script will be able to interact with any tokens deployed to any EVM networks.

Just copy the token address deployed to the network and add the address to this script and deploy it. Start the business and earn money.

Installation

Crypto Token Escrow is actually a package of two different applications. One is smart contracts for EVM blockchains. Another is web3 app interface to interact with the blockchain. Please follow below sections step by step carefully.

Prerequisites

  1. Basic Ethereum knowledge and a couple of minutes to follow this doc.

  2. The latest nodeJS LTS (v18 recommended) installed locally and node and npm are accessible from terminal/cmd/Powershell. References: Windows 10, Ubuntu, macOS

  3. An API key from Alchemy. Reference: Alchemy API Key. Do not worry about pricing. Start with the free plan. They won't force you to pay.

    • Please ensure you collected the only API Key. Not Http or Websocket url. Alchemy Key
    • Advance: If you have your own node and RPC or other RPC, please feel free to contact us. We will guide you to use those with Crypto Token Escrow.
  4. A WalletConnect Cloud project id to enable WalletConnect V2 SDK. Head over to WalletConnect Cloud to sign in or sign up. Create (or use an existing) project and copy its associated project id.

  5. KEY, SECRET and Bucket name from Filebase. Just sign up and get the KEY and SECRET from the sidebar "Access Keys" menu. Also create a Bucket and remember it. Follow the links Creating a Bucket and Access Keys. Don't worry about pricing. It's providing an insane amount of resources for free.

  6. A Chain ID of a network where you want to deploy the smart contract. Supported networks and chain ids...

    NetworkChain ID
    Ethereum1
    Goerli5
    OP Mainnet10
    Flare Mainnet14
    Coston16
    Songbird Mainnet19
    Cronos25
    Telos40
    Telos41
    XinFin Network50
    Apothem Network51
    BNB Smart Chain56
    Syscoin Mainnet57
    OKC66
    Binance Smart Chain Testnet97
    Gnosis100
    Coston2114
    Polygon137
    Nexilix Smart Chain240
    Fantom250
    zkSync Era Testnet280
    Boba Network288
    Filecoin Mainnet314
    zkSync Era324
    Cronos Testnet338
    PulseChain369
    Optimism Goerli420
    Metis Goerli599
    Taraxa Mainnet841
    Taraxa Testnet842
    Wanchain888
    PulseChain V4943
    5ireChain Thunder Testnet997
    Zora Goerli Testnet999
    Bronos Testnet1038
    Bronos1039
    Metis1088
    Polygon zkEVM1101
    Moonbeam1284
    Moonriver1285
    Moonbase Alpha1287
    Localhost1337
    Polygon zkEVM Testnet1442
    Dogechain2000
    Edgeware EdgeEVM Mainnet2021
    Beresheet BereEVM Testnet2022
    Filecoin Hyperspace3141
    Crossbell3737
    Fantom Testnet4002
    Nexi4242
    IoTeX4689
    IoTeX Testnet4690
    MEVerse Chain Testnet4759
    BlackFort Exchange Network Testnet4777
    BlackFort Exchange Network4999
    Mantle5000
    Mantle Testnet5001
    MEVerse Chain Mainnet7518
    Canto7700
    Shardeum Sphinx8082
    Klaytn8217
    Base8453
    Evmos Testnet9000
    Evmos9001
    Gnosis Chiado10200
    HAQQ Mainnet11235
    Fibo Chain12306
    Cannoli17323
    Hardhat31337
    Arbitrum One42161
    Celo42220
    Avalanche Fuji43113
    Avalanche43114
    Alfajores44787
    DFK Chain53935
    HAQQ Testedge 254211
    Linea Goerli Testnet59140
    Polygon Mumbai80001
    Base Goerli84531
    Taiko (Alpha-3 Testnet)167005
    Filecoin Calibration314159
    Arbitrum Goerli421613
    Scroll Testnet534353
    Zhejiang1337803
    Zora7777777
    Sepolia11155111
    SKALE - Razor Network278611351
    SKALE - Calypso NFT Hub Testnet344106930
    SKALE - Block Brawlers391845894
    SKALE - Europa Liquidity Hub Testnet476158412
    SKALE - Nebula Gaming Hub Testnet503129905
    SKALE - CryptoBlades1026062157
    SKALE - Human Protocol1273227453
    Aurora1313161554
    Aurora Testnet1313161555
    SKALE - Titan Community Hub1350216234
    SKALE - Chaos Testnet1351057110
    SKALE - Nebula Gaming Hub1482601649
    SKALE - Titan Community Hub Testnet1517929550
    SKALE - Calypso NFT Hub1564830818
    Harmony One1666600000
    SKALE - Europa Liquidity Hub2046399126
    SKALE - Exorde2139927552
  7. A Crypto Wallet is installed and the address and private key of an account. That will be used to deploy the smart contract. That account will be the Owner. Please make sure you have a couple of ether to pay the gas fee upon contract deployment. You must remove the private key after you successfully deployed the contract to a network. That will not be disclosed to the front end. Only the owner's public address will be public. So no worry. How to export the private key from MetaMask

  8. A Tawk.to account and property URL. We prefer using this free but powerful service to enable communication between the buyer/seller and the application owner/admin.

Steps

After purchasing Crypto Token Escrow, you will get a compressed zip file named erc20-escrow-v2.0.0.zip or something similar. Just extract that file at a suitable location on your local computer. You will get 3 more zip file in extracted folder. One is for Documents, one zip containing smart contracts application, and the other one is for web3 app. You have to work on smart contracts application. Extract the smart-contracts.zip and web3-app.zip file.

Smart Contract Deployment (smart-contracts folder)

  1. Open up a terminal/cmd/PowerShell and navigate to the smart-contracts directory. Where you should get a .env.setup file. Please make sure that your file explorer application shows you the hidden/dotfiles.

  2. After navigating to that directory run below commands...

    pnpm install
    
    cp .env.setup .env
    
  3. Open up the .env file into one of your text editors and change a couple of things as below.

    • Replace __APP_CHAIN_ID__ with the chain id you choose from the above chaininfo table. Ex: 11155111

    • Replace __ERC20_BEP20_TRC20_TOKEN_ADDRESS__ with the token address you want your application should interact to (erc20, bep20, trc20) Ex: 0x337610d27c682E347C9cD60BD4b3b107C9d34dDd

    • Replace __MINIMUM_ESCROW_AMOUNT_IN_ETHER__ with the minimum escrow amount allowed to create an escrow. In Ether. Ex: 0.001

    • Replace __ESCROW_FEE_IN_PERCENT__ with the escrow fee the owner/you want to be paid upon escrow clearance. In %. Ex: 5

    • Replace __ALCHEMY_KEY_HERE__ with the Alchemy API key. Ex: sdfasdfasdfsdfsdgffhgfghdgf

    • Replace __DEPLOYER_PRIVATE_KEY_HERE__ with the owner account private key.

  4. If you followed all the above points carefully then you are now ready to build and deploy the contract. Run the below commands one by one carefully. Please make sure you have some ether into your deployer/owner address/account to pay the gas fee.

    pnpm build-contract
    
    pnpm deploy-contract
    

    Wait some minutes after the above commands. Time depends on the network and other things. So, no worries. The deployment will be a success if you have enough ether to pay the gas fee. If you get a response from the deploy command like below then the deployment is successful. In case you face any issues, please feel free to contact us.

    EscrowHub deployed to: 0x421F67801BDa8a0eA4B2BC9D564b5C62Ca599734

We3 App Deployment (web3-app folder)

  1. Open up a terminal/cmd/PowerShell and navigate to the web3-app directory. Where you should get a .env.setup file. Please make sure that your file explorer application shows you the hidden/dotfiles.

  2. After navigating to that directory run below command...

    cp .env.setup .env
    
  3. Open up the .env file into one of your text editors and change a couple of things as below.

    • Replace __APP_NAME__ with your app title. Ex: Crypto Token Escrow.
    • Replace __APP_LIVE_BASEURL__ with the app live base url. You can skip this in your local machine. But in live server, it is required.
    • Replace __AUTH_SECRET__ with a randomly generated string. You can quickly generate a good secret on the command line via this openssl command. Ex: +oRxySo9vvloyCb4fZO/MqCe465zr7gwxK328b71eYM=
      openssl rand -base64 32
      
    • Replace __FILEBASE_KEY_HERE__ with the Filebase Access key. Ex: C3LB3BL93D1C0F687A66
    • Replace __FILEBASE_SECRET_HERE__ with the Filebase Access secret. Ex: VM0pRmuAKe41urmfZWTV9MiKyUgN5WgJn1npn5NK
    • Replace __FILEBASE_BUCKET_HERE__ with the Filebase bucket name you created before. Ex: cescrow-v2
    • Replace __WALLETCONNECT_PROJECT_ID__ with the WalletConnect Cloud project id.
    • Replace __TOKEN_SYMBOL_HERE__ with the ERC20/BEP20/TRC20 token symbol. You can get the symbol from that token etherscan. EX: USDT
    • Replace __TOKEN_DECIMALS_HERE__ with the ERC20/BEP20/TRC20 token decimals points. EX: 18
    • Replace __DEPLOYER_ADDRESS_HERE__ with the owner's account address. Ex: 0xFe5e946EcccB0f59542D5B99740fa432423F2F63
    • Replace __TAWK_TO_URL__ with Tawk.to property chat box URL. Check the example in the .env file.
  4. Copy the whole content of smart-contracts/.env file and paste at the end of web3-app/.env file.

  5. Remove DEPLOYER variable and its value from web3-app/.env file

Production Deployment

We recommend Vercel as a serverless no hassle deployment server. They have really great support for NextJS-based application deployment.

Vercel Deployment

You must need git installed into your local machine to deploy using this method. Please check this Youtube Video at least 3 times if you are not an expert. Then try to deploy to Vercel.

On Environment Variables section of Vercel build settings, copy the whole local .env file content using CMD/CTRL+A and paste into the variable input. Remove DEPLOYER variable.

VPS, DO Droplet deployment

This way of deployment is not so much easy. We recommend hiring an expert and spending some penny if you are not an expert. However, we are providing the guide. Please check this Youtube Video to learn this way.

Please ensure you upload the local .env file to the server also.

For more references, please check out this tutorial.

Upgrading V1 To V2

To upgrade the Crypto Token Escrow V1 to V2 is very simple. You don't have to do anything about contract deployment. Just follow those steps.

  1. Start following this doc from Production Deployment

  2. Collect below environment variables with it's value from previous V1 deployment in Vercel/VPS/Cloud.

    NEXT_PUBLIC_CHAIN
    
    NEXT_PUBLIC_MINIMUM_ESCROW
    
    NEXT_PUBLIC_ESCROW_FEE
    
    NEXT_PUBLIC_TOKEN_ADDRESS
    
    NEXT_PUBLIC_CONTRACT_ADDRESS
    
  3. Get a Alchemy key and set

    NEXT_PUBLIC_ALCHEMY_API_KEY
    
  4. Set below variables from the token info...

    NEXT_PUBLIC_TOKEN_SYMBOL=
    NEXT_PUBLIC_TOKEN_DECIMALS=
    
  5. Merge above environment variables with rest of others described in Here

  6. You are ready to deploy.

Sign In

To sign into the Crypto Token Escrow app, you must add a wallet to the application. Currently, Crypto Token Escrow support dedicated MetaMask, Coinbase and 300+ more wallet through WalletConnect. Rainbow and Safe multisig wallets are also there. You can also connect via a QR code.

If you do not know how to install and use those wallets then please consider searching on Google** and YouTube. That is not our cup of tea. We are assuming that you already know one of those wallets.

Visit your domain/URL. At a very first glance, you should see a page like the one below asking to connect a wallet. Connect Wallet After clicking on connect button... Wallets Some other wallets are hidden. Will be visible on some situation where you don't have metamask or coinbase. Or you embed the app in Safe app browser. Or you have TrustWallet installed. WalletConnect WalletConnect2

We used MetaMake to capture those images.

After connecting successfully you will be asked to sign into the Crypto Token Escrow app. Click on the Sign In button.

Verify Signing In

Escrow Management

Crypto Token Escrow is a React/Nextjs-based single-page application with no backend. It performs all its actions from the front end. But it is secure also. It uses IPFS/Filecoin decentralized object storage through Web3Storage to store metadata and other files. And all the queries and mutations to the smart contract you deployed before.

Let us describe the escrow lifecycle and properties.

  • Every Escrow has some properties. An escrow belongs to two different parties, the first party (buyer) and the second party (seller).

    • First party (buyer): Who creates/places a new escrow with other details.
    • Second party (seller): Seller address that the buyer (first party) provided while creating the escrow.
  • Escrow title and description are metadata for an escrow where the title is required but the description is optional.

  • Ether amount will be provided by the buyer/first party while creating escrow inclusively and will be calculated and divided into two parts. The fee (the owner will receive upon fund clearance) and the actual amount the seller will receive if no refund happens. The entered amount will be transferred to the escrow from the buyer/first party's account while creating escrow.

  • The expiration time determines when the Escrow will be expired. After expiration, if the escrow is still in the initial state then the seller (2nd party) can claim the fund on his/her own.

  • An Escrow can have multiple statuses.

    • The initial status is Awaiting Delivery just after the buyer created the escrow. The buyer can deliver funds at any time when the escrow is in Awaiting Delivery state. App owner and escrow seller can refund the buyer at any time in Awaiting Delivery state. All the actions must perform only in this state. Others' status will behave like stalled actually.
    • When the buyer delivers the funds, the state will change to COMPLETED. In this state, there are no actions that can perform on Escrow.
    • After creating escrow, the owner or the seller (second party) can refund the buyer at any time in Awaiting Delivery** state. After the refund transaction, the escrow state will change to the Refunded state.
    • After expiration time, if the escrow is still in Awaiting Delivery state, then the seller can claim the fund on their own. After a successful claim transaction, the escrow state will change to Claim after Expire state.

Whether the buyer (first party) delivers the fund or the seller (2nd party) claims the fund after expiration, the escrow fee will be transferred to the owner/deployer wallet address and the actual amount will be transferred to the seller. But, if the Owner or the seller performs the refund then the whole amount (fee+escrow amount) will be refunded to the buyer's (first party) wallet address.

Approve/Allow Tokens

Before creating the escrow, enough amount of tokens must be approved/allowed to spend on behalf of the buyer. The buyer should allow this before creating the escrow. The buyer will need to ensure that, the amount of the allowed token is equal to or larger than the escrow amount. Also, those tokens are available in his wallet.

Allow Tokens

Create Escrow

Click on the New Escrow button to create a new escrow. A popup with a couple of fields will be shown like the below image.

Create Escrow

Please make sure you read Escrow Management carefully to learn the conceptual things about Escrow.

We recommend uploading small-sized PDFs or docs. Due to decentralized object storage, there is some limitation to it. It's not a limitation of Crypto Token Escrow.

After providing all the information click on submit. Processing will be started. Please do not close the browser or tab.

Crypto Token Escrow 2

It will take some time to create the escrow. Time will depend on network status and other things.