Skip to main content

A python wrapper for the Molaris REST API

Project description

Introduction

A simple Python wrapper for the Molaris REST API. Useful for getting ERC-20 token prices, getting general token information and getting information about all tokens in a wallet.

Molaris

Use requires a Molaris API key which is currently available with the free Molaris service tier.

Usage

Setup

Replace YOUR_API_KEY with the Moralis API Key.

from MoralisPy import MoralisPy
moralis = MoralisPy()
moralis.set_api_key("YOUR_API_KEY")

ERC-20 Tokens

Get Token Metadata

from pprint import pprint as pp
token_address = "0x8430146cFd6F29c2B580c1004787b7d3c9F9F3b8"
pp(moralis.get_token_metadata(token_address, "avalanche"))
{'address': '0x8430146cfd6f29c2b580c1004787b7d3c9f9f3b8',
 'block_number': '8540191',
 'decimals': '18',
 'logo': None,
 'logo_hash': None,
 'name': 'VaporNodes',
 'symbol': 'VPND',
 'thumbnail': None,
 'validated': 1 }

Get Token Price

pp(moralis.get_token_price(token_address,"avalanche"))
{'exchangeAddress': '0x9ad6c38be94206ca50bb0d90783181662f0cfa10',
 'exchangeName': 'TraderJoe',
 'nativePrice': {'decimals': 18,
                 'name': 'Avalanche',
                 'symbol': 'AVAX',
                 'value': '151093980928143'},
 'usdPrice': 0.017792376973093486}

Wallets

Get information about all the ERC-20 tokens in a wallet, get the price of those tokens and calculate the total value of the wallet.

Native token prices (e.g. Eth, Avalanche etc.) are not provided by the Molaris API so aren't included in the sum

import pandas as pd
wallet = "YOUR_WALLET_ADDRESS"
erc20_assets, native_token_assets, erc20_token_assets = moralis.get_total_token_assets(wallet, ['eth','avalanche'])
erc20_df = pd.DataFrame(erc20_token_assets)
erc20_df.to_csv("erc20.csv")

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

MoralisPy-1.0.0.tar.gz (15.8 kB view hashes)

Uploaded Source

Built Distribution

MoralisPy-1.0.0-py3-none-any.whl (16.3 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page