{"id":20118471,"url":"https://github.com/bitcoin-api/bitcoin-api-full-stack","last_synced_at":"2025-05-06T14:31:27.979Z","repository":{"id":40704876,"uuid":"280091430","full_name":"bitcoin-api/bitcoin-api-full-stack","owner":"bitcoin-api","description":"Full-Stack API for Bitcoin","archived":false,"fork":false,"pushed_at":"2023-01-06T21:44:41.000Z","size":3789,"stargazers_count":2,"open_issues_count":34,"forks_count":2,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-04-09T13:42:35.826Z","etag":null,"topics":["api","api-gateway","aws","bitcoin","bitcoin-api","bitcoin-node","bitcoin-withdraws","dynamodb","forbidden-code","hidden-code","lambda","middleware","mongodb","nodejs","react","redis","secret-code","serverless","treasure-code","treasure-core"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-3-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/bitcoin-api.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2020-07-16T07:59:24.000Z","updated_at":"2025-02-22T08:08:10.000Z","dependencies_parsed_at":"2023-02-06T09:30:34.785Z","dependency_job_id":null,"html_url":"https://github.com/bitcoin-api/bitcoin-api-full-stack","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bitcoin-api%2Fbitcoin-api-full-stack","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bitcoin-api%2Fbitcoin-api-full-stack/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bitcoin-api%2Fbitcoin-api-full-stack/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bitcoin-api%2Fbitcoin-api-full-stack/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/bitcoin-api","download_url":"https://codeload.github.com/bitcoin-api/bitcoin-api-full-stack/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252703335,"owners_count":21790868,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["api","api-gateway","aws","bitcoin","bitcoin-api","bitcoin-node","bitcoin-withdraws","dynamodb","forbidden-code","hidden-code","lambda","middleware","mongodb","nodejs","react","redis","secret-code","serverless","treasure-code","treasure-core"],"created_at":"2024-11-13T19:11:00.000Z","updated_at":"2025-05-06T14:31:27.554Z","avatar_url":"https://github.com/bitcoin-api.png","language":"JavaScript","readme":"# Bitcoin-API-Full-Stack\n\n[![Bitcoin-API-Full-Stack](https://bitcoin-api.s3.amazonaws.com/images/visual_art/so-splush-bee-and-lamby-full-stack-banner-55.png)](#bitcoin-api-full-stack)\n\n\n#### Full Stack Bitcoin API Code\n\n\n## Contents\n* [About](#about)\n* [Bitcoin Node Servers](#bitcoin-node-servers)\n* [How to Set Up the Backend](#how-to-set-up-the-backend)\n* [How to Deploy Backend](#how-to-deploy-backend)\n* [How to Deploy API](#how-to-deploy-api)\n* [How to Deploy Frontend](#how-to-deploy-frontend)\n\n\n### About\n\nBitcoin and digital currency management technology.\n\n\n--\n\n\nThis GitHub repository, Bitcoin-API-Full-Stack, was made open source so others don't have to waste time figuring out how to create their own Bitcoin API services. Also, it was made open source so others have an alternative to using available paid products for creating and using Bitcoin API services. With this repository, people can create their own highly secure, scalable, and performant cloud-based Bitcoin APIs, exchanges, and game platforms that require very little money to operate.\n\nMaking Bitcoin-API-Full-Stack open source was done with the intention of helping people all around the world, helping anybody who wants to provide robust financial services.☮️🌍🌏🌎🏦\n\nThis repository was built in a way such that the resulting created Bitcoin API services can be run by an individual, a team or a company isn't required.😃\n\nIt's not perfect, although it's yours to discover.😇\n\nEnjoy!🎅\n\n--\n\n\n### Bitcoin Node Servers\n\n**Architecture Outline**\n\n* Linux Server\n  * Bitcoin-Core\n  * MongoDB\n  * pm2 Instances:\n    * withdraw bitcoin bot\n    * update deposit data bot\n    * update fee data bot\n    * pm2-logrotate \n\n**Summary of How the Bitcoin Node Servers Work**\n\nThe NodeJS services interact with the Bitcoin node which in turn interacts with the Bitcoin blockchain. Overall, this means the NodeJS services gather data from the Bitcoin blockchain. The NodeJS services then perform the required actions on the Bitcoin-API database. For example the fee data bot gets an estimate for the fee from the Bitcoin blockchain and updates the Bitcoin-API database with that fee. That fee estimate can then be retrieved publicly using the `/fee-data` API endpoint.\n\n### How to Set Up the Backend\n\n\n#### Requirements:\n\n* Have a Mac or Linux server, this can be a computer in your home, or in the cloud (e.g. an [EC2 instance](https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/concepts.html)). The Linux server must meet [Bitcoin Core's computer requirements](https://bitcoin.org/en/bitcoin-core/features/requirements). You need to have access to the server. This means you should be able to access a command-line or terminal in that server using [ssh](https://en.wikipedia.org/wiki/Secure_Shell). You can also manually install the backend on a computer locally without ssh, that computer just needs to stay running and connected to the internet for the services to remain active.\n\n* On the computer you're working on (e.g. your home computer), clone or download this Bitcoin-API-Full-Stack code repository. This repo is like the \"command center\" for your Bitcoin-API instance. Set up, deployment, and other useful commands are performed using the files and scripts in this repo.\n\n* Have a Redis service that you can access using a URL. [Redis Labs](https://redislabs.com) provides great Redis services.\n\n\n### Set Up The Bitcoin Node Server(s)\n\nThe backend node server is responsible for updating the database. The backend node server has three main functions:\n\n1. Update the fee data\n\n2. Update the bitcoin deposit data, this includes user balance data\n\n3. Perform bitcoin withdraws\n\n\n\u003e About multiple servers:\nYou can set up multiple backend servers if you have lots and lots of addresses although you only need one backend server, even if you have a large number of addresses.\n\n\n#### Steps to Setup a Bitcoin-API Bitcoin Node Server\n\nThis section assumes you have the requirements listed above.\n\n\n#### 1) Install and Start Bitcoin node\n\n**About**\n\nInstall and start [Bitcoin Core](https://bitcoin.org/en/bitcoin-core) on the server. This can take a while because the mainnet blockchain takes a decent amount of time to transfer to your server through the internet because of its size which is currently over 250GB. The testnet blockchain downloads much faster because it's currently only around 25GB.\n\n\n**Steps**\n\n**a)** First, in the CLI of your Linux server, download the most recent Bitcoin Core code with the following command:\n```\nwget https://bitcoin.org/bin/bitcoin-core-0.20.0/bitcoin-0.20.0-x86_64-linux-gnu.tar.gz\n```\n(you can check the [Official Bitcoin Core Download Page](https://bitcoin.org/en/download) to make sure this is the most recent Linux download link)\n\n**b)** Extract the computer-usable code from the downloaded Bitcoin Core code:\n\n```\ntar xzf bitcoin-0.20.0-x86_64-linux-gnu.tar.gz\n```\n\n**c)** Run this command to set up the Bitcoin Core Bitcoin node code on your Linux server:\n\n```\nsudo install -m 0755 -o root -g root -t /usr/local/bin bitcoin-0.20.0/bin/*\n```\n\n**d)** Start your Bitcoin node:\n\nStart your bitcoin in staging mode (testnet):\n```\nbitcoind -testnet -daemon\n```\n\nOR\n\nStart your bitcoin in production mode (mainnet):\n```\nbitcoind -daemon\n```\n\nThis should start up your Bitcoin node and trigger the blockchain to begin downloading onto your Linux server.\n\nYou can check to see that your Bitcoin node is running and how many blocks have currently been downloaded using the following command:\n\nin staging\n```\nbitcoin-cli -testnet getblockcount\n``` \nOR\n\nin production\n```\nbitcoin-cli getblockcount\n```\n\nThe resulting number of this bitcoin-cli command can be compared with the total number of blocks in the Bitcoin blockchain, also called the *block height*:\n\n* [Blockchain.com Webpage with the Testnet Total Block Height](https://www.blockchain.com/btc-testnet/blocks)\n\n* [Blockchain.com Webpage with the Mainnet Total Block Height](https://www.blockchain.com/btc/blocks)\n\n\u003e Warning: if the getblockcount command stops working, it could mean your Bitcoin node crashed due to insufficient memory on your Linux computer.\n\n\u003e ‍For reference: here's a list of commands you can use on your bitcoin node: [Chain Query list of commands for bitcoin-cli](https://chainquery.com/bitcoin-cli).\n\nWhen your node has finished downloading and is up to date with the Bitcoin blockchain, the number returned from getblockcount will be equal to the actual blockchain block height. In the meantime, you can move forwards to the next steps.\n\n#### 2) Install NodeJS and NPM\n\n**About**\n\nNext, NodeJS needs to be installed on your Linux server. NodeJS is used for the modules that interact with the Bitcoin node.\n\n**Steps**\n\n**a)** Install Git on your Linux server (Homebrew requires Git to be installed):\n```\nsudo apt install git\n```\nOR\n```\nsudo yum install git\n```\n\n**b)** Install and Configure Homebrew\n\nFirst run:\n```\n/bin/bash -c \"$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)\"\n```\n\nThen run:\n```\nsudo apt-get install build-essential\n```\nOR\n```\nsudo yum groupinstall 'Development Tools'\n```\n\nThen run:\n```\necho 'eval $(/home/linuxbrew/.linuxbrew/bin/brew shellenv)' \u003e\u003e /home/\u003cPUT COMPUTER USER NAME HERE (e.g. ec2-user)\u003e/.bash_profile\neval $(/home/linuxbrew/.linuxbrew/bin/brew shellenv)\n```\n\nHomebrew also recommends running these commands:\n```\nbrew install gcc\nexport LDFLAGS=\"-L/home/linuxbrew/.linuxbrew/opt/isl@0.18/lib\"\nexport CPPFLAGS=\"-I/home/linuxbrew/.linuxbrew/opt/isl@0.18/include\"\nexport PKG_CONFIG_PATH=\"/home/linuxbrew/.linuxbrew/opt/isl@0.18/lib/pkgconfig\"\n```\n\n**c)** Install NodeJS and NPM with Homebrew\n\nRun the following commands:\n```\nbrew install node@12\necho 'export PATH=\"/home/linuxbrew/.linuxbrew/opt/node@12/bin:$PATH\"' \u003e\u003e /home/\u003cPUT COMPUTER USER NAME HERE (e.g. ec2-user)\u003e/.bash_profile\nexport LDFLAGS=\"-L/home/linuxbrew/.linuxbrew/opt/node@12/lib\"\nexport CPPFLAGS=\"-I/home/linuxbrew/.linuxbrew/opt/node@12/include\"\n```\n\nTry typing in `node` in your CLI and see if your CLI turns into a NodeJS REPL interface. If not, try reconnecting to your Linux server. It's possible that will trigger NodeJS to be activated.\n\n**d)** Install pm2 Globally\n\nTo install [pm2](https://pm2.keymetrics.io/) globally, run the following `npm` command:\n```\nnpm install pm2@latest -g\n```\n\nNext, install [pm2-logrotate](https://www.npmjs.com/package/pm2-logrotate) with the following `pm2` command:\n```\npm2 install pm2-logrotate\n```\n\n#### 3) Install and Start MongoDB\n\n**About**\n\nMongoDB is used locally on your Bitcoin-API Bitcoin node server for caching. It prevents unnecessary non local server database writes to the main cloud database when updating addresses and balances.\n\nThese instructions will go through setting up MongoDB on an Amazon Linux server. If your machine is not an Amazon Linux, you can find the appropriate instructions here in the [official MongoDB Linux installation instructions](https://docs.mongodb.com/manual/administration/install-on-linux/).\n\n**Steps**\n\n**a)** Set Up Linux Server for MongoDB\n\nAdd the following as a file at this location, `/etc/yum.repos.d/mongodb-org-4.2.repo`, on your Linux server:\n```\n[mongodb-org-4.2]\nname=MongoDB Repository\nbaseurl=https://repo.mongodb.org/yum/amazon/2/mongodb-org/4.2/x86_64/\ngpgcheck=1\nenabled=1\ngpgkey=https://www.mongodb.org/static/pgp/server-4.2.asc\n```\n\u003e This file can be added using the `touch` and `nano` CLI commands. You may need to use `sudo` in front of those commands for admin access.\n\n**b)** Install and Start `mongod` MongoDB Base Process\n\nInstall MongoDB with this CLI command:\n```\nsudo yum install -y mongodb-org\n```\n\nStart the `mongod` base process:\n```\nsudo systemctl start mongod\n```\n\nYou can verify that the `mongod` base processes has started successfully with: \n```\nsudo systemctl status mongod\n```\n\n\n#### 4) Set Up Bitcoin-API Bitcoin Node Backend\n\n**About**\n\nThis section deals with set up for deployment to a remote Linux server. The deployment method used is called Giraffe Lick Leaf (GLL). The way GLL deployment works is you input a deploy command on your home computer that specifies a NodeJS service for the Bitcoin node. The deploy command triggers your home computer to send the most recent code for the specified NodeJS service to the remote Linux server. The Linux server accepts and installs the NodeJS service if it doesn't already exist, or it updates the existing service. \n\nThis section goes through how to set up the Bitcoin-API Bitcoin node backend for deployment. The main task is to transfer the Tree Deploy🌲🌳 code to the Linux server. The tree deploy code runs on your Linux server and it accepts and install the incoming code sent from your home computer.\n\n\n**Steps**\n\n**a)** Set Up Files and Folders\n\nSet up the appropriate files and folders using the following CLI commands:\n```\ntouch currentWithdrawReports.txt\nmkdir tigerScript\nmkdir treeDeploy\nmkdir treeDeploy/giraffeDeploy\n```\n\nand in staging:\n```\nmkdir treeDeploy/stagingCredentials\n```\nOR\n\nin production:\n```\nmkdir treeDeploy/productionCredentials\n```\n\n**b)** Set Up AWS Resources\n\nThis section goes over the AWS resources that are needed to operate the backend.\n\n##### Backend IAM Policies\n\nHere's the [AWS IAM Policies](https://docs.aws.amazon.com/IAM/latest/UserGuide/access_policies.html) that are needed for Bitcoin-API's backend. The naming for the staging IAM policies is the same except for `_staging` is appended to the policy name.\n\n[AWS IAM Policy Management Console](https://console.aws.amazon.com/iam/home#/policies)\n\n* [`bitcoin_api_user_addressGenerator`](infrastructure/policies/aws/bitcoin_api_user_addressGenerator.json)\n\n* [`bitcoin_api_user_feeDataBot`](infrastructure/policies/aws/bitcoin_api_user_feeDataBot.json)\n\n* [`bitcoin_api_user_withdrawsBot`](infrastructure/policies/aws/bitcoin_api_user_withdrawsBot.json)\n\n* [`bitcoin_api_user_depositsBot`](infrastructure/policies/aws/bitcoin_api_user_depositsBot.json)\n\n* [`bitcoin_api_eFunction_addTransactionAndUpdateExchangeUser`](infrastructure/policies/aws/bitcoin_api_eFunction_addTransactionAndUpdateExchangeUser.json)\n\n\n##### Backend IAM Users\n\nNext, the [AWS IAM Users](https://docs.aws.amazon.com/IAM/latest/UserGuide/id_users.html) for Bitcoin-API's backend need to be set up. The naming for the staging IAM users is the same except for `_staging` is appended to the user name.\n\n[AWS IAM User Management Console](https://console.aws.amazon.com/iam/home#/users)\n\n**Address Generator User**\n\nuser name: `bitcoin_api_addressGenerator`\n\npolicies: `bitcoin_api_user_addressGenerator`\n\n\n**Fee Data Bot User**\n\nuser name: `bitcoin_api_feeDataBot`\n\npolicies: `bitcoin_api_user_feeDataBot`\n\n\n**Withdraws Bot User**\n\nuser name: `bitcoin_api_withdrawsBot`\n\npolicies: `bitcoin_api_user_withdrawsBot`, `bitcoin_api_eFunction_addTransactionAndUpdateExchangeUser`\n\n\n**Deposits Bot User**\n\nuser name: `bitcoin_api_depositsBot`\n\npolicies: `bitcoin_api_user_depositsBot`, `bitcoin_api_eFunction_addTransactionAndUpdateExchangeUser`\n\n\n##### Backend DynamoDB Tables\n\nThis section describes the required [AWS DynamoDB](https://aws.amazon.com/dynamodb) production tables for Bitcoin-API. The staging tables are the same except for `_staging` is appended on the table name.\n\n[AWS DynamoDB Management Console](https://console.aws.amazon.com/dynamodb/home)\n\n| Table Name | Partition Key (type) | Sort Key (type ) | \n|--|--|--|\n| bitcoin_api_addresses | userId (string) | address (string) | \n| bitcoin_api_exchangeEmailDeliveryResults | email (string) | creationDate (number) | \n| bitcoin_api_balances | userId (string) | - | \n| bitcoin_api_exchangeUsers | userId (string) | - | \n| bitcoin_api_loginTokens | exchangeUserId (string) | expiryTime (number) | \n| bitcoin_api_metadata | key (string) | - |\n| bitcoin_api_transactions | exchangeUserId (string) | transactionId (string) |\n| bitcoin_api_users | userId (string) | - |\n| bitcoin_api_withdraws | userId (string) | ultraKey (number) |\n\n\n##### Backend DynamoDB Secondary Indexes\n\n| Table Name | Index Name | Partition Key (type) | Sort Key (type ) |\n|--|--|--|--|\n| bitcoin_api_addresses | address-index | address (string) | - |\n| bitcoin_api_exchangeUsers | email-index | email (string) | - |\n| bitcoin_api_transactions | exchangeUserId-creationDate-index | exchangeUserId (string) | creationDate (number) |\n| bitcoin_api_withdraws | state-creationDate-index | state (string) | creationDate (number) |\n\n\n#### About the Database\n\nIn the Bitcoin-API system, some DynamoDB database operations are queued with [Dr. Q👨🏿‍🔬](https://github.com/bitcoin-api/drq) to prevent conflicting updates. For preciseness, the locking queues will be called *Q-Locks👨🏿‍🔬* in this documentation.\n\n#### About Dr. Q's Q-Locks👨🏿‍🔬\n\nQ-Locks run the operations their locking in series as opposed to running them concurrently in parallel. If an operation is in a Q-Lock and another operation with the same Q-Lock attempts to be performed, the second operation will have to wait until the first operation has finished in its own Q-Lock. A Q-Lock is identified in Bitcoin-API using a string with the following format `{type}:{id}`. An example of this would be the Q-Lock used in the `POST /withdraws` endpoint whose identifier is `withdraws:user_id`. This endpoint starts the withdraw process for a user attempting to make a withdraw. What having the Q-Lock on this withdraw operation means is that for an individual user, a second withdraw operation can only occur after the first withdraw operation has finished, this prevents double spends.👨🏿‍🔬\n\nBelow lists in detail which operations specifically are in Q-Locks.\n\n\n#### Dr. Q's DynamoDB Database API Q-Locks👨🏿‍🔬\n\n\u003e Terminology:\n\u003e\n\u003e `add exchange transaction` - Adds an exchange transaction entry to the append only DynamoDB table \"bitcoin_api_transactions\". The balance information  for a user is calculated by reviewing and processing all of the entries added for that user.\n\u003e\n\u003e `real deal the withdraw` - Refunds the unused Blockchain withdraw fee if the fee estimate is higher than the actual fee.\n\n\n\u003ctable\u003e\n  \u003ctbody\u003e\n    \u003ctr\u003e\n      \u003cth\u003eQ-Lock👨🏿‍🔬\u003c/th\u003e\n      \u003cth\u003eComponent\u003c/th\u003e\n      \u003cth\u003eActions\u003c/th\u003e\n    \u003c/tr\u003e\n    \u003ctr\u003e\n      \u003ctd\u003ewithdraws:user_id\u003c/td\u003e\n      \u003ctd align=\"center\"\u003ePOST/withdraws\u003c/td\u003e\n      \u003ctd\u003e\n        \u003cul\u003e\n          \u003cli\u003einvoke withdraw (withdraw part 1/4)\u003c/li\u003e\n        \u003c/ul\u003e\n      \u003c/td\u003e\n    \u003c/tr\u003e\n    \u003ctr\u003e\n      \u003ctd\u003ewithdraws:user_id\u003c/td\u003e\n      \u003ctd align=\"center\"\u003ewithdraws bot\u003c/td\u003e\n      \u003ctd\u003e\n        \u003cul\u003e\n          \u003cli\u003edo withdraw from Bitcoin node (withdraw part 2/4)\u003c/li\u003e\n          \u003cli\u003ereal deal the withdraw (withdraw part 3/4 - skip if error in part 2/4)\u003c/li\u003e\n          \u003cli\u003everify withdraw (withdraw part 4/4)\u003c/li\u003e\n        \u003c/ul\u003e\n      \u003c/td\u003e\n    \u003c/tr\u003e\n    \u003ctr\u003e\n      \u003ctd\u003ebalances:user_id\u003c/td\u003e\n      \u003ctd align=\"center\"\u003ePOST/withdraws\u003c/td\u003e\n      \u003ctd\u003e\n        \u003cul\u003e\n          \u003cli\u003edo withdraw (withdraw part 1/4)\u003c/li\u003e\n        \u003c/ul\u003e\n      \u003c/td\u003e\n    \u003c/tr\u003e\n    \u003ctr\u003e\n      \u003ctd\u003ebalances:user_id\u003c/td\u003e\n      \u003ctd align=\"center\"\u003ewithdraws bot\u003c/td\u003e\n      \u003ctd\u003e\n        \u003cul\u003e\n          \u003cli\u003everify withdraw (withdraw part 4/4)\u003c/li\u003e\n        \u003c/ul\u003e\n      \u003c/td\u003e\n    \u003c/tr\u003e\n    \u003ctr\u003e\n      \u003ctd\u003ebalances:user_id\u003c/td\u003e\n      \u003ctd align=\"center\"\u003edeposits bot\u003c/td\u003e\n      \u003ctd\u003e\n        \u003cul\u003e\n          \u003cli\u003edeposits bot\u003c/li\u003e\n        \u003c/ul\u003e\n      \u003c/td\u003e\n    \u003c/tr\u003e\n    \u003ctr\u003e\n    \u003ctd\u003eaddresses:user_id\u003c/td\u003e\n    \u003ctd align=\"center\"\u003ePOST/addresses\u003c/td\u003e\n    \u003ctd\u003e\n    \u003cul\u003e\n        \u003cli\u003eget or assign fresh address, includes assign first address\u003c/li\u003e\n    \u003c/ul\u003e\n    \u003c/td\u003e\n    \u003c/tr\u003e\n    \u003ctr\u003e\n      \u003ctd\u003eusers:user_id\u003c/td\u003e\n      \u003ctd align=\"center\"\u003ePOST/addresses\u003c/td\u003e\n      \u003ctd\u003e\n        \u003cul\u003e\n          \u003cli\u003eassign first address\u003c/li\u003e\n        \u003c/ul\u003e\n      \u003c/td\u003e\n    \u003c/tr\u003e\n    \u003ctr\u003e\n      \u003ctd\u003eusers:user_id\u003c/td\u003e\n      \u003ctd align=\"center\"\u003ePUT/tokens\u003c/td\u003e\n      \u003ctd\u003e\n        \u003cul\u003e\n          \u003cli\u003eupdate token value\u003c/li\u003e\n        \u003c/ul\u003e\n      \u003c/td\u003e\n    \u003c/tr\u003e\n  \u003c/tbody\u003e\n\u003c/table\u003e\n\n\n#### Dr. Q's DynamoDB Database Exchange Q-Locks👨🏿‍🔬\n\n\u003ctable\u003e\n  \u003ctbody\u003e\n    \u003ctr\u003e\n      \u003cth\u003eQ-Lock👨🏿‍🔬\u003c/th\u003e\n      \u003cth\u003eComponent\u003c/th\u003e\n      \u003cth\u003eActions\u003c/th\u003e\n    \u003c/tr\u003e\n    \u003ctr\u003e\n      \u003ctd\u003eexchangeUsers:email\u003c/td\u003e\n      \u003ctd align=\"center\"\u003ePOST/verify-user\u003c/td\u003e\n      \u003ctd\u003e\n        \u003cul\u003e\n          \u003cli\u003everify email\u003c/li\u003e\n        \u003c/ul\u003e\n      \u003c/td\u003e\n    \u003c/tr\u003e\n    \u003ctr\u003e\n      \u003ctd\u003eexchangeEmailDeliveryResults:email\u003c/td\u003e\n      \u003ctd align=\"center\"\u003ehandle exchange email delivery results\u003c/td\u003e\n      \u003ctd\u003e\n        \u003cul\u003e\n          \u003cli\u003eadd exchange email delivery result data to database\u003c/li\u003e\n        \u003c/ul\u003e\n      \u003c/td\u003e\n    \u003c/tr\u003e\n    \u003ctr\u003e\n      \u003ctd\u003eexchangeUsers:exchangeUserId\u003c/td\u003e\n      \u003ctd align=\"center\"\u003ePOST/login\u003c/td\u003e\n      \u003ctd\u003e\n        \u003cul\u003e\n          \u003cli\u003eassign bitcoin address (only for first login)\u003c/li\u003e\n        \u003c/ul\u003e\n      \u003c/td\u003e\n    \u003c/tr\u003e\n    \u003ctr\u003e\n      \u003ctd\u003eexchangeUsers:exchangeUserId\u003c/td\u003e\n      \u003ctd align=\"center\"\u003eDELETE/exchange-users/:exchangeUserId\u003c/td\u003e\n      \u003ctd\u003e\n        \u003cul\u003e\n          \u003cli\u003edelete user\u003c/li\u003e\n        \u003c/ul\u003e\n      \u003c/td\u003e\n    \u003c/tr\u003e\n    \u003ctr\u003e\n      \u003ctd\u003eexchangeUsers:exchangeUserId\u003c/td\u003e\n      \u003ctd align=\"center\"\u003edeposits bot\u003c/td\u003e\n      \u003ctd\u003e\n        \u003cul\u003e\n          \u003cli\u003eupdate Bitcoin deposit info [add exchange transaction]\u003c/li\u003e\n        \u003c/ul\u003e\n      \u003c/td\u003e\n    \u003c/tr\u003e\n    \u003ctr\u003e\n      \u003ctd\u003eexchangeUsers:exchangeUserId\u003c/td\u003e\n      \u003ctd align=\"center\"\u003ePOST/withdraws\u003c/td\u003e\n      \u003ctd\u003e\n        \u003cul\u003e\n          \u003cli\u003estart withdraw (exchange withdraw part 1/5) [add exchange transaction]\u003c/li\u003e\n        \u003c/ul\u003e\n      \u003c/td\u003e\n    \u003c/tr\u003e\n    \u003ctr\u003e\n      \u003ctd\u003eexchangeUsers:exchangeUserId\u003c/td\u003e\n      \u003ctd align=\"center\"\u003ewithdraws bot\u003c/td\u003e\n      \u003ctd\u003e\n        \u003cul\u003e\n          \u003cli\u003efinalize withdraw (exchange withdraw part 5/5) [add exchange transaction]\u003c/li\u003e\n        \u003c/ul\u003e\n      \u003c/td\u003e\n    \u003c/tr\u003e\n    \u003ctr\u003e\n      \u003ctd\u003eexchangeUsers:exchangeUserId\u003c/td\u003e\n      \u003ctd align=\"center\"\u003ePOST/exchanges\u003c/td\u003e\n      \u003ctd\u003e\n        \u003cul\u003e\n          \u003cli\u003edo exchange [add exchange transaction]\u003c/li\u003e\n        \u003c/ul\u003e\n      \u003c/td\u003e\n    \u003c/tr\u003e\n    \u003ctr\u003e\n      \u003ctd\u003eexchangeUsers:exchangeUserId\u003c/td\u003e\n      \u003ctd align=\"center\"\u003ePOST/dreams\u003c/td\u003e\n      \u003ctd\u003e\n        \u003cul\u003e\n          \u003cli\u003eenchanted function ✨🧞‍♀️✨ [add exchange transaction]\u003c/li\u003e\n        \u003c/ul\u003e\n      \u003c/td\u003e\n    \u003c/tr\u003e\n    \u003ctr\u003e\n      \u003ctd\u003evanguard_withdraws:exchangeUserId\u003c/td\u003e\n      \u003ctd align=\"center\"\u003ewithdraws bot\u003c/td\u003e\n      \u003ctd\u003e\n        \u003cul\u003e\n            \u003cli\u003ewithdraw from Bitcoin node (exchange withdraw \n          part 2/5) \u003c/li\u003e\n            \u003cli\u003ereal deal the withdraw (exchange withdraw part 3/5) \u003c/li\u003e\n            \u003cli\u003everify withdraw (exchange withdraw part 4/5) \u003c/li\u003e\n        \u003c/ul\u003e\n      \u003c/td\u003e\n    \u003c/tr\u003e\n  \u003c/tbody\u003e\n\u003c/table\u003e\n\n\n#### Redis Keys and Values\n\n| Key | Type | Value\n|--|--|--|\n| Q | stream - max length 300000 | all [Dr. Q👨🏿‍🔬](https://github.com/bitcoin-api/drq) operations |\n| ipAddressRateLimiterQueueId | stream - max length 200000 | rate limit by ip address (per endpoint per ip address) |\n| advancedCodeRateLimiterQueueId | stream - max length 200000 | rate limit by advanced code (per endpoint per advanced code) |\n| bankStatusQueueId | stream - max length 2000 | The NodeJS services periodically send requests to this queue to indicate whether they're active or not. This is used by the API to determine if the entire Bitcoin-API system is active or not. If the system is not active, all the API endpoints will respond with an error indicating the service is currently unavailable. |\n| cacheOnAndOffStatus | stream - max length 1000 | cache for on and off status of API, you can edit a database value to switch the entire API off or back on |\n| zarbonDeploy | stream - max length 1000 | Giraffe Lick Leaf (GLL) deploy queue |\n| unusedAddressData | list of encoded JSON objects | contains unused address data, this data including the address itself is assigned to users (equivalently Bitcoin-API tokens) when they make requests to the `POST - /addresses` endpoint |\n\n\n##### Backend S3 Storage Bucket\n\nThis section goes over how to set up the required [AWS S3](https://aws.amazon.com/s3) production bucket for Bitcoin-API. The staging bucket is the same except for `_staging` is appended onto the bucket name (recommended for simplicity, although it's not necessary and the S3 staging bucket can have a completely different name if wanted).\n\n[AWS S3 Management Console](https://console.aws.amazon.com/s3/home)\n\n**Steps to Set Up Bitcoin-API S3 Bucket (Staging or Production)**\n\n1. Create a bucket in S3\n\n2. Create a folder on the root level of that bucket and call it `qr_codes`. This is the folder where the Bitcoin address QR code images are stored.\n\n\n**c)** Set Up Backend .env Environment Variable Files\n\nThe following environment files need to be created and set up:\n\n\n**Address Generator**\n\n.env path: `/1-backend/\u003cstagingCredentials OR productionCredentials\u003e/addressGenerator/.env`\n\n.env Template: [Address Generator .env Template File](infrastructure/environment/dotenv-templates/1-backend/addressGenerator.env)\n\n\n**Fee Data Bot**\n\n.env path: `/1-backend/\u003cstagingCredentials OR productionCredentials\u003e/feeDataBot/.env`\n\n.env Template: [Fee Data Bot .env Template File](infrastructure/environment/dotenv-templates/1-backend/feeDataBot.env)\n\n\n**Withdraws Bot**\n\n.env path: `/1-backend/\u003cstagingCredentials OR productionCredentials\u003e/withdrawsBot/.env`\n\n.env Template: [Withdraws Bot .env Template File](infrastructure/environment/dotenv-templates/1-backend/withdrawsBot.env)\n\n\n**Deposits Bot**\n\n.env path: `/1-backend/\u003cstagingCredentials OR productionCredentials\u003e/depositsBot/.env`\n\n.env Template: [Deposits Bot .env Template File](infrastructure/environment/dotenv-templates/1-backend/depositsBot.env)\n\n\n**Giraffe**\n\n.env path: `/1-backend/\u003cstagingCredentials OR productionCredentials\u003e/giraffe/.env`\n\n.env Template: [Giraffe .env Template File](infrastructure/environment/dotenv-templates/1-backend/giraffe.env)\n\n\n**Tree**\n\n.env path: `/1-backend/\u003cstagingCredentials OR productionCredentials\u003e/tree/.env`\n\n.env Template: [Tree .env Template File](infrastructure/environment/dotenv-templates/1-backend/tree.env)\n\n\n**d)** Send and Start Initial NodeJS Services Modules\n\nFor this step, you will manually send and start up the NodeJS service modules (a.k.a. \"The Tigers\"). This is only necessary for the initial setup and after this the Giraffe Lick Leaf (GLL) deployment can be used for instant deploys with a single simple command.\n\nFor this command you will need to create a `/infrastructure/scripts/1-backend/setUpTigers.sh` pre-gitignored set up command file using the provided [`/infrastructure/scripts/1-backend/setUpTigers.template.sh` template file](infrastructure/scripts/1-backend/setUpTigers.template.sh).\n\nA chart is provided showing how to replace the template placeholder values in detail:\n\n\n#### Set Up Tigers Configuration Chart\n\n| value to update  | meaning | example |\n|--|--|--|\n| mode | environment | either staging or production |\n| pemPath | path on your home computer to your Linux server's .pem access key file | /Users/user-name/user-files/super-secret-path/linux-server-access-file.pem |\n| sourceRepoPath | the path on your home computer to where your `bitcoin-api-full-stack` repo is located (this repo!😎) | /Users/user-name/my-code-folder/bitcoin-api-full-stack |\n| destinationUserName | the user name you use to access your Linux server | ec2-user |\n| destinationUrl | the URL of your Linux server | ec2-instance-name.ec2-instance-region.compute.amazonaws.com |\n| destinationHomePath | the home path on your Linux server for your Linux user | /home/ec2-user |\n\nAfter the values have been replaced, run the `/infrastructure/scripts/1-backend/setUpTigers.sh` command to transport the NodeJS service modules from your home computer to your Linux server.\n\nIn the `/infrastructure/scripts/1-backend` folder in your CLI, run:\n\n```\n./setUpTigers.sh\n```\n\u003e note: you may need to run `chmod 777 ./setUpTigers.sh` first before running the set up script\n\nAfter the modules have been transported to your Linux server, it's time to start them up!\n\n\n#### Here's the instructions to manually run your NodeJS services:\n\n**Address Generator (manually triggered)**\n\nThis NodeJS service adds unused addresses to the system. Run the following commands in the `/[Linux user home path]/tigerScript/addressGenerator` path on your Linux server:\n\nIf not already, install the address generator node modules with:\n```\nnpm install\n```\n\nThen, to add new addresses to your Bitcoin-API system, you can run the following command:\n```\nnode AddUnusedAddress [number of addresses to add, defaults to 1]\n```\n\nor in production:\n```\nnode AddUnusedAddress.js [number of addresses to add, defaults to 1] --mode=production\n```\n\nAdding an address to your Bitcoin-API system will look like this:\n![Address Generator Creating New Bitcoin Address](https://bitcoin-api.s3.amazonaws.com/images/documentation/calzone-sun-successfully-added-address.png)\n\n\u003cbr\u003e\n\n**Fee Data Bot (runs in infinite loop)**\n\nThis NodeJS service updates your Bitcoin-API system's fee data which includes the fee itself in terms of how much the user pays on Bitcoin withdraw. This service is managed by pm2. To set up the NodeJS fee data service, in the `/[Linux user home path]/tigerScript/feeDataBot` path on your Linux server, first install the node modules:\n\n```\nnpm install\n```\n\nThen, run the following command to start up the NodeJS fee data service:\n```\npm2 start UpdateFeeDataWorker.js\n```\n\nor in production:\n```\npm2 start UpdateFeeDataWorker.js -- --mode=production\n```\n\nYou can also test the service without pm2 using:\n```\nnode UpdateFeeDataWorker\n```\n\nor:\n```\nnode UpdateFeeDataWorker --mode=production\n```\n\nAfter the main function finishes, it starts again after 10 seconds to keep the fee up to date in your Bitcoin-API system.\n\nWhen the main function has finished, it should look like this:\n\n\u003cimg\n    src=\"https://bitcoin-api.s3.amazonaws.com/images/documentation/fee-fee-successful-execution-2.png\"\n    width=\"800\"\n/\u003e\n\nTo watch your service's logs, first use this pm2 command:\n```\npm2 list\n```\n\nand see which is the number associated with the `UpdateFeeDataWorker.js` process, in this case. Running this command also provides other useful data associated with your pm2 processes.\n\nNext, to view the fee data worker logs in realtime, run:\n```\npm2 logs [the number of your NodeJS service's process]\n```\nYou can optionally sign up and log in to pm2's web services and see your NodeJS service's logs in your browser, in realtime, using the [pm2 webapp](https://app.pm2.io/).\n\nThis pm2 command can also be used to monitor your fee data service and all your other pm2 services:\n```\npm2 monit\n```\n\n\u003e **Important Note:** In the file [`/1-backend/feeDataBot/updateFee.js`](1-backend/feeDataBot/updateFee.js), you can adjust the fee levels using the `getFeeData` function.\n\n\u003e **Errors:** If the service stops working or if you see any errors, particularly as soon as you first run the service, it could be possible there's a misconfiguration. It's also possible there could be a network, a blockchain, or a cloud service provider error. The logs will provide details about the cause of any error that occurs.\n\nThis updates the [AWS DynamoDB](https://console.aws.amazon.com/dynamodb/home) `bitcoin_api_metadata_staging` or `bitcoin_api_metadata` table with the new fee data. The key associated with the fee data in the metadata table is `fee`. The actual fee the user pays is calculated as follows:\n```\nValues stored in the DynamoDB database entry:\namount,\nmultiplier,\nbusiness fee data object of the form:\n{\n    [custom fee key 1]: {\n        amount: a1\n    },\n    [custom fee key 2]: {\n        amount: a2\n    },\n    ...\n    [custom fee key n]: {\n        amount: an\n    }\n}\nwhere 0 \u003c= a1,a2,...,an and a1,a2,...,an are real numbers\n\nCalculation:\n\nblockchain fee estimate = (amount x multiplier)\nbusiness fee = sum of the \"businessFeeData\" object's fee amounts\n\nfee estimate to pay = (blockchain fee estimate + business fee)\n```\nThis is a fee estimate because if the actual blockchain fee needed and used is less than the blockchain fee estimate, any unused blockchain fee from the estimate in the actual Bitcoin node withdraw will get refunded to the user after the Bitcoin node withdraw has finished.\n\nFor example, if the blockchain fee estimate is 0.0001 BTC and only 0.00003 BTC is needed for the Bitcoin node withdraw blockchain fee, then 0.00007 BTC will be refunded to the user.\n\n\n#### EnviroWithdraws\n\nEnviroWithdraws are intended for collecting money for our environment. The `POST - /withdraws` endpoint has an optional request body Bitcoin amount parameter `enviroWithdrawAmount`. The `enviroWithdrawAmount` parameter automatically adds its value to the `businessFeeData` object with the custom key `enviroWithdraw` whose corresponding object value contains the specified `enviroWithdrawAmount`.\n\nHere's an example of the resulting `businessFeeData` with an `enviroWithdrawAmount` of 0.000001 BTC specified in the request body:\n```.js\n{\n    {...},\n    ...\n    enviroWithdraw: {\n        amount: 0.000001\n    }\n}\n```\n\nEnviroWithdraw or not, Bitcoin-API suggests to please consider contributing a portion of the fees you collect towards the environment and thank you very much for considering our environment!🌲🌳🌄\n\n\u003cbr\u003e\n\n\n**Deposits Bot (runs in infinite loop)**\n\nThis NodeJS service updates Bitcoin addresses and user balances for Bitcoin deposits to Bitcoin-API addresses. To set up this pm2 managed NodeJS Bitcoin deposit worker service, in the `/[Linux user home path]/tigerScript/depositsBot` path on your Linux server, first install the node modules:\n\n```\nnpm install\n```\n\nTo run the Bitcoin deposit worker, input the following command:\n```\npm2 start UpdateDepositData.js\n```\n\nor in production:\n```\npm2 start UpdateDepositData.js -- --mode=production\n```\n\nYou can also test the service without pm2 using:\n```\nnode UpdateDepositData\n```\n\nor:\n```\nnode UpdateDepositData --mode=production\n```\n\nA successful iteration of the Bitcoin deposit worker should look like this:\n\n![Update Deposit Data Worker Successful Execution](https://bitcoin-api.s3.amazonaws.com/images/documentation/theomega-successful-execution.png)\n\n\n\u003cbr\u003e\n\n\n**Withdraws Bot (runs in infinite loop)**\n\nThis NodeJS service performs Bitcoin withdraws. To set up this pm2 managed NodeJS withdraw Bitcoin worker service, in the `/[Linux user home path]/tigerScript/withdrawsBot` path on your Linux server, first install the node modules:\n\n```\nnpm install\n```\n\nTo run the withdraw Bitcoin worker, input the following command:\n```\npm2 start WithdrawMoneyDoer.js\n```\n\nor in production:\n```\npm2 start WithdrawMoneyDoer.js -- --mode=production\n```\n\nYou can also test the service without pm2 using:\n```\nnode WithdrawMoneyDoer\n```\n\nor:\n```\nnode WithdrawMoneyDoer --mode=production\n```\n\nWhen an iteration of the withdraw Bitcoin worker completes, it should look like this:\n\n![Withdraw Money Doer Successful Execution](https://bitcoin-api.s3.amazonaws.com/images/documentation/korg-successful-execution.png)\n\n\u003cbr\u003e\n\n**e)** Transfer Tree Deploy🌲🌳 Code\n\nThis step explains how to set up the tree deploy code.\n\nTo transfer the tree deploy code first you must create a `/infrastructure/scripts/1-backend/plantTree.sh` file (pre-gitignored). A template file is provided at [`/infrastructure/scripts/1-backend/plantTree.template.sh`](infrastructure/scripts/1-backend/plantTree.template.sh).\n\nRefer to the [Set Up Tigers Configuration Chart](#set-up-tigers-configuration-chart) for details on how to configure the required values which are the same for `plantTree.sh`.\n\nAfter you've set up your `plantTree.sh` file, transfer your tree deploy files to your Linux server by running the following command in the `/infrastructure/scripts/1-backend` folder:\n```\n./plantTree.sh\n```\n\u003e note: you may need to run `chmod 777 ./plantTree.sh` first before running the plant tree script\n\nNow, in your Linux server, go to the `/[Linux user home path]/treeDeploy/giraffeDeploy/tree` folder and install the node modules for your tree deployment code with:\n```\nnpm install\n```\n\nYou can test that the transfer and set up of your tree deploy code went successfully by running the following command:\n```\nnode WaterTree\n```\n\nor in production:\n```\nnode WaterTree --mode=production\n```\n\nIt will look like this:\n![Water Tree No-Op](https://bitcoin-api.s3.amazonaws.com/images/documentation/water-tree-no-op.png)\n\n\nAnd that's it, your Bitcoin-API backend Bitcoin node server is now operational and is also ready for ultra-fast Giraffe Lick Leaf deployments! See more on this in the next step.\n\n\n\u003cbr\u003e\n\n### How to Deploy Backend\n\nNow that we've got our Bitcoin-API backend Bitcoin node server up and running, let's go over how to do a super fast Giraffe Lick Leaf (GLL) deployment to instantly update your backend NodeJS services!\n\nFirst, in your Linux server at `/[Linux user home path]/treeDeploy/giraffeDeploy/tree`, run:\n```\nnode WaterTree\n```\n\nor in production:\n```\nnode WaterTree --mode=production\n```\n\nThis command will start up your tree code acceptor and installer. \n\n\nNow, on your home computer in one of the `/infrastructure/scripts/1-backend/giraffeLickLeaf/feeDataBot`, `/infrastructure/scripts/1-backend/giraffeLickLeaf/withdrawsBot`, or `/infrastructure/scripts/1-backend/giraffeLickLeaf/depositsBot` folders in this repo, run one of the following commands to do an instant deployment of a NodeJS service:\n\n##### Deploy Backend NodeJS Service with GLL\n\n```\n./deployStaging.sh\n```\n\nor in production:\n```\n./deployProduction.sh\n```\n\nThis will trigger a GLL deployment to update your NodeJS service, here's an example demo video of what the deployment looks like:\n\n\u003ca href=\"https://www.youtube.com/watch?v=ZZ4zdq4AJY8\"\u003e\n    \u003cimg\n        src=\"https://bitcoin-api.s3.amazonaws.com/documents/open-source/bitcoin-api-full-stack/youtube-logo-2.png\"\n        width=\"85\"\n    /\u003e\n\u003c/a\u003e\n\nGLL deployment provides continuous integration for the backend NodeJS services that interact with the Bitcoin node on the Linux server. The overall Bitcoin-API service doesn't need to be shut down or be interrupted.\n\nAfter you've finished your deployments, you can shut down your Water Tree code acceptor and installer process in your Linux server. To do this simply input the keyboard keys `control` plus `c`.\n\n\n\n### How to Deploy API\n\nThe API is serverless, it uses [AWS Lambda](https://aws.amazon.com/lambda) functions which are accessed through [API Gateway](https://aws.amazon.com/api-gateway). This section goes over how to set the API up.\n\n\n**a)** Set Up Environment Variables\n\nUse the [API Environment Variable Template File](infrastructure/environment/dotenv-templates/2-api/api.env), create an environment variable file and add it to `/2-api/stagingCredentials/.env` in staging, and add it to `/2-api/productionCredentials/.env` in production.\n\n\n**b)** Set Up AWS API Resources\n\nThis section goes over the [AWS](https://aws.amazon.com) resources that necessary to set up and run the Bitcoin-API API.\n\n\n##### API IAM Policies\n\nHere's the [AWS IAM Policies](https://docs.aws.amazon.com/IAM/latest/UserGuide/access_policies.html) that are needed for Bitcoin-API's API. The naming for the staging IAM policies is the same except for `_staging` is appended to the policy name.\n\n[AWS IAM Policy Management Console](https://console.aws.amazon.com/iam/home#/policies)\n\n\n**Built-In AWS Policies Used:**\n\n* `AWSLambdaBasicExecutionRole`\n\n\n**Custom AWS Policies to Set Up:**\n\n* [`bitcoin_api_user_deployAPIFunctions`](infrastructure/policies/aws/bitcoin_api_user_deployAPIFunctions.json)\n\n* [`bitcoin_api_user_deployExchangeFunctions`](infrastructure/policies/aws/bitcoin_api_user_deployExchangeFunctions.json)\n\n* [`bitcoin_api_eFunction_mongolianBeginningDragonProtection`](infrastructure/policies/aws/bitcoin_api_eFunction_mongolianBeginningDragonProtection.json)\n\n* [`bitcoin_api_role_lambda_api_tokens_post`](infrastructure/policies/aws/bitcoin_api_role_lambda_api_tokens_post.json)\n\n* [`bitcoin_api_role_lambda_api_tokens_get`](infrastructure/policies/aws/bitcoin_api_role_lambda_api_tokens_get.json)\n\n* [`bitcoin_api_role_lambda_api_tokens_put`](infrastructure/policies/aws/bitcoin_api_role_lambda_api_tokens_put.json)\n\n* [`bitcoin_api_role_lambda_api_addresses_post`](infrastructure/policies/aws/bitcoin_api_role_lambda_api_addresses_post.json)\n\n* [`bitcoin_api_role_lambda_api_feeData_get`](infrastructure/policies/aws/bitcoin_api_role_lambda_api_feeData_get.json)\n\n* [`bitcoin_api_role_lambda_api_withdraws_post`](infrastructure/policies/aws/bitcoin_api_role_lambda_api_withdraws_post.json)\n\n* [`bitcoin_api_role_lambda_service_cacheOnAndOffStatus`](infrastructure/policies/aws/bitcoin_api_role_lambda_service_cacheOnAndOffStatus.json)\n\n* [`bitcoin_api_role_lambda_eAPI_eUsers_post`](infrastructure/policies/aws/bitcoin_api_role_lambda_eAPI_eUsers_post.json)\n\n* [`bitcoin_api_role_lambda_eAPI_eUsers_get`](infrastructure/policies/aws/bitcoin_api_role_lambda_eAPI_eUsers_eUserId_get.json)\n\n* [`bitcoin_api_role_lambda_eAPI_eUsers_eUserId_delete`](infrastructure/policies/aws/bitcoin_api_role_lambda_eAPI_eUsers_eUserId_delete.json)\n\n* [`bitcoin_api_role_lambda_eAPI_verifyUser_post`](infrastructure/policies/aws/bitcoin_api_role_lambda_eAPI_verifyUser_post.json)\n\n* [`bitcoin_api_role_lambda_eAPI_login_post`](infrastructure/policies/aws/bitcoin_api_role_lambda_eAPI_login_post.json)\n\n* [`bitcoin_api_role_lambda_eAPI_logout_post`](infrastructure/policies/aws/bitcoin_api_role_lambda_eAPI_logout_post.json)\n\n* [`bitcoin_api_role_lambda_eAPI_withdraws_post`](infrastructure/policies/aws/bitcoin_api_role_lambda_eAPI_withdraws_post.json)\n\n* [`bitcoin_api_role_lambda_eService_handleEEDRs`](infrastructure/policies/aws/bitcoin_api_role_lambda_eService_handleEEDRs.json)\n\n##### API IAM Roles\n\nThe following [AWS IAM Roles](https://docs.aws.amazon.com/IAM/latest/UserGuide/id_roles.html) need to be created and set up. The naming for the staging IAM roles is the same except for `_staging` is appended to the policy name.\n\n[AWS IAM Role Management Console](https://console.aws.amazon.com/iam/home#/roles)\n\n\n**Infrastructure: Empty Lambda**\n\nname: `bitcoin_api_lambda_infrastructure_emptyLambda`\n\npolicies: `AWSLambdaBasicExecutionRole`\n\n\n**API: POST - /tokens**\n\nname: `bitcoin_api_lambda_api_tokens_post`\n\npolicies: `AWSLambdaBasicExecutionRole`, `bitcoin_api_role_lambda_api_tokens_post`\n\n\n**API: GET - /tokens**\n\nname: `bitcoin_api_lambda_api_tokens_get`\n\npolicies: `AWSLambdaBasicExecutionRole`, `bitcoin_api_role_lambda_api_tokens_get`\n\n\n**API: PUT - /tokens**\n\nname: `bitcoin_api_lambda_api_tokens_put`\n\npolicies: `AWSLambdaBasicExecutionRole`, `bitcoin_api_role_lambda_api_tokens_put`\n\n\n**API: POST - /addresses**\n\nname: `bitcoin_api_lambda_api_addresses_post`\n\npolicies: `AWSLambdaBasicExecutionRole`, `bitcoin_api_role_lambda_api_addresses_post`\n\n\n**API: GET - /fee-data**\n\nname: `bitcoin_api_lambda_api_feeData_get`\n\npolicies: `AWSLambdaBasicExecutionRole`, `bitcoin_api_role_lambda_api_feeData_get`\n\n\n**Service - Cache On and Off Status**\n\nname: `bitcoin_api_lambda_service_cacheOnAndOffStatus`\n\npolicies: `AWSLambdaBasicExecutionRole`, `bitcoin_api_role_lambda_service_cacheOnAndOffStatus`\n\n\n**API: POST - /withdraws**\n\nname: `bitcoin_api_lambda_api_withdraws_post`\n\npolicies: `AWSLambdaBasicExecutionRole`, `bitcoin_api_role_lambda_api_withdraws_post`\n\n\n**Exchange API: POST - /exchange-users**\n\nname: `bitcoin_api_lambda_eAPI_eUsers_post`\n\npolicies: `AWSLambdaBasicExecutionRole`, `bitcoin_api_role_lambda_eAPI_eUsers_post`\n\n\n**Exchange API: GET - /exchange-users/:exchange-user-id**\n\nname: `bitcoin_api_lambda_eAPI_eUsers_eUserId_get`\n\npolicies: `AWSLambdaBasicExecutionRole`, `bitcoin_api_eFunction_mongolianBeginningDragonProtection`, `bitcoin_api_role_lambda_eAPI_eUsers_eUserId_get`\n\n\n**Exchange API: DELETE - /exchange-users/:exchange-user-id**\n\nname: `bitcoin_api_lambda_eAPI_eUsers_eUserId_delete`\n\npolicies: `AWSLambdaBasicExecutionRole`, `bitcoin_api_eFunction_mongolianBeginningDragonProtection`, `bitcoin_api_role_lambda_eAPI_eUsers_eUserId_delete`\n\n\n**Exchange API: POST - /verify-user**\n\nname: `bitcoin_api_lambda_eAPI_verifyUser_post`\n\npolicies: `AWSLambdaBasicExecutionRole`, `bitcoin_api_role_lambda_eAPI_login_post`, `bitcoin_api_role_lambda_eAPI_verifyUser_post`\n\n\n**Exchange API: POST - /login**\n\nname: `bitcoin_api_lambda_eAPI_login_post`\n\npolicies: `AWSLambdaBasicExecutionRole`, `bitcoin_api_role_lambda_eAPI_login_post`\n\n\n**Exchange API: POST - /withdraws**\n\nname: `bitcoin_api_lambda_eAPI_withdraws_post`\n\npolicies: `AWSLambdaBasicExecutionRole`, `bitcoin_api_role_lambda_eAPI_withdraws_post`, `bitcoin_api_eFunction_addTransactionAndUpdateExchangeUser`, `bitcoin_api_eFunction_mongolianBeginningDragonProtection`\n\n\n**Exchange API: POST - /logout**\n\nname: `bitcoin_api_lambda_eAPI_logout_post`\n\npolicies: `AWSLambdaBasicExecutionRole`, `bitcoin_api_eFunction_mongolianBeginningDragonProtection`, `bitcoin_api_role_lambda_eAPI_logout_post`\n\n\n**Exchange API: POST - /exchanges**\n\nname: `bitcoin_api_lambda_eAPI_exchanges_post`\n\npolicies: `AWSLambdaBasicExecutionRole`, `bitcoin_api_eFunction_addTransactionAndUpdateExchangeUser`, `bitcoin_api_eFunction_mongolianBeginningDragonProtection`\n\n\n**Exchange API: POST - /dreams**\n\nname: `bitcoin_api_lambda_eAPI_dreams_post`\n\npolicies: `AWSLambdaBasicExecutionRole`, `bitcoin_api_eFunction_addTransactionAndUpdateExchangeUser`, `bitcoin_api_eFunction_mongolianBeginningDragonProtection`\n\n\n**Exchange Service - Handle Exchange Email Delivery Results (EEDRs)**\n\nname: `bitcoin_api_lambda_eService_handleEEDRs`\n\npolicies: `AWSLambdaBasicExecutionRole`, `bitcoin_api_role_lambda_eService_handleEEDRs`\n\n\n##### API IAM Users\n\nTo deploy the API, the following [AWS IAM User](https://docs.aws.amazon.com/IAM/latest/UserGuide/id_users.html) needs to be created and set up. The naming for the staging IAM user is the same except for `_staging` is appended to the user name.\n\n[AWS IAM User Management Console](https://console.aws.amazon.com/iam/home#/users)\n\n**Deploy API User**\n\nuser name: `bitcoin_api_deployAPI`\n\npolicies: `bitcoin_api_user_deployAPIFunctions`, `bitcoin_api_user_deployExchangeFunctions`\n\n\n#### Deploy API\n\nTo deploy the [AWS Lambda](https://aws.amazon.com/lambda) functions required for the Bitcoin-API API, in the `/infrastructure/scripts/2-api` path in this repo, run the following script:\n```\n./deployStaging --meta=\"a\"\n```\nor in production:\n\n```\n./deployProduction --meta=\"a\"\n```\n\nFor reference here are the API deploy command options:\n\n| command name  | meaning | possible values |\n|--|--|--|\n| functions |  filter functions by nickname, function names separated by commas  | any Lambda function nickname (e.g. `POST/tokens,GET/tokens`) |\n| meta | API(a) or exchange(e) | `a`, `e`, or `ae` (deploy all functions, defaults to `ae`)  |\n\nThis will set up the Lambda functions associated with the core API part of your Bitcoin-API. Next, the set up for the [AWS API Gateway](https://aws.amazon.com/api-gateway) API used as your core API will be explained in detail. How this works is you create an HTTP API with API Gateway and you attach your deployed Lambda functions to the HTTP API Gateway. After you set up the core API, you will be able to set up the exchange API.\n\n#### API Gateway Set Up \n\nFirst go to the [AWS API Gateway Console](https://console.aws.amazon.com/apigateway/main/apis) and press \"Create API\".\n\nFor the \"Choose an API type\" section, choose \"Build\" for the \"HTTP API\" type API.\n\nYou will next be prompted to input a name for your API. Input an API name such as `bitcoin_api_core_api_staging` or `bitcoin_api_core_api` and press \"Next\".\n\nNext, you will be prompted to \"Configure routes\". Press \"Next\".\n\nYou will then be prompted to \"Review and create\". Pres \"Create\".\n\nNext, create six Lambda integrations, and attach them to the appropriate routes:\n\n* `bitcoin_api_api_tokens_post_staging`\n\n* `bitcoin_api_api_tokens_get_staging`\n\n* `bitcoin_api_api_tokens_put_staging`\n\n* `bitcoin_api_api_addresses_post_staging`\n\n* `bitcoin_api_api_feeData_get_staging`\n\n* `bitcoin_api_api_withdraws_post_staging`\n\n\n**CORS Settings Configuration:**\n\n| Setting |  Value |\n|--|--|\n| Access-Control-Allow-Origin | * |\n| Access-Control-Allow-Headers | * |\n| Access-Control-Allow-Methods | * |\n| Access-Control-Expose-Headers | * |\n| Access-Control-Max-Age | 0 Seconds |\n\nNext, now your core Bitcoin-API API is almost active, only a couple more steps.\n\nFirst, add the following database entry to the `bitcoin_api_metadata` or the `bitcoin_api_metadata_staging` DynamoDB table:\n```.json\n{\n  \"key\": \"onAndOffSwitch\",\n  \"bitcoinAPIIsOn\": true,\n  \"bitcoinAPIIsOffReason\": \"This Bitcoin-API instance is off because I'm out having fun with my lover!!!🌹💕💘️💖💏💖💘️💕🌹\"\n}\n```\nYou can use this database object to control whether the whole API is on or off. Simply set \n`bitcoinAPIIsOn` to `false` to turn the API off.\n\nNow, add the following Lambda function to [run periodically using CloudWatch](https://console.aws.amazon.com/cloudwatch/home?region=us-east-1#rules):\n\n* `bitcoin_api_lambda_service_cacheOnAndOffStatus` - every one minute\n\nAnd now, your Bitcoin-Api core API is active!\n\n\n#### Deploy The Exchange API\n\nTo finish the rest of the set up which includes setting up the exchange, there's a few more steps.\n\n**Set Up Exchange Bitcoin-API Token**\n\nCreate a token using the `POST - /tokens` endpoint on your newly created API. The token and the userId associated with this token both need to be added for your API environment variables `EXCHANGE_BITCOIN_API_TESTNET_TOKEN` and `EXCHANGE_TOKEN_USER_ID`. \n\nInitialize this token by retrieving an address with it. Make a request to the `POST - /addresses` endpoint using your token.\n\n**Deploy Exchange API Lambda Functions**\n\nDeploy your Bitcoin-API exchange API functions with the following command in the `/infrastructure/scripts/2-api` path in this repo:\n\n```\n./deployStaging --meta=\"e\"\n```\nor in production:\n```\n./deployProduction --meta=\"e\"\n```\n\n**Set Up AWS SES**\n\nSet up your [AWS SES](https://aws.amazon.com/ses/) email. SES is used to send emails for setting up exchange accounts.\n\nFirst, verify the email that you're going to be using to send the exchange emails from, this can be your exchange's support email. You can also verify the entire domain of the email that you're sending from. Verifying your email can be done on [this page in the AWS SES browser console](https://console.aws.amazon.com/ses/home#verified-senders-domain:).\n\nNext, create an [AWS SNS](https://aws.amazon.com/sns) topic to forward email events to an AWS Lambda function. Call this topic `bitcoin_api_e_emailDeliveryResultsForwarder_staging` or `bitcoin_api_e_emailDeliveryResultsForwarder`. On creation, give it a nickname `s_ba_email` or `p_ba_email` (this is optional, you can give it another nickname if you want😃🤠). You can create and configure your SNS topics in the [AWS SNS browser console](https://console.aws.amazon.com/sns/v3/home#/dashboard).\n\nFor the SNS topic you've just created, attach your `bitcoin_api_lambda_eService_handleEEDRs_staging` or `bitcoin_api_lambda_eService_handleEEDRs` Lambda function as a subscriber.\n\nNow, back in your [AWS SES browser console](https://console.aws.amazon.com/ses/home), go to your email's or your domain's settings.  In the settings, go to the notifications section and click \"Edit configuration\". In the \"SNS Topic Configuration\" settings, for `Bounces`, `Complaints`, and `Deliveries` choose `bitcoin_api_e_emailDeliveryResultsForwarder_staging` or `bitcoin_api_e_emailDeliveryResultsForwarder`. Leave the \"Include original headers\" checkbox unchecked. Press \"Save Config\" after.\n\nIn your API's .env file, your `EXCHANGE_MANAGEMENT_EMAIL` environment variable must be set to your verified SES's email used to send emails for your exchange.\n\n**Set Up API Gateway HTTP API**\n\nFor the Bitcoin-API exchange API, just repeat creating an HTTP API in the same way you created the [core HTTP API](#api-gateway-set-up) except using the exchange Lambda functions. You can name it `bitcoin_api_exchange_api_staging` or `bitcoin_api_exchange_api`.\n\n#### Deploy API Demo Video\n\nHere is an example video of a live production API deployment. Updated website contents are retrieved using a newly deployed [AWS Lambda](https://aws.amazon.com/lambda) function:\n\n\u003ca href=\"https://www.youtube.com/watch?v=8FCWWAyXB8A\"\u003e\n    \u003cimg\n        src=\"https://bitcoin-api.s3.amazonaws.com/documents/open-source/bitcoin-api-full-stack/youtube-logo-2.png\"\n        width=\"85\"\n    /\u003e\n\u003c/a\u003e\n\n\n### How to Deploy Frontend\n\nThe frontend code modules are [React](https://reactjs.org) webapps made with [Create React App](https://reactjs.org/docs/create-a-new-react-app.html). They can be deployed in the same way as any other React webapp.\n\n---\n\n### Contribute\n\nBitcoin-API-Full-Stack is open source. Pull requests, GitHub issues, or any other feedback or suggestions are welcome and are greatly appreciated.\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbitcoin-api%2Fbitcoin-api-full-stack","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbitcoin-api%2Fbitcoin-api-full-stack","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbitcoin-api%2Fbitcoin-api-full-stack/lists"}