Nao-KM
    • Create new note
    • Create a note from template
      • Sharing URL Link copied
      • /edit
      • View mode
        • Edit mode
        • View mode
        • Book mode
        • Slide mode
        Edit mode View mode Book mode Slide mode
      • Customize slides
      • Note Permission
      • Read
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Write
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Engagement control Commenting, Suggest edit, Emoji Reply
      • Invitee
    • Publish Note

      Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

      Your note will be visible on your profile and discoverable by anyone.
      Your note is now live.
      This note is visible on your profile and discoverable online.
      Everyone on the web can find and read all notes of this public team.
      See published notes
      Unpublish note
      Please check the box to agree to the Community Guidelines.
      View profile
    • Commenting
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
      • Everyone
    • Suggest edit
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
    • Emoji Reply
    • Enable
    • Versions and GitHub Sync
    • Note settings
    • Engagement control
    • Transfer ownership
    • Delete this note
    • Save as template
    • Insert from template
    • Import from
      • Dropbox
      • Google Drive
      • Gist
      • Clipboard
    • Export to
      • Dropbox
      • Google Drive
      • Gist
    • Download
      • Markdown
      • HTML
      • Raw HTML
Menu Note settings Sharing URL Create Help
Create Create new note Create a note from template
Menu
Options
Versions and GitHub Sync Engagement control Transfer ownership Delete this note
Import from
Dropbox Google Drive Gist Clipboard
Export to
Dropbox Google Drive Gist
Download
Markdown HTML Raw HTML
Back
Sharing URL Link copied
/edit
View mode
  • Edit mode
  • View mode
  • Book mode
  • Slide mode
Edit mode View mode Book mode Slide mode
Customize slides
Note Permission
Read
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Write
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Engagement control Commenting, Suggest edit, Emoji Reply
Invitee
Publish Note

Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

Your note will be visible on your profile and discoverable by anyone.
Your note is now live.
This note is visible on your profile and discoverable online.
Everyone on the web can find and read all notes of this public team.
See published notes
Unpublish note
Please check the box to agree to the Community Guidelines.
View profile
Engagement control
Commenting
Permission
Disabled Forbidden Owners Signed-in users Everyone
Enable
Permission
  • Forbidden
  • Owners
  • Signed-in users
  • Everyone
Suggest edit
Permission
Disabled Forbidden Owners Signed-in users Everyone
Enable
Permission
  • Forbidden
  • Owners
  • Signed-in users
Emoji Reply
Enable
Import from Dropbox Google Drive Gist Clipboard
   owned this note    owned this note      
Published Linked with GitHub
Subscribed
  • Any changes
    Be notified of any changes
  • Mention me
    Be notified of mention me
  • Unsubscribe
Subscribe
# 如何为 Matataki 开发一个第三方 Fan票 空投应用? 前段时间,Matataki 开放了自己的 [API 文档](https://docs.matataki.io/),虽然这份文档看起来还很不完善[^1],不过不妨害先实现一些 [简单的应用场景](https://www.matataki.io/p/4292)。根据 Joel Monegro 的理论:Information Capital is more valuable when distributed[^2],不妨我们先实现空投。 通过本文,你可以了解到: - Matataki API 简介 - 基于 React 开发 Dapp 的前端 - 基于 Nest.js 开发 Dapp 的后端 目前的前端 👉 [GitHub Repo](https://github.com/NaoMikuOshi/Matataki-Token-AirDropper) 和后端 👉 [GitHub Repo](https) Demo: - 生产版 https://matataki-airdrop.netlify.app/ - 测试版(基于 Matataki 测试版) https://matataki-airdrop-testing.netlify.app/ [^1]: > ⚠️警告⚠️ > 与其他成熟的平台不同,你通过 API 获取的用户 `accessToken` 目前是和 Matataki.io 上的用户服务令牌是一样的。获取到用户 `accessToken` 即意味着你是在以用户本人的名义作出 API 操作! > 个人看法是,Matataki 如果真的要做 Dapp,OAuth 和权限控制是必须要做的 > [OAuth in one picture](https://twitter.com/kamranahmedse/status/1276994010423361540) > [name=NaoMiku] [^2]: [WTF is Capital: How to Fix Capitalism, Joel Monegro](https://github.com/carboclan/pm/blob/master/notes/MacroWTF_Archive.md) # 目录 [toc] # Step 1 查阅文档 这些 API 是 Matataki 官方给第三方开发者开放的,你可以通过 API 进行 Fan票的操作(查询、转账等),作为一个需要用户使用的 Dapp,你需要有用户的 `accessToken`。目前 Matataki 给第三方 App 提供的只有通过邮箱、密码登录来获得 `accessToken`。 # Step 2 前端 Connect to Matataki 以前端常用的请求库 axios 配合 React 为例,来举例: {%gist NaoMikuOshi/9ce6febc5a7fe4a1fc4f4e17a81ac2d1%} 然后你就可以利用这个 `client` 去写函数了,以和用户模组为例 {%gist NaoMikuOshi/90d0c8777dddfb62dfdf3f9a4ce7e5be%} # Step 3 建设一个后端(可选) > 这里加可选的话,更像是一个 general 的 dapp 开发指南。这篇我们只要介绍 airdroper 本身感觉就好。 > [name=xiaodao] 如果你要做一些更高级的功能,可能 Matataki 现有的 API 不能满足仅在前端开发的需求。这时候就需要你自己去搭建一个后端。这里以 Nest.js + TypeScript 为例。 ## Setup Nest 使用 Nest CLI 创建 Nest 项目非常简单. 只需要有 npm 就可以执行以下命令: ```bash npm i -g @nestjs/cli nest new project-name ``` 后续就是配置你的后端了,这里不再过多赘述,详细可以查阅 [Nest 的文档(英文)](https://docs.nestjs.com/first-steps) 或 [Nest 的文档(中文)](https://docs.nestjs.cn/7/firststeps) 。 ## 设置一个中间账户 我们 AirDropper 是一个代币空投的工具,如果使用用户的账户来进行操作存在安全风险。所以我们还得去 Matataki 注册一个账户,给我们的后端使用。 在项目保存私密数据的最佳实践是你把敏感的内容放进环境变量里。node 一般都使用 `dotenv` 作为文件 =输入=> 环境变量的最佳工具。 ```bash # 空投中转账号 TEMP_ACCOUNT=just_airdrop@foo.bar TEMP_PASSWORD=foooobbbbbaaaarrrrr TEMP_UID=114514 ``` 这样我们的后端可以从 `process.env.[环境变量]` 来读取到敏感的数据。 ## 创建Airdrop 的实现 {%gist NaoMikuOshi/38efc2ce7cda7a3a8a5c97ac40d7f16a %} 首先用用户的 `accessToken` 来转账到我们的临时账户,然后再去 DB 创建对象。 {%gist NaoMikuOshi/e1173e93f53fc3f30baec95ba5ca536b %} # Step 4 空投的扩展 —— 手气红包 > // @todo, 争取先让后端也 deploy 上公网,后续再做这个 > [name=NaoMiku] # 致谢 感谢Matataki 团队的 小岛、@zxplus @Neko 和 @Frank 对AirDrop项目的支持

