Comments (6)
Could one overwrite the
isApprovedForAll
to returntrue
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.
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.
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.
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.
- 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.
- 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)
- expose internal method for checking whether an address is authorized to act on behalf of an nft
- ERC721A Contracts Classified as ERC-20 Tokens in Etherscan HOT 2
- Batch burning with ERC721ABurnable implementation HOT 1
- I cannot compile my contract with hardhat
- Incorrect Twitter Link (twitter.com/AzukiOfficial > twitter.com/Azuki)
- OK, I'll give it a try. HOT 1
- fail mint in other contract HOT 1
- Please help me ERC721A team. I'm stuck on infinite loading in my current deployment with Hardhat....
- Please support ERC4906
- We were not able to estimate gas. There might be an error in the contract and this transaction may fail
- ERC721A interface id
- Precalculate TokenIds? HOT 1
- add support for ERC165 HOT 1
- Need a way to dynamically set value for `_startTokenId` in constructor HOT 6
- How can i add royaltyInfo? HOT 1
- Why is value of `_tokenApprovals` mapping a struct with one parameter instead simply an address? HOT 2
- How may not be clean upper bits of `from` address in `transferFrom` function? HOT 2
- What is the purpose of this function on L911? HOT 2
- is there an IERC721Enumerable implementation ? HOT 1
- Cross-chain NFT
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from erc721a.