This tool aims at listening the smart contracts of https://woken.exchange/
and push notifications in Discord channels on specific events on the smart contract
You must have :
- node
- npm
installed on your host to run the app locally
To install dependencies, just run the following command :
npm install
Useful to do some tests and create LP pair
0x841699991e4129BA98385f50CDc4235CdF4A9397
0xE06B56Fc1E19402E1a9DF3513E024a3b9847c9E5
0x1da474bE245f0C3bd1eE0F9F9f9B1CC353776b46
0xd79128b22985fb7114D842b2BA419fb0794E36B1
In order to listen smart contract event, we can implements websocket.
This solution was chosen and it works on production.
The selected JS library to communicate with the blockchain is Alchemy-SDK based on the famous ethers.js library.
some steps are required to make work the bot that send notifications to the wanted Discord channel.
Create an account on Alchemy and create an app for the network you want to run the bot (Mainnet, TestNet)
After that, you can get your Alchemy key/auth token that will be used for websockets
If you want to send notifications on a specific channel in Discord, you will have to create a Webhook on this channel.
To do that, you can refer to this video : https://www.youtube.com/watch?v=fKksxz2Gdnc
After that, you will have a signed URL (URL with secret token)
which can be used to send notiifctations
Edit the .env file and fill the ALCHEMY_API_KEY key in this file
You will need to fill other required keys like DISCORD_WEBHOOK_PROPOSAL_URL that is the URL provided by Discord when you created a Webhook on a channel.
The address of your factory smart contract is required as well. Fill it in FACTORY_ADDRESS key
npm run build
npm run start:ws
You will see in the console these logs
meaning that your websockets arre listening these events and are ready to send notifications if needed !!
==> TODO later
We decided to choose the Websocket solution, so this discord notifier app will run with the following comand :
nm run start:ws
Remarks : Useful for the Solution 2 (Alchemy Notify Service) ==> Not used right now to listen smart contract !!
Once created on AWS dashboard. Connect to it with SSH
sudo su
apt install curl
curl https://raw.githubusercontent.com/creationix/nvm/master/install.sh | bash
Then
source ~/.bashrc
nvm install node
To install a specific version :
nvm install 18.16.0
apt update
then :
apt install git-all
npm install pm2 -g
git clone https://github.com/gilbruno/Woken_Discord_Bot.git
npm install
npm run build
Do it in AWS EC2 in Security Groups ==> Open protocols and ports you need (SSH, TCP, TCP Custom, etc ...)
This step is important to keep a fix IP and associate with a DNS ==> See AWS tuto for this
This step is important to do a reverse proxy from NGINX to your NodeJS App As the port 80 is the port by default of Nginx, we do not need to specify a port in the URL So the URL without port will be able to be associated to tthe port 3000 of your app
apt install nginx
then launch the elastic IP in the URL without any port (80 by default)
Ex : http://13.49.112.85/
You must see this
If you see Apache. Apache is installed by default on your server. You must uninstall it and restart Nginx
Edit the following file :
nano /etc/nginx/sites-available/default
In the location block, write this :
location / {
proxy_pass http://localhost:3000; #whatever port your app runs on
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
}
On the root line, write the directory of your NodeJS app
root /home/ubuntu/woken/Woken_Discord_Bot;
Reload configuration :
nginx -t
Restart Nginx :
service nginx restart
Now you must see the home page of your NodeJS app when launching the elastic IP of your EC2 instance in browser !! And not the homepage of Nginx !
To connect to your EC2 with SSH :
ssh -i <path_to_your_pem_file_key> ec2-user@<IP_EC2_Instance>
In this app, we only use a web hook to send notifications to a channel.
But this app can be used to implements a Discord Bot.
To do this, some steps are required in the Discord developer portal.
Anyway, a little implementation of a Discord Bot than can be logged to a server was implemented in this app.
So, we an go further to implements more complexe features with a bot.
Code is here !
Connect to the Discord Developer Portal on the URL : https://discord.com/developers.
If you have a Discord account, you will be connected with this account automatically.
Use the left menu for that
Use the left menu for that. The token will be used to login your bot to a server.
You must Grant all Privileged Gateway Intents :
- PRESENCE INTENT
- SERVER MEMBERS INTENT
- MESSAGE CONTENT INTENT
In order to do that, you will run a endpoint (HTTP Request) to add your bot to the server you want.
Even if you are not the administrator of the server.
So, you must generate the URL endpoint.
To do that, go to OAuth2 > URL Generator.
Then, in SCOPES block, select bot and in BOT PERMISSIONS BOT select Administrator.
After selecting these 2 values, the GENERATED URL appears in the bottom of the page.
Like below :
Ex : https://discord.com/api/oauth2/authorize?client_id=<My_Client_Id>&permissions=8&scope=bot
When execute this URL in a browser, the UI will suggest you all the server where you have admin role :
- on a server
- on at least one channel where you have admin roles or enough big roles.
If you choose a Discord server where you are an admin, you will get a notification to add/grant the new Bot on your server. If you choose a Discord server where you are an admin, the Discord server admn will be notified that someone wants to add a bot on his/her server. Once the bot added/granted in the server, you will be able to login your bot to this server.