Import from clipboard

Paste your markdown or webpage here...

Advanced permission required

Your current role can only read. Ask the system administrator to acquire write and comment permission.

This team is disabled

Sorry, this team is disabled. You can't edit this note.

This note is locked

Sorry, only owner can edit this note.

Reach the limit

Sorry, you've reached the max length this note can be.
Please reduce the content or divide it to more notes, thank you!

Import from Gist

Import from Snippet

or

Export to Snippet

Are you sure?

Do you really want to delete this note?
All users will lose their connection.

Create a note from template

Create a note from template

Oops...
This template has been removed or transferred.
Upgrade
All
  • All
  • Team
No template.

Create a template

Upgrade

Delete template

Do you really want to delete this template?
Turn this template into a regular note and keep its content, versions, and comments.

This page need refresh

You have an incompatible client version.
Refresh to update.
New version available!
See releases notes here
Refresh to enjoy new features.
Your user state has changed.
Refresh to load new user state.

Sign in

Forgot password

or

By clicking below, you agree to our terms of service.

Sign in via Facebook Sign in via Twitter Sign in via GitHub Sign in via Dropbox Sign in with Wallet
Wallet ( )
Connect another wallet

New to HackMD? Sign up

Help

  • English
  • 中文
  • Français
  • Deutsch
  • 日本語
  • Español
  • Català
  • Ελληνικά
  • Português
  • italiano
  • Türkçe
  • Русский
  • Nederlands
  • hrvatski jezik
  • język polski
  • Українська
  • हिन्दी
  • svenska
  • Esperanto
  • dansk

Documents

Help & Tutorial

How to use Book mode

Slide Example

API Docs

Edit in VSCode

Install browser extension

Contacts

Feedback

Discord

Send us email

Resources

Releases

Pricing

Blog

Policy

Terms

Privacy

Cheatsheet

Syntax Example Reference
# Header Header 基本排版
- Unordered List
  • Unordered List
1. Ordered List
  1. Ordered List
- [ ] Todo List
  • Todo List
> Blockquote
Blockquote
**Bold font** Bold font
*Italics font* Italics font
~~Strikethrough~~ Strikethrough
19^th^ 19th
H~2~O H2O
++Inserted text++ Inserted text
==Marked text== Marked text
[link text](https:// "title") Link
![image alt](https:// "title") Image
`Code` Code 在筆記中貼入程式碼
```javascript
var i = 0;
```
var i = 0;
:smile: :smile: Emoji list
{%youtube youtube_id %} Externals
$L^aT_eX$ LaTeX
:::info
This is a alert area.
:::

This is a alert area.

Versions and GitHub Sync
Get Full History Access

  • Edit version name
  • Delete

revision author avatar     named on  

More Less

Note content is identical to the latest version.
Compare
    Choose a version
    No search result
    Version not found
Sign in to link this note to GitHub
Learn more
This note is not linked with GitHub
 

Feedback

Submission failed, please try again

Thanks for your support.

On a scale of 0-10, how likely is it that you would recommend HackMD to your friends, family or business associates?

Please give us some advice and help us improve HackMD.

 

Thanks for your feedback

Remove version name

Do you want to remove this version name and description?

Transfer ownership

Transfer to
    Warning: is a public team. If you transfer note to this team, everyone on the web can find and read this note.

      Link with GitHub

      Please authorize HackMD on GitHub
      • Please sign in to GitHub and install the HackMD app on your GitHub repo.
      • HackMD links with GitHub through a GitHub App. You can choose which repo to install our App.
      Learn more  Sign in to GitHub

      Push the note to GitHub Push to GitHub Pull a file from GitHub

        Authorize again
       

      Choose which file to push to

      Select repo
      Refresh Authorize more repos
      Select branch
      Select file
      Select branch
      Choose version(s) to push
      • Save a new version and push
      • Choose from existing versions
      Include title and tags
      Available push count

      Pull from GitHub

       
      File from GitHub
      File from HackMD

      GitHub Link Settings

      File linked

      Linked by
      File path
      Last synced branch
      Available push count

      Danger Zone

      Unlink
      You will no longer receive notification when GitHub file changes after unlink.

      Syncing

      Push failed

      Push successfully