rarible / sdk

MIT License
83 stars 43 forks source link

Several doc + code examples are not working #649

Open kasper-keunen opened 1 month ago

kasper-keunen commented 1 month ago

Have spent about 2 days hitting my head against the sdk and following examples / readme but apart from being able to read nft market data have been unable to get any write transactions through and since i need to access this sdk to be able to handle a nft ticketing market this is highly annoying.

I will give a few examples, for starters this "Example Application": https://docs.rarible.org/reference/example-application. If you follow the instructions; so clone/pull the sdk and then run yarn install --ignore-engines && yarn bootstrap && yarn build-all. You get the following error:

Screenshot 2024-07-22 at 22 18 19

In this example application: https://example.rarible.org/connect contains a lot of dead links like this one: https://github.com/rarible/sdk/tree/master/packages/connector. Then the deploy/create collection example uses what i think is a dated/old way of creating a collection. The example dapp works, but replicating it is not possible as out of the box createCollction doesn't work.

Screenshot 2024-07-22 at 22 47 07

Then this instruction in the readme on how to create a collection: https://docs.rarible.org/reference/create-collection seems to require CreateCollectionRequestSimplified but this seems to be depreciated? Its hard to tell - what is certain that the example as shown doesn't work.

Screenshot 2024-07-22 at 22 22 56

Then in the sdk documetation on github: https://github.com/rarible/sdk this example on creating an collection is given:

const { address, tx } = await sdk.nft.createCollection({
    blockchain: Blockchain.ETHEREUM,
    type: "ERC721",
    name: "name",
    symbol: "RARI",
    baseURI: "https://ipfs.rarible.com",
    contractURI: "https://ipfs.rarible.com",
    isPublic: true,
})

Running this gives the following error: Screenshot 2024-07-22 at 22 32 51

And if i then try to use the EVMBlockchain type it doesn't work either. Have no clue what is going on.

Over the last days i have run into more problems but these are the most recent blockers.

As a dev myself i fully understand that updating docs is not fun and it is bound to happen that stuff gets outdated - so honestly that by itself is not a problem. That being said i seem unable to get it to work whatever i do - would be great if there would be at least a working example. I am pretty sure that once all set up the SDK should work great but it seems kind of rough getting a working config/setup on the rails.

Finally i was wondering if wagmi/viem support is coming soon? I noticed in a previous github issue that this addition was planned to be added in march (a few months back). Would be great to know where it stands.

kasper-keunen commented 1 month ago

Will provide a example of my configuration/script (simplied) so it is easier to access what is going on. This is my package.json:


{
    "name": "woosh",
    "version": "1.0.0",
    "main": "index.ts",
    "scripts": {
        "test": "echo \"Error: no test specified\" && exit 1"
    },
    "keywords": [],
    "author": "",
    "license": "ISC",
    "description": "",
    "dependencies": {
        "@rarible/api-client": "0.16.5-alpha.13",
        "@rarible/sdk": "^0.13.68-fix.39",
        "@rarible/sdk-wallet": "^0.13.68-fix.39",
        "@rarible/types": "^0.10.0-alpha.42",
        "@rarible/web3-ethereum": "^0.13.68-fix.39",
        "@types/node": "^18.0.0",
        "dotenv": "16.0.0",
        "ethers": "5.6.2",
        "ts-node": "^10.9.2",
        "tslib": "2.3.1",
        "typescript": "^5.4.5",
        "web3": "1.5.0"
    }
}

So as you can see i already downgraded the packages to what i find in the sdk repo/docs. Then this simple script where i just want to deploy a collection on Polygon. Mind you i did also try this with ethers but get the same error. Of course i have tried pretty much all package versions at this point.

import { createRaribleSdk } from "@rarible/sdk";
import { toUnionAddress } from "@rarible/types";
import { Blockchain } from "@rarible/api-client";
import { EthereumWallet } from "@rarible/sdk-wallet";
import { Web3Ethereum } from "@rarible/web3-ethereum"
import Web3 from "web3"

const PRIVATE_KEY = "XXXX"
const POLYGON_RPC_URL = 'https://polygon-mainnet.infura.io/v3/XXXX';
const provider = new Web3.providers.HttpProvider(POLYGON_RPC_URL);
const web3 = new Web3(provider);

const wallet = web3.eth.accounts.privateKeyToAccount(PRIVATE_KEY);
const web3Ethereum = new Web3Ethereum({ web3, from: wallet.address });
const ethereumWallet = new EthereumWallet(web3Ethereum);

