Intro

Installable via npm install --save ethavatar, it can also be used directly in the browser.

Quick Example

'use strict'

// Load EthAvatar module
const EthAvatar = require('ethavatar')

// Instantiate EthAvatar with current Web3 provider and Infura IPFS API
const ethavatar = new EthAvatar()

// Get avatar of current address
ethavatar.get()
  .then((avatar) => {
    if (typeof avatar === 'undefined') {
      throw new Error('Avatar of address not set')
    } else {
      return avatar
    }

  }).then((avatar) => {
    // Load FileSystem module
    const fs = require('fs')

    // Write avatar to file
    fs.writeFile(
      'avatar.jpg',
      avatar,
      'binary',
      (err) => {
        if (err) {
          throw err
        }
      }
    )

  }).catch((error) => {
    console.error(error.message)
  })

There are more available, so take a look at the docs below for a full list. This documentation aims to be comprehensive, so if you feel anything is missing please create a GitHub issue for it.

Download

The source is available for download from GitHub. Alternatively, you can install using npm:

$ npm install --save ethavatar

You can then require() ethavatar as normal:

const ethavatar = require('ethavatar')

In the Browser

Ethavatar should work in any ES2015 environment out of the box.

Usage:

<script type="text/javascript" src="index.js"></script>

The portable versions of ethavatar, including index.js and index.min.js, are included in the /dist folder. Ethavatar can also be found on unpkg.com under

EthAvatar

src/client.js

Client class for EthAvatar.

new EthAvatar(web3Conn: object?, ipfsConn: object?, contract: string?)
Parameters
web3Conn (object? = null) Connection to Web3 provider (default is current Web3 provider).
ipfsConn (object? = null) Connection to IPFS API (default is Infura API).
contract (string? = null) Smart contract address (default is deployed address).
Instance Members
get(address = null)
set(buffer)
remove()
watch(callback?, address = null)

File helper class for EthAvatar.

new FileHelper(ethavatar: EthAvatar?)
Parameters
ethavatar (EthAvatar?) Instance of EthAvatar object.
Instance Members
toFile(filename?, address = null)
fromFile(filename?)

URL helper class for EthAvatar.

new UrlHelper(ethavatar: EthAvatar?)
Parameters
ethavatar (EthAvatar?) Instance of EthAvatar object.
Instance Members
toUrl(url?, address = null)
fromUrl(url?)