领取测试LAT的新方案

加入浅浅社区Discord

使用机器人,并填写你的小狐狸地址

image

回车即可领取测试LAT,如果指令失效,请升级到最新版Discord!

备注:我已经往水龙头充值50万LAT,短时间内是够的,每次指令可以获得20测试LAT。


实现方案

  • 第一步:有一个PlatON(或其他兼容EVM)的测试节点【这里主要是保护RPC端口不被外部用户访问和使用】

  • 第二步:云服务器安装以下依赖包

4fd3bfb4aaf587f73a8daace3be4c182_

  • 第三步:水龙头地址需要在对应测试节点的RPC上解锁账号unlockAccount()

  • 第四步:开发机器人,源码如下

deploy-commands.js文件

const { SlashCommandBuilder } = require('@discordjs/builders');
const { REST } = require('@discordjs/rest');
const { Routes } = require('discord-api-types/v9');
const { clientId, guildId, token } = require('./config.json');

const commands = [
	new SlashCommandBuilder().setName('faucet').setDescription('PlatON测试水龙头')
    .addStringOption(option =>
        option.setName('platondev').setDescription('请输入PlatON的0x地址').setRequired(true)
    ),
]
	.map(command => command.toJSON());

const rest = new REST({ version: '9' }).setToken(token);

rest.put(Routes.applicationGuildCommands(clientId, guildId), { body: commands })
	.then(() => console.log('Successfully registered application commands.'))
	.catch(console.error);

faucet.js文件

// Require the necessary discord.js classes
const { Collection, Client, Formatters, Intents } = require('discord.js');
var Web3 = require('web3');
var web3 = new Web3('测试节点RPC地址');
const { token } = require('./config.json');

// Create a new client instance
const client = new Client({ intents: [Intents.FLAGS.GUILDS, Intents.FLAGS.GUILD_MESSAGES] });

// When the client is ready, run this code (only once)
client.once('ready', () => {
	console.log('Ready!');
});

client.on('interactionCreate', async interaction => {
	if (!interaction.isCommand()) return;

	const { commandName } = interaction;

	if (commandName === 'faucet') {
		const address = interaction.options.getString('platondev');
		if(address.substring(0,2)=='0x'&&address.length==42){
			web3.eth.sendTransaction({
				from: 'PlatON水龙头地址',
				to: address,
				value: '20000000000000000000'
			})
			.then(function(receipt){
				console.log(receipt);
			});
			return interaction.reply(`测试LAT已发送到您的地址,请查收!`)
		}else{
			return interaction.reply(`请检查您的地址是否正确!请务必填写 0x 地址!`);
		}
        
	}
});
// Login to Discord with your client's token
client.login(token);

config.json

{
	"token": "机器人私钥",
	"clientId": "机器人ApplicationId",
	"guildId": "Discord服务器Id"
}

最后使用forever做进程守护!