区块链研习社互联网科技区块链大学

使用 EOS Dfuse API 获取智能合约 ABI 数据 -

2019-08-17  本文已影响10人  极客红石

简介:Dfuse 是 EOS Canada 推出的针对 EOS 开发者的 WebSocket 和 REST API,同时支持主网、测试网络和 CryptoKylin 网络。本文整理了通过 Dfuse API 获取智能合约 ABI 数据的详情。

Dfuse 是 EOS Canada 推出的针对 EOS 开发者的 WebSocket 和 REST API,同时支持主网、测试网络和 CryptoKylin 网络。本文整理了通过Dfuse API 获取智能合约 ABI 数据的详情。

使用 Dfuse API 需注册申请 api key(可免费申请),并通过 api key 获取 jwt token.

通过 api key 获取 jwt token 的 Node.js 代码示例:

const fetch = require('node-fetch');

fetch('https://auth.dfuse.io/v1/auth/issue?', {
    method: 'post',
    body: JSON.stringify({ api_key:'{这里放你的 `api key`}'})
}).then(response => response.json()
    .then(data => console.log(data.token)));

接口地址:

mainnet.eos.dfuse.io

请求示例:

以获取 eosio.token 合约 ABI 为例:

Node.js 代码示例:

const fetch = require('node-fetch');

fetch('https://mainnet.eos.dfuse.io/v0/state/abi?&' +
    'token={JWT Token}' +
    '&account=eosio.token&' +
    'json=true', {
    method: 'get',
}).then(response => response.json()
    .then(data => console.log(data)));

返回 JSON 示例:

{
  "block_num": 54674487,
  "account": "eosio.token",
  "abi": {
    "version": "eosio::abi/1.1",
    "structs": [
      {
        "name": "account",
        "base": "",
        "fields": [
          {
            "name": "balance",
            "type": "asset"
          }
        ]
      },
      {
        "name": "close",
        "base": "",
        "fields": [
          {
            "name": "owner",
            "type": "name"
          },
          {
            "name": "symbol",
            "type": "symbol"
          }
        ]
      },
      {
        "name": "create",
        "base": "",
        "fields": [
          {
            "name": "issuer",
            "type": "name"
          },
          {
            "name": "maximum_supply",
            "type": "asset"
          }
        ]
      },
      {
        "name": "currency_stats",
        "base": "",
        "fields": [
          {
            "name": "supply",
            "type": "asset"
          },
          {
            "name": "max_supply",
            "type": "asset"
          },
          {
            "name": "issuer",
            "type": "name"
          }
        ]
      },
      {
        "name": "issue",
        "base": "",
        "fields": [
          {
            "name": "to",
            "type": "name"
          },
          {
            "name": "quantity",
            "type": "asset"
          },
          {
            "name": "memo",
            "type": "string"
          }
        ]
      },
      {
        "name": "open",
        "base": "",
        "fields": [
          {
            "name": "owner",
            "type": "name"
          },
          {
            "name": "symbol",
            "type": "symbol"
          },
          {
            "name": "ram_payer",
            "type": "name"
          }
        ]
      },
      {
        "name": "retire",
        "base": "",
        "fields": [
          {
            "name": "quantity",
            "type": "asset"
          },
          {
            "name": "memo",
            "type": "string"
          }
        ]
      },
      {
        "name": "transfer",
        "base": "",
        "fields": [
          {
            "name": "from",
            "type": "name"
          },
          {
            "name": "to",
            "type": "name"
          },
          {
            "name": "quantity",
            "type": "asset"
          },
          {
            "name": "memo",
            "type": "string"
          }
        ]
      }
    ],
    "actions": [
      {
        "name": "close",
        "type": "close",
        "ricardian_contract": ""
      },
      {
        "name": "create",
        "type": "create",
        "ricardian_contract": ""
      },
      {
        "name": "issue",
        "type": "issue",
        "ricardian_contract": ""
      },
      {
        "name": "open",
        "type": "open",
        "ricardian_contract": ""
      },
      {
        "name": "retire",
        "type": "retire",
        "ricardian_contract": ""
      },
      {
        "name": "transfer",
        "type": "transfer",
        "ricardian_contract": "## Transfer Terms & Conditions\n\nI, {{from}}, certify the following to be true to the best of my knowledge:\n\n1. I certify that {{quantity}} is not the proceeds of fraudulent or violent activities.\n2. I certify that, to the best of my knowledge, {{to}} is not supporting initiation of violence against others.\n3. I have disclosed any contractual terms & conditions with respect to {{quantity}} to {{to}}.\n\nI understand that funds transfers are not reversible after the {{transaction.delay}} seconds or other delay as configured by {{from}}'s permissions.\n\nIf this action fails to be irreversibly confirmed after receiving goods or services from '{{to}}', I agree to either return the goods or services or resend {{quantity}} in a timely manner.\n"
      }
    ],
    "tables": [
      {
        "name": "accounts",
        "index_type": "i64",
        "type": "account"
      },
      {
        "name": "stat",
        "index_type": "i64",
        "type": "currency_stats"
      }
    ]
  }
}

Dfuse 接口官方文档:https://docs.dfuse.io

Dfuse API 思维导图:

Dfuse.png

我们有一个区块链知识星球,做区块链前沿资料的归纳整理以方便大家检索查询使用,也是国内顶尖区块链技术社区,欢迎感兴趣的朋友加入。如果你对上面内容有疑问,也可以加入知识星球提问我:

image
上一篇下一篇

猜你喜欢

热点阅读