区块链NFT开发报错:execution reverted: ERC721: approve to caller 解决分享

区块链开发NFT上链
approve 时报错

Transaction 0x0bf0f2da260fac96ad1ed4e32aa10a4e86ed9b976140e73a7ecb8327c2be7617 has failed with status: 0x0. Gas used: 22233. Revert reason: 'execution reverted: ERC721: approve to caller

问题重现

关键代码如下

    public static Boolean setApprovedForAll(String contractAddress, String address, String operator){
    
    
        NFT721 nft721 = getOperateNft721(address, contractAddress, BigInteger.valueOf(22_000_000_000l), BigInteger.valueOf(6_700_000l));
        try {
    
    
            TransactionReceipt tr = nft721.setApprovalForAll(operator,true).sendAsync().get();
            if(tr.getBlockHash().isEmpty()) return false;
        } catch (InterruptedException | ExecutionException e) {
    
    
            log.error("获取721uri异常", e);
            throw new BusinessException(40080,"processing nft,but happen a error when minting::"+e.getMessage());
        }
        return true;
    }

当执行调用setApprovalForAll 方法去操作链时报错了

问题分析和解决

根据报错信息说是approve caller 的关键字,怀疑是传入的参数operator有问题。我这里传入的是账户地址。而审批授权应该是代理交易的地址,按着这个思路去修改operator的值为代理交易地址,果然神奇的正常了

猜你喜欢

转载自blog.csdn.net/huangxuanheng/article/details/125333275