🛰 A Serverless Discord bot for Ethereum authentication.
A Discord bot that enables you to authenticate users with Ethereum. The infrastructure is fully serverless and based on AWS Lambda.
The bot is based on:
If you find this repository useful, any ETH, NFT, or other tokens are greatly appreciated.
ETH Address: 0xa8624937a437F53382d4B48f1AE13E0CF5C9F8cB
.aws/credentials
with the same structure as .aws/credentials.example
(including the "[scaffold-eth]" part), and fill in the parameters aws_access_key_id
and aws_secret_access_key
with the values you obtained from the previous step.All the secrets necessary for the bot to run are retrieved from an AWS Secrets Manager secret named /dev/serverless_discord_bot/discord
you have to create that secret manually before deploying the stack. When creating the secret choose the option Other type of secrets.
The secret must contain the following key/value pairs:
app_id
, from the application you've created in the Discord Setup.public_key
, from the application you've created in the Discord Setup.bot_token
, from the application you've created in the Discord Setup.server_id
- Right-click your server on Discord and select Copy ID to get this.channel_id
. Right-click your channel on Discord and select Copy ID to get this.role_id
. Right-click the role you've created in the Discord setup and select Copy ID to get this. You can see your server's roles by right-clicking your server > Server Settings > Roles.jwt_secret
. This is the secret which will be used to encode/decode the authentication JWTs. Anything works here, but choose something strong enough.We'll now go through the deployment of the infrastructure responsible for interacting with Discord. This includes creating the slash-command and handling the role assignment when a user is successfuly authenticated.
cd
into packages/discord-interaction/src/commands_layer/nodejs and install the layer dependencies using npm install
. This is the only install required for this infrastructure. The rest is auto-installed by SAM.
cd
back into packages/discord-interaction/ and do sam build
. Once the build is complete do sam deploy --guided
and choose the following parameters:
Stack Name [dev-discord-interaction]: dev-discord-interaction
AWS Region [us-east-2]: us-east-2
#Shows you resources changes to be deployed and require a 'Y' to initiate deploy
Confirm changes before deploy [y/N]: n
#SAM needs permission to be able to create roles to connect to the resources in your template
Allow SAM CLI IAM role creation [Y/n]: y
DiscordHandlerFunction may not have authorization defined, Is this okay? [y/N]: y
Save arguments to configuration file [Y/n]: y
SAM configuration file [samconfig.toml]: samconfig.toml
SAM configuration environment [default]: default
Once the deployment is complete copy the API Gateway endpoint URL stack output and paste it in the Discord Developer Portal as Interactions Endpoint URL. If Discord was able to successfuly ping our Lambda you'll get a message saying "All your edits have been carefully recorded" at the top of the screen.
Check that you now have a stack called dev-discord-interaction in Cloudformation. Cross your fingers 🤞 and call the command /eth-auth
in your Discord channel. If everything went right with the deploy, the bot should respond with a URL.
Now let's deploy the API that will talk to the front-end and handle the Ethereum authentication flow.
yarn install
. You'll get quite a lot of warnings regarding workspace dependencies, but those are harmless. Note: All the packages for this infrastructure (and also for the front-end and the chain) are installed through yarn
workspaces. The api package dependencies will later be installed using npm
.cd
into packages/serverless-infrastructure and run npm run deploy
. After this runs, you should now have a stack called dev-scaffold-eth-infra-dynamodb in Cloudformation.cd
into packages/api and install the dependencies using npm install
.npx serverless create_domain
.npm run deploy
.In the root folder run in two separate command prompts:
yarn react-app:start
to start the local react app server.yarn chain
to start the local chain server. Note: This example runs with a local chain, but you can set the chain to whatever you want. Just edit the variable targetNetwork in packages/react-app/src/App.jsx to change to a different chain.Once the the local react app and chain servers are ready all is set up to try the bot.
/eth-auth
in the channel.server_id
and channel_id
, and make them dynamic depending on the server the bot is responding to.