solidity – Why ABI and Contract Source Code Are Not Visible on Etherscan’s Smart Contract

blockchainetherscansolidityweb3js

I recently posted a small Lottery contract on the ethereum rinkeby network. The contract got deployed successfully however I am not able to see Contract source code and ABI on the Etherscan portal. Below is the address

https://rinkeby.etherscan.io/address/0xa19Ea5690dD32BFf3081cB0d81f91170AD859E0C#code

Other people from my training group deployed their code they got ABI and other details. Below is the URL

https://rinkeby.etherscan.io/address/0xc09eb46ce7A8b32F4339390cB94A3568C20eCaa9#code

Below is Solidity code.

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.9;

contract Lottery{

    address payable public manager;
    address payable[] public players;

    constructor()  {
        manager = payable(msg.sender);

    }

    function enter() public payable{
        require (msg.value > 0.01 ether);

        players.push(payable(msg.sender));
    }

    function random_num() private view returns (uint){
        return uint(keccak256(abi.encodePacked(block.difficulty, block.timestamp, players)));
    }

    function pick_winner() public restricted_func {
        uint index = random_num() % players.length;
        players[index].transfer(address(this).balance);
        players = new address payable[](0);
    }

    function get_list_players() public view returns(address payable[] memory) {
        return players;
    }


    modifier restricted_func{
        require (msg.sender == manager);
        _;
    }

}

And below is my Deploy.js

const HDWalletProvider = require('@truffle/hdwallet-provider');
const Web3 = require('web3');

const { abi, evm } = require('./compile');

console.log(abi);


provider = new HDWalletProvider(
  "my secret code phrase",
  "https://rinkeby.infura.io/v3/infura_key"
);

const web3 = new Web3(provider);

const deploy = async () => {
  const accounts = await web3.eth.getAccounts();

  console.log('Attempting to deploy from account', accounts[0]);

  const result = await new web3.eth.Contract(abi)
    .deploy({ data: evm.bytecode.object })
    .send({ gas: '1000000', from: accounts[0] });

  console.log(abi);
  console.log('Contract deployed to', result.options.address);
  provider.engine.stop();
};

deploy();

Could someone please help me understand why?
Many thanks in advance!!

Best Answer

Sometimes Etherscan may identify similar contracts which is probably why your partners have the ABI of the contract already visible. You can make this happen for your contract manually by verifying the contract yourself on https://rinkeby.etherscan.io/verifyContract.

For a single file contract it's easy but you can follow some tutorials such as this one or this one for context.