Hi,
I’m Creating a React dApp using Moralis and Opensea-js. For testing purposes, I’ve created a simple page to buy an asset from Opensea using Moralis. I’ve completely followed : This Video
The first time, the buying request goes just fine. For Reference, Here’s a The Asset URL Opensea-NFT
But Right Now, The same NFT, I can’t send any buying requests. I’m trying several NFTs. But same error. Here’s the error view:
My App Code:
import React, { useState, useEffect, useMemo } from 'react';
import { useMoralis } from 'react-moralis';
import './test.css';
function Ground() {
const {
Moralis,
user,
logout,
authenticate,
enableWeb3,
isInitialized,
isAuthenticated,
isWeb3Enabled,
} = useMoralis();
// eslint-disable-next-line
const [values, setValues] = useState({ tokenAddress: '', tokenId: '' });
const [address, setAddress] = useState('');
const [id, setId] = useState('');
const web3Account = useMemo(
() => isAuthenticated && user.get('accounts')[0],
[user, isAuthenticated]
);
const getAsset = async () => {
const res = await Moralis.Plugins.opensea.getAsset({
network: 'testnet',
tokenAddress: address,
tokenId: id,
});
console.log(res);
};
// eslint-disable-next-line
const getOrder = async () => {
const res = await Moralis.Plugins.opensea.getOrders({
network: 'testnet',
tokenAddress: values.tokenAddress,
tokenId: values.tokenId,
orderSide: 0,
page: 1, // pagination shows 20 orders each page
});
console.log(res);
};
// eslint-disable-next-line
const createSellOrder = async () => {
const expirationTime = Math.round(Date.now() / 1000 + 60 * 60 * 24);
const startAmount = 1;
const endAmount = 1;
await Moralis.Plugins.opensea.createSellOrder({
network: 'testnet',
tokenAddress: values.tokenAddress,
tokenId: values.tokenId,
tokenType: 'ERC1155',
userAddress: web3Account,
startAmount,
endAmount,
expirationTime: startAmount > endAmount && expirationTime, // Only set if you startAmount > endAmount
});
console.log('Create Sell Order Successful');
};
const createBuyOrder = async () => {
await Moralis.Plugins.opensea.createBuyOrder({
tokenAddress: address,
network: 'testnet',
tokenId: id,
tokenType: 'ERC721',
amount: 0.0001,
userAddress: web3Account,
paymentTokenAddress: '0xc778417e063141139fce010982780140aa0cd5ab',
});
console.log('Create Buy Order Successful');
};
useEffect(() => {
if (isInitialized) {
Moralis.initPlugins();
}
// eslint-disable-next-line
}, []);
useEffect(() => {
if (isAuthenticated && !isWeb3Enabled) {
enableWeb3();
}
// eslint-disable-next-line
}, [isAuthenticated]);
return (
<div className='main'>
<input
type='text'
placeholder='Contract Address'
id=''
onChange={(e) => setAddress(e.target.value)}
/>
<br />
<input
type='text'
placeholder='TokenID'
id=''
onChange={(e) => setId(e.target.value)}
/>
<br />
<ul>
<li>
<button type='button' onClick={authenticate}>
Login
</button>
</li>
<li>
<p>{web3Account}</p>
<button type='button' onClick={logout}>
Logout
</button>
</li>
<li>
<button type='button' onClick={getAsset}>
Get asset
</button>
</li>
<li>
<button type='button' onClick={createBuyOrder}>
Create Buy Order
</button>
</li>
<li>
<button type='button'>Create Sell Order</button>
</li>
</ul>
</div>
);
}
export default Ground;
Here’s My package.json File
{
"name": "i-ethereum",
"version": "0.1.0",
"private": true,
"homepage": "./",
"dependencies": {
"@reach/router": "^1.3.4",
"@tim-soft/react-spring-web": "^9.0.0-beta.36",
"@walletconnect/web3-provider": "^1.7.1",
"bootstrap": "^5.1.1",
"cra-template": "1.1.2",
"elegant-icons": "0.0.1",
"emailjs-com": "^3.2.0",
"et-line": "^1.0.1",
"ethers": "^5.5.3",
"firebase": "^9.6.3",
"font-awesome": "^4.7.0",
"moralis": "^1.1.2",
"opensea-js": "^1.2.7",
"react": "^17.0.2",
"react-awesome-reveal": "^3.8.1",
"react-bootstrap": "^1.6.3",
"react-cool-onclickoutside": "^1.6.2",
"react-dom": "^17.0.2",
"react-moralis": "^1.1.0",
"react-photo-gallery": "^8.0.0",
"react-pose": "^4.0.10",
"react-scripts": "4.0.3",
"react-select": "^4.3.1",
"react-slick": "^0.28.1",
"react-socks": "^2.2.0",
"react-spring-lightbox": "^1.6.0",
"react-tsparticles": "^1.34.0",
"sass": "^1.39.2",
"slick-carousel": "^1.8.1",
"styled-components": "^5.3.1",
"web-vitals": "^2.1.0",
"web3": "^1.6.1",
"webpack": "4.44.2"
},
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test",
"eject": "react-scripts eject"
},
"eslintConfig": {
"extends": [
"react-app",
"react-app/jest"
]
},
"browserslist": {
"production": [
">0.2%",
"not dead",
"not op_mini all"
],
"development": [
"last 1 chrome version",
"last 1 firefox version",
"last 1 safari version"
]
}
}
Can Anyone Help me out here!