GithubHelp home page GithubHelp logo

Comments (6)

Vectorized avatar Vectorized commented on August 26, 2024 2

@santiq

Could one overwrite the isApprovedForAll to return true for a staking contract, that way users don't have to approve it and thus save a transaction?

Yes. But it is dangerous practice. Not recommended.

Your users also have to trust that whoever you approve won't rug them.

Some savvy users will consider this a red flag.

contract NFT is ERC721A, Ownable {

    mapping(uint256 => bool) internal _globalOperatorApprovals;

    function setGlobalOperatorApproval(address operator, bool approved) external onlyOwner {
        _globalOperatorApprovals[operator] = approved;
    }

    function isApprovedForAll(address owner, address operator) public view override returns (bool) {
        return (_globalOperatorApprovals[operator] || ERC721A.isApprovedForAll(owner, operator));
    }
}

from erc721a.

Vectorized avatar Vectorized commented on August 26, 2024

Did you add an additional button on your dApp to let the user approve the staking contract to transfer on their behalf?

This is so that isApprovedForAll returns true.

from erc721a.

santiq avatar santiq commented on August 26, 2024

@Vectorized

Could one overwrite the isApprovedForAll to return true for a staking contract, that way users don't have to approve it and thus save a transaction?

from erc721a.

rafaelbate avatar rafaelbate commented on August 26, 2024

Thanks for your proposals.

Summing up, we ended up doing the following:

  • Commented lines 409 and 413 of ERC-721A;
  • We overrode transferFrom() in our main contract for it to check if the "msg.sender" is not the contract, and, if it is not the contract, we verify if the user is the holder of the token;
  • Once we verify that the user is the owner of the token, we call the _transfer function of ERC-721A.

This is safe because once the contract is deployed, the owner is not able in any shape or form to transfer tokens from a user wallet to the contract. Only the contract itself is able to do it.

This way, users don't have to pay any extra gas fees to approve for something. When a user accepts to stake, it is implied that they "approve" the staking, hence we end up saving gas fees for the user.

Everything is running smoothly now.

If you find this is a suitable solution, you may close this issue.

from erc721a.

codesport avatar codesport commented on August 26, 2024
  • Using a "stake.sol" contract to handle all the staking. In this contract, we call a function "stakingTokens", that will check all the conditions prior to staking (if the user is the owner of the token, if the token isn't already staked, etc…). After checking all the conditions, we call the "transferFrom" function of the ERC-721A contract and send the usual parameters "msg.sender", "address(this)", "_tokenIds".

@rafaelbate by any chance, would you be able to provide a link to a reference contract for Stake.sol for either ERC-721 or ERC-721A? I'm sure others have the same question. I'm curious with how to this, And it would definitely help the community learn how it should be implemented.

If I find something I will post it here so others can benefit. Google is everybody's friend!

from erc721a.

rafaelbate avatar rafaelbate commented on August 26, 2024
  • Using a "stake.sol" contract to handle all the staking. In this contract, we call a function "stakingTokens", that will check all the conditions prior to staking (if the user is the owner of the token, if the token isn't already staked, etc…). After checking all the conditions, we call the "transferFrom" function of the ERC-721A contract and send the usual parameters "msg.sender", "address(this)", "_tokenIds".

@rafaelbate by any chance, would you be able to provide a link to a reference contract for Stake.sol for either ERC-721 or ERC-721A? I'm sure others have the same question. I'm curious with how to this, And it would definitely help the community learn how it should be implemented.

If I find something I will post it here so others can benefit. Google is everybody's friend!

I will post it in a near future, Right now I am not able to do it due to NDA.

from erc721a.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.