我正在通过参考其示例 OpenSea Creatures 来学习如何在 Node.js(可在此处找到)中使用 OpenSea SDK。SDK 链接到一个已有两年历史的分支,但我使用的是master 分支。
我正在尝试创建一个工厂,可以部署从中铸造代币的合同。出于测试目的,我让我的工厂部署 Creatures 合约,这是我的 Solidity 代码:
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
import "@openzeppelin/contracts/access/Ownable.sol";
import "./ERC721Tradable.sol";
contract NFTContractFactory is Ownable
{
event ContractCreated(address addr);
function createContract(string memory name, string memory symbol)
public onlyOwner
{
Creature nc = new Creature(name, symbol, owner());
nc.transferOwnership(msg.sender);
emit ContractCreated(address(nc));
}
}
contract Creature is ERC721Tradable {
constructor(string memory _name, string memory _symbol, address _proxyRegistryAddress)
ERC721Tradable(_name, _symbol, _proxyRegistryAddress)
{}
function baseTokenURI() override public pure returns (string memory) {
return "https://creatures-api.opensea.io/api/creature/";
}
function contractURI() public pure returns (string memory) {
return "https://creatures-api.opensea.io/contract/opensea-creatures";
}
}
ERC721Tradable.sol
可以在这里找到。我对Creature
合同所做的唯一更改是将其名称和符号从工厂传递过来。
我在以下地址部署了这些合约的样本:
- NFTContractFactory:
0xbc2e680be967834a5f6fd72ac9e2b0251f28b2a8
- 生物:
0x5126c9f90a18c197dc8964ea477d63bcfbef97ab
,0xf9473fa26c4631dcd2ee1c7ad50e0c3545ff35a7
,0x5c7f60d78774f81989b262da785daf7b6a2aed2b
这是我的测试脚本:
const Web3 = require('web3')
const OpenSea = require('opensea-js')
const OpenSeaPort = OpenSea.OpenSeaPort
const Network = OpenSea.Network
const MnemonicWalletSubprovider = require("@0x/subproviders").MnemonicWalletSubprovider;
const MNEMONIC = 'my metamask wallet mnemonic'
const BASE_DERIVATION_PATH = `44'/60'/0'/0`;
const mnemonicWalletSubprovider = new MnemonicWalletSubprovider({
mnemonic: MNEMONIC,
baseDerivationPath: BASE_DERIVATION_PATH,
});
const RPCSubprovider = require("web3-provider-engine/subproviders/rpc");
const alchemyRpcSubprovider = new RPCSubprovider("my alchemy rinkeby endpoint");
const Web3ProviderEngine = require("web3-provider-engine");
const providerEngine = new Web3ProviderEngine();
providerEngine.addProvider(mnemonicWalletSubprovider);
providerEngine.addProvider(alchemyRpcSubprovider);
providerEngine.start();
const seaport = new OpenSeaPort(
providerEngine,
{
networkName: Network.Rinkeby,
apiKey: ""
},
(arg) => console.log(arg)
);
async function main() {
// Expire this auction one day from now. Note that we convert from the JavaScript timestamp (milliseconds):
const expirationTime = Math.round(Date.now() / 1000 + 60 * 60 * 24)
const assetPromise = seaport.api.getAsset({
tokenAddress: '0xf9473fa26c4631dcd2ee1c7ad50e0c3545ff35a7',
tokenId: '1',
})
assetPromise.then(asset => {
console.log(asset);
const sellOrderPromise = seaport.createSellOrder({
asset,
accountAddress: 'my address',
startAmount: 3,
// If `endAmount` is specified, the order will decline in value to that amount until `expirationTime`. Otherwise, it's a fixed-price order:
endAmount: 0.1,
expirationTime
});
sellOrderPromise.then(order => console.log(order)).catch(error => console.log(error));
});
}
main()
不幸的是,我的测试输出仅包含该行的令牌信息console.log(asset);
;我什至没有看到最终订单或任何错误,也没有看到我的列表正在创建。我不知道如何解决这个问题,所以如果有人能从这里指出我正确的方向,我将非常感激。
Edit1:添加.catch(error => console.log(error));
以捕获任何错误,但仍然没有!
Edit2:似乎我不是唯一一个无声失败的人?问题在这里