Created by starline — fr.freepik.com

Profile Smart Contract — final version and deployed address

MetaZebre
4 min readMay 6, 2022

--

A few days ago, we modified our Profile Smart Contract so that it could work with any non renounced ownable smart contract. Today, we’ll add a final touch to it.

Let’s close the loop

Silly me. I thought yesterday that I had finished my Profile smart contract, but I forgot one thing: make this contract ownable, so I could, as its owner, set the profile for that profile contract.

A profile smart contract should have its own profile right?

Two lines were enough to add that possibility. The more I write Solidity smart contracts, the more I am amazed at how some apparently very sophisticated functionalities can be added so easily.

So here is the final version of that contract, with the two modified lines in bold:

Profile.sol

// SPDX-License-Identifier: GPL-3.0
pragma solidity ^0.8.9;
import "@openzeppelin/contracts/access/Ownable.sol";interface IOwnable {
function owner() external view returns(address);
}
contract Profile is Ownable { // contract data
mapping(address => string) private _profiles;
function getProfile(address addr)
external
view
returns(string memory)
{
return _profiles[addr];
}
function setProfile(string memory ipfsHash)
external
returns(bool)
{
_profiles[msg.sender] = ipfsHash;
return true;
}
function setProfileFor(address addr, string memory ipfsHash)
external
returns(bool)
{
// get the owner of the contract
address contractOwner = IOwnable(addr).owner();
// check contract owner is msg.sender
require(contractOwner == msg.sender, "You are not the owner of that contract");
// set profile
_profiles[addr] = ipfsHash;
return true;
}
}

Profile Smart Contract Profile

As you might have guessed, I love recursivity.

So now, let’s write the profile of that Profile Smart Contract. I’ll write it in Markdown this time, because I mainly want to write a description of the smart contract and how it works. I can also add some yaml at the top following the Front Matter format:

scProfile.md

---
title: Simple Profile system smart contract
creator: 0xedB00816FB204b4CD9bCb45FF2EF693E99723484
date: 2022-04-21
website: http://www.metazebre.com/
tags:
- profile system
- Fantom Network
- Solidity tutorial
---
This is a simple Profile system smart contract.
The main use case for that contract is to serve as a repository of profiles for
blockchain addresses.
You can read all the details about it in
[a simple decentralised profile system](http://www.metazebre.com/blog/2022/04/17-Simple-profile-system).
The source code of that contract is there too.# Functions## setProfile(ipfsCID)
Calling this function will associate the IPFS CID (Content ID) to the address
of msg.sender.
It is up to you to upload the profile contract to IPFS.The format is up to you too. Maybe some kind of standard will emerge with usage.
Yaml format is probably a good idea. Please visit
[this link](http://www.metazebre.com/blog/04/17-Simple-profile-system) to see
an example of a profile file.
This function returns true on success.## getProfile(address)
Will return the CID of the IPFS profile file of the given address.
## setProfileFor(address, ipfsCID)
If you want to associate a profile to one of your owned smart contract, (like I
did for this smart contract) you can call that function.
The profile smart contract will call the owner() function of your smart contract,
and associate the ipfsCID to your smart contract address if it matches your
msg.sender address.

Events?

It is common practise to send events when an action changes the state of a smart contract.

Other applications (but not other smart contracts) can easily subscribe to these events, to monitor what’s going on in the smart contract. We’ll start from the principle that this profile smart contract will serve as the preference and settings repository for other web 3.0. We could indeed facilitate the task of knowing when to update their user’s profile by sending an event each time a profile is updated.

This, again, is done in just a few lines, in bold again:

Profile.sol

// SPDX-License-Identifier: GPL-3.0
pragma solidity ^0.8.9;
import "@openzeppelin/contracts/access/Ownable.sol";interface IOwnable {
function owner() external view returns(address);
}
contract Profile is Ownable { event ProfileUpdate(address indexed from, string cid); // contract data
mapping(address => string) private _profiles;
function getProfile(address addr)
external
view
returns(string memory)
{
return _profiles[addr];
}
function setProfile(string memory ipfsHash)
external
returns(bool)
{
_profiles[msg.sender] = ipfsHash;
emit ProfileUpdate(msg.sender, ipfsHash);
return true;
}
function setProfileFor(address addr, string memory ipfsHash)
external
returns(bool)
{
// get the owner of the contract
address contractOwner = IOwnable(addr).owner();
// check contract owner is msg.sender
require(contractOwner == msg.sender, "You are not the owner of that contract");
// set profile
_profiles[addr] = ipfsHash;
emit ProfileUpdate(addr, ipfsHash);
return true;
}
}

Deployed address

Now that the contract seems to be in its final form, I have deployed it on my favorite blockchain: Fantom.

It’s cheap and fast. Fantom is full of scams and ponzi, but that’s the downside of being a thriving ecosystem.

You need to be very rich to experiment on Ethereum and your users would better be rich too to afford using your application.

Here on Fantom, transactions are cheap and they go fast. That is all we need to experiment and create.

Innovation is affordable on Fantom. That’s why innovation is on Fantom.

So here is the deployed contract address: 0x9F0277916F3a3F00Cc3Db18496ea6D6B4E65d73a

You can see the deployment transaction, that is, the creation of the contract on the Fantom Network. It cost only 0.31 FTM to deploy the smart contract on the blockchain. That is $0.35. That’s how cheap Fantom is.

I then put my profile IPFS address, which cost me 0.046 FTM (= $0.05).

And finally, I put the profile of the profile contract itself. Here the tx cost more than the previous, probably because the setProfileFor() function has to make a call to an external contract (which, in that case, happens to be himself, but the contract did not know that). So it cost me 0.073 FTM (= $0.08).

Thank you for following me in that journey. This system follows the KISS principle: Keep It Small and Simple, so it will be dead easy to build other applications on top of it. Now, one last cool think would be to have a nice web interface, don’t you think? So, stay tuned … ;-)

--

--

MetaZebre

Follow Le Zèbre in his investigations in the land of yield addicts and leverage dealers. #DegenDeFi