forked from kenryu42/ethereum-nft-sales-bot
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 47f4181
Showing
25 changed files
with
13,311 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
{ | ||
"env": { | ||
"node": true, | ||
"mocha": true, | ||
"es2021": true | ||
}, | ||
"extends": ["eslint:recommended", "prettier"], | ||
"parserOptions": { | ||
"ecmaVersion": "latest", | ||
"sourceType": "module" | ||
}, | ||
"rules": { | ||
"indent": [ | ||
"error", | ||
"tab" | ||
], | ||
"linebreak-style": [ | ||
"error", | ||
"unix" | ||
], | ||
"quotes": [ | ||
"error", | ||
"single" | ||
], | ||
"semi": [ | ||
"error", | ||
"always" | ||
] | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
name: 'run-tests' | ||
on: | ||
pull_request: | ||
push: | ||
branches: | ||
- main | ||
- 'releases/*' | ||
|
||
jobs: | ||
tests: | ||
runs-on: ubuntu-latest | ||
|
||
strategy: | ||
matrix: | ||
node-version: [16.x] | ||
|
||
steps: | ||
- uses: actions/checkout@v3 | ||
- run: echo $ENV_FILE | base64 -d > .env | ||
env: | ||
ENV_FILE: ${{ secrets.ENV_FILE }} | ||
- name: Use Node.js ${{ matrix.node-version }} | ||
uses: actions/setup-node@v3 | ||
with: | ||
node-version: ${{ matrix.node-version }} | ||
cache: 'npm' | ||
- run: npm ci | ||
- run: npm test |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
node_modules/ | ||
.env | ||
.DS_Store |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ | ||
"semi": true, | ||
"trailingComma": "none", | ||
"singleQuote": true, | ||
"printWidth": 80, | ||
"useTabs": true | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
MIT License | ||
|
||
Copyright (c) 2022 kenryu42 | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,129 @@ | ||
## Ethereum NFT Sales Bot | ||
|
||
NFT sales monitoring bot of the Ethereum blockchain. (ERC721, ERC1155) | ||
|
||
## Market Coverage | ||
|
||
- [Opensea](https://opensea.io/) | ||
<img src="https://pbs.twimg.com/profile_images/1533843334946508806/kleAruEh_400x400.png" width="11"/> | ||
(Wyvren & Seaport) | ||
|
||
- [Looksrare](https://looksrare.org/) | ||
<img src="https://pbs.twimg.com/profile_images/1493172984240308225/Nt6RFdmb_400x400.jpg" width="11"/> | ||
|
||
- [X2Y2](https://x2y2.io/) | ||
<img src="https://pbs.twimg.com/profile_images/1482386069891198978/mMFwXNj8_400x400.jpg" width="11"/> | ||
|
||
- [Gem](https://gem.xyz/) | ||
<img src="https://pbs.twimg.com/profile_images/1469735318488293380/AuOdfwvH_400x400.jpg" width="11"/> | ||
|
||
- [Genie](https://www.genie.xyz/) | ||
<img src="https://pbs.twimg.com/profile_images/1486044157017788419/cqdhpZBX_400x400.png" width="11"/> | ||
|
||
## GIF Generator for Bundle Sale | ||
|
||
<img src="https://media2.giphy.com/media/sjKGGbK6CnM3AnJZ25/giphy.gif?cid=790b76110714c67c573d4cc5887b69aa0074c0b663666fbf&rid=giphy.gif&ct=g" /> | ||
|
||
<br/> | ||
|
||
## Prerequisites | ||
|
||
- Opensea API Key - [apply here](https://docs.opensea.io/reference/request-an-api-key) | ||
- Alchemy API Key - [apply here](https://auth.alchemyapi.io/signup) | ||
- Etherscan API Key - [apply here](https://etherscan.io/register) | ||
|
||
## Notify Method | ||
|
||
|
||
- Discord | ||
|
||
Notification is optional. You can turn it on or off in the configuration file. (`config/setup.js`) | ||
|
||
## Twitter Guide | ||
|
||
1. Register Twitter developer account with Elevated access. [🔗 Link](https://developer.twitter.com/en/portal/petition/essential/basic-info) | ||
2. Create a development app with OAuth 1.0a read-write permissions. [🔗 Link](https://developer.twitter.com/en/docs/apps/app-permissions) | ||
3. Install [Twurl](https://github.com/twitter/twurl) and run following command: | ||
|
||
``` | ||
twurl authorize --consumer-key <your-app-key> --consumer-secret <your-app-secret> | ||
``` | ||
|
||
This will return an URL that you should open up in your browser. Authenticate to Twitter, and then enter the returned PIN back into the terminal. | ||
|
||
This should create a file called `.twurlrc` in your home directory with all the necessary information. | ||
|
||
## Discord Guide | ||
|
||
1. Open the Discord channel you want to receive sales event notifications. | ||
2. From the channel menu, select **Edit channel**. | ||
3. Select **Integrations**. | ||
4. Select **Create Webhook**. | ||
5. Enter the name of the bot that will post the message. | ||
6. Copy the URL from the **WEBHOOK URL** field. | ||
7. Click **Save**. | ||
|
||
## Configuration | ||
|
||
> Create an `.env` file in the root directory of the project with the following contents: | ||
``` | ||
CONTRACT_ADDRESS= | ||
OPENSEA_API_KEY= | ||
ALCHEMY_API_KEY= | ||
ETHERSCAN_API_KEY= | ||
TWITTER_API_KEY= | ||
TWITTER_API_SECRET= | ||
TWITTER_ACCESS_TOKEN= | ||
TWITTER_ACCESS_SECRET= | ||
WEBHOOK_URL= | ||
``` | ||
|
||
**Do not commit/include your .env file in your repository.** | ||
|
||
## Installation | ||
|
||
```bash | ||
npm install | ||
``` | ||
|
||
## Run Test | ||
|
||
To ensure your configuration(`.env`) is correct, run the following command: | ||
|
||
```bash | ||
npm test | ||
``` | ||
|
||
The test should take less than a minute to run. If it fails, please check your configuration. | ||
|
||
## Usage | ||
|
||
Run the following command to start the bot: | ||
|
||
```bash | ||
node app.js | ||
``` | ||
|
||
To test a certain transaction for debugging purposes, run the following command: | ||
|
||
``` | ||
node app.js -t <transaction hash> | ||
``` | ||
|
||
## Contributing | ||
|
||
Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change. | ||
|
||
Please make sure to update tests as appropriate. | ||
|
||
## Credits | ||
|
||
**Daniel Griffin** @dsgriffin | ||
|
||
[NFT Sales Twitter Bot](https://github.com/dsgriffin/nft-sales-twitter-bot) | ||
|
||
## LICENSE | ||
|
||
This project is [MIT](https://github.com/kenryu42/ethereum-nft-sales-bot/blob/main/LICENSE) licensed. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
import { runApp } from './controllers/runApp.js'; | ||
import { WEB3, CONTRACT, CONTRACT_ADDRESS } from './config/setup.js'; | ||
import { options } from './config/commander.js'; | ||
import { getContractData } from './utils/api.js'; | ||
|
||
let lastTransactionHash; | ||
|
||
async function main() { | ||
const contractData = await getContractData(); | ||
const collectionName = contractData.collection.name; | ||
const tokenType = contractData.schema_name; | ||
|
||
const transferEvent = | ||
tokenType === 'ERC721' | ||
? CONTRACT.events.Transfer({}) | ||
: CONTRACT.events.TransferSingle({}); | ||
|
||
transferEvent | ||
.on('connected', (subscription_id) => { | ||
console.log(new Date().toString(), '\n'); | ||
console.log('Subscription successfully connected.'); | ||
console.log(`Subscription ID: ${subscription_id}\n`); | ||
console.log( | ||
`Listening to ${tokenType} sale events on collection: ${collectionName}` | ||
); | ||
console.log(`Contract address: ${CONTRACT._address}\n`); | ||
}) | ||
.on('data', async (data) => { | ||
const transactionHash = data.transactionHash.toLowerCase(); | ||
|
||
if (transactionHash == lastTransactionHash) return; | ||
lastTransactionHash = transactionHash; | ||
|
||
await runApp(WEB3, transactionHash, CONTRACT_ADDRESS, tokenType); | ||
}) | ||
.on('error', (error, receipt) => { | ||
console.error(error); | ||
console.error(receipt); | ||
}); | ||
} | ||
|
||
(async () => { | ||
if (options.test) { | ||
try { | ||
const contractData = await getContractData(); | ||
// const contractName = contractData.name; | ||
const tokenType = contractData.schema_name; | ||
console.log(`Running test for tx: ${options.test}`); | ||
await runApp(WEB3, options.test, CONTRACT_ADDRESS, tokenType); | ||
WEB3.currentProvider.disconnect(); | ||
} catch (error) { | ||
console.error(error); | ||
process.exit(1); | ||
} | ||
} else { | ||
try { | ||
await main(); | ||
} catch (error) { | ||
console.error(error); | ||
process.exit(1); | ||
} | ||
} | ||
})(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
[ | ||
{ | ||
"anonymous": false, | ||
"inputs": [ | ||
{ | ||
"indexed": true, | ||
"internalType": "address", | ||
"name": "from", | ||
"type": "address" | ||
}, | ||
{ | ||
"indexed": true, | ||
"internalType": "address", | ||
"name": "to", | ||
"type": "address" | ||
}, | ||
{ | ||
"indexed": true, | ||
"internalType": "uint256", | ||
"name": "tokenId", | ||
"type": "uint256" | ||
} | ||
], | ||
"name": "Transfer", | ||
"type": "event" | ||
}, | ||
{ | ||
"anonymous": false, | ||
"inputs": [ | ||
{ | ||
"indexed": true, | ||
"internalType": "address", | ||
"name": "operator", | ||
"type": "address" | ||
}, | ||
{ | ||
"indexed": true, | ||
"internalType": "address", | ||
"name": "from", | ||
"type": "address" | ||
}, | ||
{ | ||
"indexed": true, | ||
"internalType": "address", | ||
"name": "to", | ||
"type": "address" | ||
}, | ||
{ | ||
"indexed": false, | ||
"internalType": "uint256", | ||
"name": "id", | ||
"type": "uint256" | ||
}, | ||
{ | ||
"indexed": false, | ||
"internalType": "uint256", | ||
"name": "value", | ||
"type": "uint256" | ||
} | ||
], | ||
"name": "TransferSingle", | ||
"type": "event" | ||
} | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import { Command } from 'commander'; | ||
|
||
const program = new Command(); | ||
|
||
program.name('app.js').description('CLI to NFT sales bot').version('0.1.0'); | ||
|
||
program.option( | ||
'-t, --test <tx>', | ||
'test by running the app for the given transaction hash' | ||
); | ||
|
||
program.parse(); | ||
|
||
export const options = program.opts(); |
Oops, something went wrong.