0

I have a test dapp, which is connected to Polygon's Mumbai testnet.

I can deploy a basic data (name and description) to the blockchain and read from it.

A deploymed part I copied from other project, which I found on medium.. It looks like that (deploy.js script):

const hre = require('hardhat')

async function main() {
  const Gallery = await hre.ethers.getContractFactory('Gallery')
  const gallery = await Gallery.deploy()
  await gallery.deployed()

  const txHash = gallery.deployTransaction.hash;
  const txReceipt = await hre.ethers.provider.waitForTransaction(txHash);
  console.log(`check your contract: https://mumbai.polygonscan.com/address/${txReceipt.contractAddress}`)
  console.log("contract address:", txReceipt.contractAddress);
}

main()
  .then(() => process.exit(0))
  .catch((error) => {
    console.error(error)
    process.exit(1)
  })

If I switch the Metamask account and run command: npm run deploy:testnet I get the contract address on the command line which i paste to teh enviroment.ts file.

When I than refresh the application, I lose the data, uploaded to the blockchain.

I somehow am not sure, if I can access to the all data deploed to the network from different accounts

Solidity part:

// SPDX-License-Identifier: MIT
pragma solidity >=0.7.0 <0.9.0;

contract Board{
  Board[] private boards;
  mapping(address => Board[]) private authorToBoards;

  struct Board{
    string title;
    string description;
  }

  function store(string memory title, string memory description) public {
    Board memory board = Board(title, description);

    boards.push(board);
    authorToBoards[msg.sender].push(board);
  }

  function retrieveAllBoards() public view returns (Board[] memory) {
    return boards;
  }

  function retrieveBoardsByAuthor() public view returns (Board[] memory) {
    return authorToBoards[msg.sender];
  }
}

I am not sure if I understand that right, but am I even able to access to all Boards, not only the boards for which I am an author?

Thanks and sorry if it sounds confused but I am beginner in web3 development

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy