1

I am trying to create asset based transfer Smart contract by solidity language. i'm using ethereum.

functions are

  1. Create assets (land_id, land_size, land_price) with a ownership of contract owner.

  2. Transfer assets to other person.

  3. getCurrentOwnership
  4. Previous Owners list
  5. getAsset details.

My Contract:

pragma solidity >=0.4.22 <0.6.0; 

contract Asset {

uint256 public owners_count;
address public contract_owner;              // Manufacturer/owner
bytes32 public land_id;                   // land_id
bytes32 public land_sqrfeet;              // land_sqrfeet
bytes32 public land_created_date;         // Created date
mapping(uint => address) public owners;     // list of owners

function createland(bytes32 _land_id, bytes32 _land_sqrfeet, bytes32 _land_created_date) public returns (bool){
    setOwner(msg.sender);
    land_id = _land_id;
    land_sqrfeet = _land_sqrfeet;
    land_created_date = _land_created_date;
    return true;
}

//Modifier that only allows owner of the bag to Smart Contract AKA Good to use the function
modifier onlyOwner(){
    require(msg.sender == contract_owner);
    _;
}

//This function transfer ownership of contract from one entity to another
function transferOwnership(address _newOwner) public onlyOwner(){
    require(_newOwner != address(0));
    contract_owner = _newOwner;
}

//Get the previous owner in the mappings
function previousOwner() view public returns(address){
    if(owners_count != 0){
        uint256 previous_owner = owners_count - 1;
        return owners[previous_owner];
    }
}

function setOwner(address owner)public{
    owners_count += 1 ;
    owners[owners_count] = owner;
}

function getCurrentOwner() view public returns(address){
    return owners[owners_count] ;
}

function getOwnerCount() view public returns(uint256){
    return owners_count;
}}

but with this contract, i can able to get last created asset details. I can not get previous creation assets details.

Questions are:

  1. Each Assets should be different contract address or one contract address?
  2. If take one contract address for all assets, how can i get old transaction by contract function?
Balakrishnan
  • 103
  • 8

1 Answers1

1
  1. Each Assets should be different contract address or one contract address?

Ans : Each Assets should be on one contract address only.

  1. If take one contract address for all assets, how can i get old transaction by contract function?

Ans : You can use structure(Data Structure) for store your all assets details and also for get details. You can see this link for how to create structure .

Mahesh Rajput
  • 1,211
  • 7
  • 17
  • hi mahesh rajput, thanks for reply. Let me try this. And few more questions: i can create two assets with same details one by one. So it is creating duplicate record in the blockchain network. how can i restrict duplicate asset creation? – Balakrishnan Dec 17 '18 at 08:12
  • For that, you can add a new condition that checks whether the entered details of a structure is already existing or not in your asset structure. – Mahesh Rajput Dec 17 '18 at 08:47
  • thanks dude. can i get direct chat? i want to get more details regarding smart contract. – Balakrishnan Dec 17 '18 at 09:40
  • You can connect me over LinkedIn. You can find my LinkedIn profile under the About Me section of this profile. – Mahesh Rajput Dec 17 '18 at 09:53
  • hi dude, Can you please give suggestion to this contract https://ethereum.stackexchange.com/questions/64231/suggestion-on-my-asset-contract. – Balakrishnan Dec 18 '18 at 06:49