File: example.js

Recommend this page to a friend!
  Classes of Filip Štamcar   EthAvatar.JS   example.js   Download  
File: example.js
Role: Example script
Content type: text/plain
Description: Example script
Class: EthAvatar.JS
Get avatar image for an Ethereum address
Author: By
Last change: Update of example.js
Date: 2 years ago
Size: 712 bytes


Class file image Download
'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) })