gravatar for ethereum addresses
Eth Avatar associates an avatar of your choice with an Ethereum address that you own.
We hope this project will be a "gravatar for ethereum addresses".
This project is free and open source. We hope to see other projects make use of it! The more projects use it, the more useful it is.
The avatar image is stored on IPFS and is bound to your address via an Ethereum smart contract.
// assumes you're running web3.js and ipfs.js already!
// todo: well need to host web3.js and ipfs-api.js on ethavatar.co so folks can pull down from there
// https://gitcoin.co/static/v2/js/ipfs-api.js
// var ipfs = ipfsAPI('ipfs.infura.io', '5001', {protocol: 'https'}); // connect to the unfura IPFS node
// setup
var eth_avatar_abi = [{"constant": false, "inputs": [], "name": "getIPFSHash", "outputs": [{"name": "", "type": "string"}], "payable": false, "type": "function"}, {"constant": false, "inputs": [{"name": "hash", "type": "string"}], "name": "setIPFSHash", "outputs": [], "payable": false, "type": "function"}, {"anonymous": false, "inputs": [{"indexed": true, "name": "hashAddress", "type": "address"}, {"indexed": false, "name": "hash", "type": "string"}], "name": "DidSetIPFSHash", "type": "event"}]
var eth_avatar_address = '0x4FbF2f1613Cc86314b22AE10Ae95D19cF2990824'; //mainnet
var eth_avatar_contract = web3.eth.contract(eth_avatar_abi).at(eth_avatar_address);
// configure inputs
var target_address = web3.eth.coinbase; // TODO - your address
// get the IPFS data
eth_avatar_contract.getIPFSHash.call((err, result) => {
var ipfs_hash = result;
ipfs.files.get(ipfs_hash, (err, result) => {
if(err) {
console.error('**Error fetching avatar data from IPFS: ' + err);
return;
}
// need help from tarek -- what if the hashcontent is empty?
var hashContent = result[0].content;
var avatarDataBuffer = Buffer.from(hashContent);
// we've got the data
var avatarData = JSON.parse(avatarDataBuffer.toString());
// TODO - use the avatar data for something
// avatarData.title
// Now fetch the image itself
ipfs.files.get(avatarData.imageHash, (err, result) => {
if(err) {
console.error('**Error fetching avatar image from IPFS: ' + err);
return;
}
var imageContent = result[0].content;
var imageBlob = new Blob( [ imageContent ], { type: "image/jpeg" } );
var imageURL = window.URL.createObjectURL(imageBlob);
// TODO - use the avatar data for something
});
})
})
Before you start, make sure you have both npm & Node.js installed
Install Truffle.
$ npm install -g truffle
Download and launch Ganache. Make sure Ganache is running on port 7545
.
Clone the repository to a folder of your choice.
$ git clone https://github.com/gitcoinco/ethavatar.git
Fetch all required packages.
$ cd ethavatar
$ npm install
Deploy the smart contract to Ganache.
$ truffle migrate
Launch the Dapp
$ npm run start