EatTheBlocks Forum

Assembly issue solidity

I’m working a proxy contract for an already deployed contract

The deployed contract has both the logic and storage in same contract

But the already deployed contract doesn’t have erc721 metadata interface

So the proxy I’m writing intends to send that to the already deployed function along with some other functions written in the proxy contract

My question is I know I’m the assembly section when you call a fallback it send the info to the contract address named implementation

If the fallback in the contract is called does the info of the other functions deliver to the old contract

pragma solidity ^0.4.20;

contract Proxy {

address admin;

address implementation;

string _baseURI = ‘http://abc’;

struct GeosByTokenIdsStruct {

uint tokenId;
string lat;
string lon;

// tokenId => token history array
mapping(uint => GeosByTokenIdsStruct[]) public geosByTokenIds;

constructor(address _implementation) public {

    admin = msg.sender; 
    implementation = _implementation;


function tokenURI(uint256 _tokenId) public view returns (string memory) {

    require(exists(_tokenId), "ERC721Metadata: URI query for nonexistent token");

    string memory _tokenURI = tokenURIs[_tokenId];

    // Even if there is a base URI, it is only appended to non-empty token-specific URIs
    if (bytes(_tokenURI).length == 0) {
        return string(abi.encodePacked(baseURI, Strings.toString(_tokenId)));
    } else {
        // abi.encodePacked is being used to concatenate strings
        return string(abi.encodePacked(_baseURI, _tokenURI));

function baseURI() public view returns (string memory) {
    return _baseURI;

function transfer(uint tokenId) view public returns (string lat, string lon) {
        lat = geosByTokenIds[tokenId][0].lat,
        lon = geosByTokenIds[tokenId][0].lon
    implementation.buyToken(getGeoFromTokenId(lat, lon));

function getTokenId(string memory lon, string memory lat) pure public returns (uint) {
return uint(keccak256(abi.encodePacked(lon, “,”, lat)));

function setGeoByTokenId(uint _tokenId, string _lat, string _lon) public {
    geosByTokenIds[_tokenId].push(GeosByTokenIdsStruct(_tokenId, _lat, _lon));

function getGeoFromTokenId(uint tokenId) view public returns(string memory, string memory) {
  return (geosByTokenIds[tokenId][0].lat, geosByTokenIds[tokenId][0].lon) ;


  • This function will return whatever the implementation call returns
    function () payable external {
    require(implementation != address(0));
    address impl = implementation;

    assembly {
    let ptr := mload(0x40)
    calldatacopy(ptr, 0, calldatasize)
    let result := delegatecall(gas, impl, ptr, calldatasize, 0, 0)
    let size := returndatasize
    returndatacopy(ptr, 0, size)

    switch result
    case 0 { revert(ptr, size) }
    default { return(ptr, size) }

If you are forwarding a call, its more simple that delegatecall. No need for assembly. If myContract is a pointer to the erc721 token:;

Much appreciated Jklepatch

1 Like