First contract - Pet owners

I am learning blockchain and smarcontract. This post will be my note how I am starting my journey to blockchain technology.

In this example I will create a contract for storing who is owning a Pet.


// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0; //build contract on top of Solidity >=0.8.0 and <0.9.0

contract PetOwner {
    mapping (string => Pet) public petOwners;

    struct Pet {
        string name;
        string petType;

    function addPetOwner(string memory ownerName, string memory _name, string memory _petType) public {
        petOwners[ownerName] = Pet({name: _name, petType: _petType});


Put it to the Remix IDE: It should compile and we can deploy it on local environment:

Deploy contract

When we have contract deployed we can create example contract ownership

Test Transaction

and ask petOwners field for information which Pet is owned by Marcin.

Test check

Let’s deploy it to Ethenerum test network

Ethenerum allows to test our contract test networks. For this example I will use Rinkeby. This a free and for testing smart contracts network.

I am not covering how to install Metamask. Always remember to not share private key and seed
You can always create a new Metamask identity for the your tests.

  1. Switch the Remix Environment from Javascript VM to Injected Web3
  2. Connect your Metamas. Ensure you have choosen Rinkeby network
    Metamask Rinkeby Network
  3. If you dont have any ETH coins you can use this Faucet to grab some:
  4. Click deploy. You will be asked by Metamask to confirm the transaction: Contract deployment transaction

Now I can test my contract. I fill the data

And we will be asked again for confirming the transaction

When everything will be done, our transaction should be visible on Etherscan Etherscan

And at the end we can check if petOwner field contains our definition:

This post are my notes from Blockchain development tutorial availale here.