Skip to content

Deploy your first blockchain contract to Ethereum

· 2 min read
ethereum blockchain solidity tutorial
Deploy your first blockchain contract to Ethereum

First contract - Pet owners

I am learning blockchain and smart contracts. This post will be my note on how I am starting my journey into blockchain technology.

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

Development

// 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 in the Remix IDE: https://remix.ethereum.org/. It should compile and we can deploy it on the 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 Ethereum test network

Ethereum allows testing our contract on test networks. For this example I will use Rinkeby. This is a free network for testing smart contracts.

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 your tests.

  1. Switch the Remix Environment from Javascript VM to Injected Web3
  2. Connect your Metamask. Ensure you have chosen Rinkeby network Metamask Rinkeby Network
  3. If you don’t have any ETH coins you can use this Faucet to grab some: https://faucets.chain.link/rinkeby
  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 contains my notes from a Blockchain development tutorial available here.

Marcin Jasion

Marcin Jasion

Senior Platform Engineer

Comments