async function main() {
    const sdk = createRaribleSdk(ethereumWallet, "prod");

    const { address, tx } = await sdk.nft.createCollection({
        blockchain: Blockchain.POLYGON,
        type: "ERC721",
        name: "My Polygon Collection",
        symbol: "MPC",
        baseURI: "https://example.com/metadata/",
        contractURI: "https://example.com/contract-metadata/",
        isPublic: false,
        operators: [toUnionAddress(`POLYGON:${wallet.address}`)], // Convert to UnionAddress
    });
}

main().catch((error) => {
    console.error(error);
    process.exit(1);
});

/**
 * npx ts-node createCollection.ts
 */

This results in the following error:

Screenshot 2024-07-23 at 14 47 38

What would be the issue here?

kasper-keunen commented 1 month ago

So i want to test the SDK in the backend context as that will be the way we would be issuing the tickets on primary/secondary market, so that is this part of the SDK: https://github.com/rarible/sdk/tree/master/packages/sdk-examples/src/backend

Running that code 'out of the box' so basically adding the private key and rpc results in this error:

Screenshot 2024-07-23 at 18 13 35

Trying to solve this by trying to solve the version conflics (tbh not even sure if that is the core of the issue but i suspect so) doesn't work.

This own script:


import { EthereumWallet } from "@rarible/sdk-wallet"
import { createRaribleSdk } from "@rarible/sdk";
import { ethers } from "ethers"
import { EthersEthereum } from "@rarible/ethers-ethereum"
import { Blockchain } from "@rarible/api-client";
import { toUnionAddress } from "@rarible/types";

export function updateNodeGlobalVars() {
    (global as any).FormData = FormData;
    (global as any).window = {
        fetch: fetch,
        dispatchEvent: () => { },
    };
    (global as any).CustomEvent = function CustomEvent() {
        return
    }
}

updateNodeGlobalVars();

const PRIVATE_KEY = "XXXX"
const POLYGON_RPC_URL = 'https://polygon-mainnet.infura.io/v3/XXXXX';

const OPERATOR_ADDRESS = "XXX"

// Setup with ethers (same as for ethereum)
const raribleEthers = new ethers.providers.JsonRpcProvider(POLYGON_RPC_URL)
const raribleProvider = new EthersEthereum(new ethers.Wallet(PRIVATE_KEY, raribleEthers))
const raribleWallet = new EthereumWallet(raribleProvider)
const raribleSdkWithEthers = createRaribleSdk(raribleWallet, "prod", { apiKey: "XXXXX" })

async function main() {

    const { address, tx } = await raribleSdkWithEthers.nft.createCollection({
        blockchain: Blockchain.POLYGON,
        type: "ERC721",
        name: "My Polygon Collection",
        symbol: "MPC",
        baseURI: "https://example.com/metadata/",
        contractURI: "https://example.com/contract-metadata/",
        isPublic: false,
        operators: [toUnionAddress(`POLYGON:${OPERATOR_ADDRESS}`)], // Convert to UnionAddress
    });
}

main().catch((error) => {
    console.error(error);
    process.exit(1);
});

/**
 * npx ts-node createCollectionBackend.ts
 * npx tsc createCollectionBackend.ts
 */

Screenshot 2024-07-23 at 18 18 19

This is my package.json


{
    "name": "woosh",
    "version": "1.0.0",
    "main": "index.ts",
    "scripts": {
        "test": "echo \"Error: no test specified\" && exit 1"
    },
    "keywords": [],
    "author": "",
    "license": "ISC",
    "description": "",
    "dependencies": {
        "@rarible/api-client": "0.16.5-alpha.13",
        "@rarible/sdk": "^0.13.68-fix.39",
        "@rarible/sdk-wallet": "^0.13.68-fix.39",
        "@rarible/types": "^0.10.0-alpha.42",
        "@types/node": "^18.0.0",
        "dotenv": "16.0.0",
        "ethers": "5.6.2",
        "form-data": "^4.0.0",
        "node-fetch": "^3.3.2",
        "ts-node": "^10.9.2",
        "tslib": "2.3.1",
        "typescript": "^5.4.5"
    }
}

Going to stop the spam here - i am sorry for being so difficult - if this is all me making/misunderstanding i would love to know as well. In fact i am hoping this is all me being incredibly dense/dumb. Clearly this SDK does work as it is used a lot and at scale. If I was rude in previous messages i do apologize i was just very frustrated getting it to work - again i do know that the SDK is solid and complete - but for some reason i am unable to get it to work.

In the end i am quite convinced that the source of these problems is a single line/config somewhere. I will now halt my own efforts i did ask a few in my team to verify independely of these issues. Hope we can get this unblocked soon!