2
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Python3でNEMのAPIを叩く-007-アカウントが作成したモザイク定義を取得<コーディング編>

Last updated at Posted at 2018-03-18

#はじめに
前回は事前準備としてモザイクを定義しました。
今回では、そのモザイク定義をAPIを使って取得します。

#使うAPI
/account/mosaic/definition/page を使用します。

スクリーンショット 2018-03-19 0.54.30.png
(解説:和訳)https://www.pr1sm.com/crypto-coin/nem-nis-api-documentation-in-japanese/#retrieving-mosaic-definitions-that-an-account-has-created

スクリーンショット 2018-03-19 0.56.44.png
(解説:本家)https://nemproject.github.io/#retrieving-mosaic-definitions-that-an-account-has-created

#サンプル
##コード
実行環境が無い方はpaizaで試せます。
https://paiza.io/ja

Python3
import requests
import json

node = 'http://50.3.87.123:7890'    # テストネットのノード
api = '/account/mosaic/definition/page'
parameter = 'address=TCJC5VFBIYF5TKEUS273XS7IXUKJ36I3JCJQ7WOH'
url = str(node + api + '?' + parameter)

r = requests.get(url).json()

print(json.dumps(r,indent=4))

##結果の例

json
{
    "data": [
        {
            "id": {
                "name": "tamago",
                "namespaceId": "oden"
            },
            "levy": {},
            "properties": [
                {
                    "name": "divisibility",
                    "value": "6"
                },
                {
                    "name": "initialSupply",
                    "value": "9000000000"
                },
                {
                    "name": "supplyMutable",
                    "value": "true"
                },
                {
                    "name": "transferable",
                    "value": "true"
                }
            ],
            "creator": "756317d797f742b695cece76aa74ecd47305b48d5158c6dab44a48592de0325e",
            "description": "\u304a\u3067\u3093\u306e\u5b9a\u756a\u3002tamago\u3067\u3059\u3002\u304a\u3067\u3093\u306e\u51fa\u6c41\u3092\u5438\u3044\u53d6\u3063\u3066\u30a6\u30de\u30a6\u30de\u3067\u3059\uff01"
        }
    ]
}

##解説
前回作成したネームスペースodenのモザイクtamagoの定義が返ってきていますね。
propertiesがNano Walletで見たとき、下図になります。

json
            "properties": [
                {
                    "name": "divisibility",
                    "value": "6"
                },
                {
                    "name": "initialSupply",
                    "value": "9000000000"
                },
                {
                    "name": "supplyMutable",
                    "value": "true"
                },
                {
                    "name": "transferable",
                    "value": "true"
                }
            ],

スクリーンショット 2018-03-19 1.08.01.png

#次回
Python3でNEMのAPIを叩く-008-[最終回]アカウントのトランザクションデータを取得する

2
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?