solang icon indicating copy to clipboard operation
solang copied to clipboard

Not able to deploy contract on substrate after compiling it successfully

Open s-h-ubham opened this issue 3 years ago • 2 comments

I have written a basic NFT smart contract in solidity and compiled it using solang, it is compiled successfully for target substrate but while deploying the contract it is showing error Cannot read properties of undefined (reading 'toLowerCase'), is it a problem with solang compiler or substrate chain. I have attached the screenshot of issue.

Screenshot from 2022-04-21 10-16-35

s-h-ubham avatar Apr 21 '22 04:04 s-h-ubham

I imagine this is a dup #666

Would you mind sharing the solidity code please?

seanyoung avatar Apr 26 '22 08:04 seanyoung

This was my solidity code @seanyoung

`// SPDX-License-Identifier: MIT pragma solidity ^0.8.7; // pragma solidity >=0.6.0 <0.8.0; interface IErc20{

event Transfer(address indexed from, address indexed to, uint256 indexed tokenId);
event Approval(address indexed owner, address indexed approved, uint256 indexed tokenId);
event ApprovalForAll(address indexed owner, address indexed operator, bool approved);




function balanceOf(address owner) view  external returns(uint);
function ownerOf(uint tokenId) external view  returns(address);
function approve(address operator,uint tokenId) external returns(bool);
function getApprovedAddress(uint tokenId) view external returns(address);
function setApprovalForAll(address operator,bool approved) external payable;
function isApproved(address owner, address operator) external view returns(bool);
function transfer(address to, uint tokenId) external;
function transferFrom(address from, address to, uint tokenId) payable external;
function mint(address to, uint tokenId) external ;
function burn(uint tokenId) external ;




    
}

contract Erc721 is IErc20{

// nft Tokens // uint[] public tokens;

//mapping to know list of tokens hold by the owner
mapping(address=>uint[]) public ownerToId;
// to count the nfts of the owner
mapping(address=>uint) public nftCounterOfOwner;  

//to get the address of the token id
mapping(uint=>address) public tokenIdToOwner;

//mapping to know who approved the tokenId
mapping(uint=>address) public idToApproval;

//mapping to know whether the owner address is approved for the operator address returns true or false
mapping(address=>mapping(address=>bool)) public ownerToOperator;



modifier validNftToken(uint tokenId){
    require(tokenIdToOwner[tokenId]!=address(0),"Zero address owner are not valid ");
    _;
}

modifier canTranfer(uint tokenId){
    address tokenOwner=tokenIdToOwner[tokenId];
    require(tokenOwner==msg.sender || idToApproval[tokenId]==msg.sender || ownerToOperator[tokenOwner][msg.sender] ,"Not owner approved ");

    _;
}


// constructor(owner){
    
// }

function balanceOf(address owner) view  override public returns(uint){
    require(owner!=address(0),"Zero address are not allowed");
    return nftCounterOfOwner[owner];

}
function ownerOf(uint tokenId) public view override returns(address){
    return tokenIdToOwner[tokenId];
}
function approve(address operator,uint tokenId) override public returns(bool) {
    address tokenOwner=tokenIdToOwner[tokenId];
    require(operator!=tokenOwner,"Operator is the owner,so it is useless to approve");
    tokenIdToOwner[tokenId]=operator;
    // must write emit before returning boolean other wise we get error unreachable 
    emit Approval(tokenOwner, operator, tokenId);
    return true;

}
//It gives the address of the owner who approved the token , if and only if it is valid 
function getApprovedAddress(uint tokenId) public validNftToken(tokenId) override view returns(address){
    return idToApproval[tokenId];

}

//setting the approved to false(by default) for all the operators
function setApprovalForAll(address operator,bool approved) override payable public{
    ownerToOperator[msg.sender][operator]=approved;
    emit ApprovalForAll(msg.sender, operator, approved);

}

//checking whether the operator got approved by the owner or not
function isApproved(address owner, address operator) public view override returns(bool){
    return ownerToOperator[owner][operator];
    
}
function transfer(address to, uint tokenId) public override{
    address from =tokenIdToOwner[tokenId];
    removeToken(from,tokenId);
    addNftToken(to,tokenId);
    
    clearTokenApproval(tokenId);
    emit Transfer(from ,to, tokenId);



}
function transferFrom(address from, address to, uint tokenId) payable public override canTranfer(tokenId) validNftToken(tokenId){ 
    address tokenOwner=tokenIdToOwner[tokenId];
    require(tokenOwner==from,"Not Owner");
    require(to!=address(0),"Zero address are not valid");
    transfer(to,tokenId);



}
function addNftToken(address to, uint tokenId) public{
    require(tokenIdToOwner[tokenId]==address(0),"NFT already exists");
    tokenIdToOwner[tokenId]=to;
    nftCounterOfOwner[to]+=1;


}
function removeToken(address from ,uint tokenId) public {
    require(tokenIdToOwner[tokenId]==from,"Not the owner");
    nftCounterOfOwner[from]-=1;
    delete tokenIdToOwner[tokenId];
}
function clearTokenApproval(uint tokenId) public{
    delete idToApproval[tokenId];
}

function mint(address to, uint tokenId) override public{
    require(to!=address(0),"receiver is not valid");
    require(tokenIdToOwner[tokenId]==address(0),"Token id is already minted");
    addNftToken(to,tokenId);
    emit Transfer(address(0),to, tokenId);

}
function burn(uint tokenId) public validNftToken(tokenId) override {
    address tokenOwner=tokenIdToOwner[tokenId];
    clearTokenApproval(tokenId);
    removeToken(tokenOwner,tokenId);
    emit Transfer(tokenOwner, address(0), tokenId);

}
//function getMetadata()

}`

s-h-ubham avatar Apr 27 '22 07:04 s-h-ubham

The contract compiles and deploys fine with a recent Solang version.

xermicus avatar Jun 26 '23 17:06 xermicus