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?
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 .

  • 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 8: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 8:47
  • thanks dude. can i get direct chat? i want to get more details regarding smart contract. – balakrishnan Dec 17 '18 at 9: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 9:53
  • hi dude, Can you please give suggestion to this contract ethereum.stackexchange.com/questions/64231/…. – balakrishnan Dec 18 '18 at 6:49

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.