Recommend this page to a friend!
  Classes of Filip Štamcar   EthAvatar.JS   Download  
Role: Documentation
Content type: text/markdown
Description: Documentation
Class: EthAvatar.JS
Get avatar image for an Ethereum address
Author: By
Last change: Replace axios with cross-fetch
Date: 2 years ago
Size: 10,728 bytes


Class file image Download

![EthAvatar Logo][icon-logo]


[![Stable Version][icon-stable-version]][link-package] [![Unstable Version][icon-unstable-version]][link-package] [![Downloads][icon-downloads]][link-package] [![License][icon-license]][link-license] [![Node.js][icon-nodejs]][link-nodejs] [![Build Status][icon-travis]][link-travis]

EthAvatar.JS is a JavaScript API for EthAvatar.


About EthAvatar

[EthAvatar][link-ethavatar] associates an avatar of your choice with an Ethereum address that you own. It is using [IPFS][link-ipfs] and [Ethereum][link-ethereum] [Smart Sontract][link-contract] to store avatars of addresses.

The avatar image is stored on IPFS and is bound to your address via an Ethereum smart contract.


  • Visual Verification: When sending ether to an exchange for instance, instead of being paranoid if you've pasted the correct address, wallets that support Eth Avatar will be able to fetch the exchange logo as a forms of visual verification. The same also works the other way around when transferring from the exchange to your own wallet.
  • Token Branding: Tokens and contracts will be able to associate branding artwork to their addresses, allowing it to be possibly visible on EtherScan and exchanges once they support Eth Avatar.
  • Personal Use: It's fun to associate avatars with your personal addresses and be able to visually differentiate between them in your wallets.


  • [x] ~~Command line program~~
  • [x] ~~Watching for contract events~~
  • [x] ~~Deleting avatars~~
  • [x] ~~Uploading avatars from files or URLs~~
  • [x] ~~Better tests~~
  • [ ] Support for JavaScript fronted frameworks


Using NPM or Yarn

EthAvatar.JS requires [Node.js][link-nodejs] and [NPM][link-npm] or [Yarn][link-yarn]. It works with Node.js 10 or later, but it is recommended to use supported and maintained versions. Note that if you want to use it with Node.js 12 or later, you must use Yarn instead of NPM (because of [Truffle and Web3 bug][link-truffle-bug]).

You could globally install EthAvatar.JS to get command line interface:

npm install -g ethavatar // Using NPM
yarn global add ethavatar // Using Yarn

You could also install EthAvatar.JS locally, so you could use it in your application:

npm install --save ethavatar // Using NPM
yarn add ethavatar // Using Yarn

Using CDN

If you want to use EthAvatar.JS in browser, you could include scripts from one of our CDNs in your HTML website:

<!-- Normal Versions -->
<script src=""></script>
<script src=""></script>

<!-- Minified Versions -->
<script src=""></script>
<script src=""></script>


In Command Line

Command line program allows you to get and set avatars using files.

First you should specify Web3 and IPFS connection using ethavatar config:

$ ethavatar config --web3
$ ethavatar config --ipfs

Program will save them in ~/.ethavatar file. Web3 connection is required and all providers are supported. IPFS connection is optional and it uses Infura IPFS API by default.

You can get avatar to file using ethavatar get <filename>:

$ ethavatar get avatar.jpg # Save avatar of current address to file avatar.jpg
$ ethavatar get avatar.jpg --address 0x0000000000000000000000000000000000000000 # Save avatar of address 0x0000000000000000000000000000000000000000 to file avatar.jpg

You can set avatar using ethavatar set <filename>:

$ ethavatar set avatar.jpg # Uplaod avatar of current address from fileavatar.jpg

In Applications


The whole class is asynchronous, so you would need to use promises or async/await in your application.

First, include this library and instantiate the class in your file:

const EthAvatar = require('ethavatar')
const ethavatar = new EthAvatar()

