Smart Contract integration

Could someone explain how the integration of Moralis works with smart contracts?

Can you give more details on what part are you interested regarding smart contracts integration?

1 Like

I started studying a lot more in the past days and I am stuck right now on this.
It’s weird because on my smart contract when I set three parameters it works, if I add one more then the transaction does not go through.

Error: Returned error: VM Exception while processing transaction: revert
at Object.ErrorResponse (http://localhost:3000/static/js/vendors~main.chunk.js:195282:15)
at http://localhost:3000/static/js/vendors~main.chunk.js:197393:30
at XMLHttpRequest.request.onreadystatechange (http://localhost:3000/static/js/vendors~main.chunk.js:203985:7)

I don’t know what you have in your smart contract, what function you tried to execute. Usually this error could mean that you didn’t send the expected parameters for the contract function or the contract function didn’t work properly.

I`m just using the publish function and if I remove the string readableNFT it works, otherwise not.

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

import "../node_modules/@openzeppelin/contracts/token/ERC1155/ERC1155.sol";
import "./StoreFront.sol";

contract BookStore is ERC1155 {
    uint256 private _currentBookVersionId;

    mapping(uint256 => BookVersion) private _bookVersions;

    StoreFront private _storeFront;

    struct BookVersion {
        uint256 price;
        address currency;
        address author;
        string readableNFT;
    }

    address private _owner;

    constructor() ERC1155("https://example.com/api/{id}.json") {
        _currentBookVersionId = 1;
        _owner = msg.sender;
    }

    function setStoreFront(address _storeFrontAddress) public {
        require(
            msg.sender == _owner,
            "BookStore: Only contract owner can set storeFront"
        );
        _storeFront = StoreFront(_storeFrontAddress);
    }

    function publish(
        uint256 _quantity,
        uint256 _price,
        address _currency,
        string memory _readableNFT
    ) public {
        _mint(msg.sender, _currentBookVersionId, _quantity,'');
        _bookVersions[_currentBookVersionId] = BookVersion(
            _price,
            _currency,
            msg.sender,
            _readableNFT
        );
        _currentBookVersionId += 1;
    }

    function transferFromAuthor(address _buyer, uint256 _bookVersionId) public {
        require(
            msg.sender == address(_storeFront),
            "Method can only be called by Store Front contract"
        );
        BookVersion memory bookVersion = _bookVersions[_bookVersionId];
        safeTransferFrom(bookVersion.author, _buyer, _bookVersionId, 1, "");
    }

    function bookVersionPrice(uint256 _bookVersionId)
        public
        view
        returns (uint256)
    {
        return _bookVersions[_bookVersionId].price;
    }

    function bookVersionCurrency(uint256 _bookVersionId)
        public
        view
        returns (address)
    {
        return _bookVersions[_bookVersionId].currency;
    }

    function bookVersionAuthor(uint256 _bookVersionId)
        public
        view
        returns (address)
    {
        return _bookVersions[_bookVersionId].author;
    }
}

It may be related to how that _readableNFT parameter is sent, but I’m not expert in Solidity to tell you exactly how to fix it now.