Class is using injected Web3 provider (like Mist or MetaMask) and Infura IPFS API. It is using official smart contract for detected network. You could also change them when instantiating the class:

/// Load Web3 and IPFS
const Web3 = require('web3')
const IpfsAPI = require('ipfs-api')

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

// Use local Web3 Provider
const web3Provider = new Web3.providers.HttpProvider('')
const web3Connection = new Web3(web3Provider)

/// Use Infura IPFS API
const ipfsConnection = IpfsAPI('', '5001', {protocol: 'https'})

// Use custom contract address
const contractAddress = '0x96fc5a0b46e9e4b5d114c42d4daeaa1c2517078a'

const ethavatar = new EthAvatar(

Getting Avatars

You should use method get() to get avatar of address. It uses current address as default, but you could specify any other address:

  .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
      (err) => {
        if (err) {
          throw err

  }).catch((error) => {

The avatar is returned as buffer, so you could directly write it to file.

Setting Avatars

You should use set() to set avatar of address. It's parameter must be buffer of avatar, so it is possible to upload it from a file:

let avatar = Buffer.from(['00', '01', '03', '04', '05', '06', '07', '08', '09'])

  .then((avatar) => {
    console.log('Avatar uploaded!')

  }).catch((error) => {

Deleting Avatars

You should use remove() to remove avatar of address. It doesn't have any parameters and you could only remove avatar of your address:

  .then(() => {
    console.log('Avatar removed!')

  }).catch((error) => {

Watching Changes

You can also watch for avatar changes of specific address. It uses current address as default, but you could specify any other address: => {
  console.log('User address: ' + result.hashAddress)
  console.log('IPFS hash: ' + result.hash)
}, '0xe12Aa5FB5659bb0DB3f488e29701fE303bcBAf65')

File Operations

File operations are possible with FileHelper class:

const FileHelper = require('ethavatar').fileHelper
const fileHelper = new FileHelper(ethavatar)

You can then save avatar directly to file:

fileHelper.toFile('avatar.png', '0xe12Aa5FB5659bb0DB3f488e29701fE303bcBAf65')
  .then((avatar) => {
    console.log('Avatar saved!')

  }).catch((error) => {

You can also upload avatar from file:

  .then((avatar) => {
    console.log('Avatar uploaded!')

  }).catch((error) => {

URL operations

URL operations are possible with UrlHelper class:

const UrlHelper = require('ethavatar').urlHelper
const urlHelper = new UrlHelper(ethavatar)

You can then post avatar as multipart form data:

urlHelper.toUrl('', '0xe12Aa5FB5659bb0DB3f488e29701fE303bcBAf65')
  .then((avatar) => {
    console.log('Avatar downloaded!')

  }).catch((error) => {

The request will have `multipart/form-datacontent type and includeaddressandavatar` form values.

You can also get avatar from URL:

  .then((avatar) => {
    console.log('Avatar uploaded!')

  }).catch((error) => {

Other Examples

You could also look to [example.js][link-example] or [API documentation][link-documentation]. Source code of [console application][link-console] is also great way to learn how this works.

Built With

  • [Ethereum][link-ethereum]
  • [Truffle Framework][link-truffle]
  • [Web3][link-web3]
  • [IPFS][link-ipfs]


Please read [][link-contributing] for details.


This project uses [SemVer][link-semver] for versioning. For the versions available, see the [tags on this repository][link-tags].


This project is licensed under the MIT license. See the [LICENSE][link-license-file] file for details.


[icon-stable-version]: [icon-unstable-version]: [icon-downloads]: [icon-license]: [icon-nodejs]: [icon-travis]:

[link-ethavatar]: [link-contract]: [link-ethereum]: [link-truffle]: [link-web3]: [link-ipfs]: [link-nodejs]: [link-npm]: [link-yarn]: [link-semver]: [link-license]:

[link-package]: [link-travis]:

[link-tags]: [link-license-file]: [link-example]: [link-documentation]: [link-console]: [link-contributing]: