0.6.10 • Published 2 years ago

@omnite/sdk v0.6.10

Weekly downloads
-
License
ISC
Repository
-
Last release
2 years ago

Omnite SDK

API docs

API documentation is available under docs/index.html.

Facets

Available facets (FacetName enum) with required params:

{
    DiamondCutFacetOnlyOwnerAccess: undefined;
    DiamondCutWithOmniteSignature: undefined;
    DiamondLoupeFacet: undefined;
    ERC2981CollectionOwnerFacet: [
        {
            type: 'address',
            desc: 'Royalty receiver',
        },
        {
            type: 'uint256',
            desc: 'Royalty Fraction',
        },
        {
            type: 'uint256',
            desc: 'Fee denominator',
        },
    ];
    ERC4907Facet: undefined;
    ERC721BaseTokenURIFacet: [
        {
            type: 'string',
            desc: 'Base token uri for tokens',
        },
    ];
    ERC721ContractURI: [
        {
            type: 'string',
            desc: ' ContractURI of the contract',
        },
    ];
    ERC721ContractURIFacet: undefined;
    ERC721CoreFacet: [];
    ERC721MinterRoleMintableFacet: [
        {
            type: 'address[]',
            desc: 'Addresses',
        },
    ];
    ERC721OwnerMintableFacet: undefined;
    ERC721OwnerMintableWithTokenURIFacet: undefined;
    ERC721TokenURIFacet: undefined;
    ERC721TransferableFacet: undefined;
}

Examples

You can find more complete examples in examples directory.

Initialize (required for package to work)

await config.initialize({
    supportedChains: [
        // supported chains for project
        ChainId.BSCT,
        ChainId.RINKEBY,
    ],
    providerRpcUrls: {
        // taken from https://chainlist.org/, private RPC URLs can be used too
        [ChainId.BSCT]: 'https://data-seed-prebsc-1-s1.binance.org:8545/',
        [ChainId.RINKEBY]:
            'https://rinkeby.infura.io/v3/9aa3d95b3bc440fa88ea12eaa4456161',
    },
});

Local deployment

const collectionCreator = new CollectionCreator({
    sourceChainId: chainId,
    senderAddress: '0x21453911eb364c7DF9291d2f427fd04Fa7234667',
    deployData: {
        collectionName,
        collectionTicker: 'TC11',
        userAddress: '0x21453911eb364c7DF9291d2f427fd04Fa7234667',
    },
    facets: [
        {
            name: FacetName.ERC721TokenURIFacet,
            initializeParams: ['ipfs://url/'], // initialize params for ERC721TokenURIFacet
        },
        {
            name: FacetName.ERC721ContractURI,
            initializeParams: ['ipfs://contractUri'], // initialize params for ERC721ContractURI
        },
    ],
    deployBroker: BridgeBroker.LayerZero,
    networks: [{ amount: 10, chainId: chainId }],
});

collectionCreator.baseTokenUri =
    'ipfs://QmNNvuUaB5cd8mP7oMhcEeax1AMSHcWfp2GzY3YfoZJLD3/'; // base token uri, will be concatenated with token id if tokenURI is requested. Eg. ipfs://QmNNvuUaB5cd8mP7oMhcEeax1AMSHcWfp2GzY3YfoZJLD3/11 for tokenId 11

const unsignedTx = await collectionCreator.deploy(); // if signer is not provided as parameter, then unsigned tx is returned
const result = await wallet.sendTransaction(unsignedTx);
await result.wait(); // wait for the tx to be confirmed once

Facet params

    DiamondCutFacetOnlyOwnerAccess: undefined;
    ERC721CoreFacet: [];
    ERC721MinterRoleMintableFacet: [Array<string>];
    ERC721OwnerMintableFacet: undefined;
    ERC721TokenURIFacet: undefined;
    ERC721BaseTokenURIFacet: [string];
    ERC721TransferableFacet: undefined;
    DiamondLoupeFacetv2: undefined;
    ERC721ContractURI: [string];
    ERC721OwnerMintableWithTokenURIFacet: undefined;

Local minting

// Initialize collection
const collection = new Collection({
   {
    chainId: ChainId.BSCT, // chain id of network you want to operate on
    collectionAddress: '0x93760dd3cfda89c7bc01b1cd931419c7c8d86907', // contract address on network above
    senderAddress: '0x21453911eb364c7DF9291d2f427fd04Fa7234667', // sender address
    }
});

// Execute mint for myself (mintTo parameter is not provided, it'll use signer address)
const mintUnsignedTx = await collection.mint(
    1,
    'QmNNvuUaB5cd8mP7oMhcEeax1AMSHcWfp2GzY3YfoZJLD3'
);

const mintResult = await wallet.sendTransaction(mintResult);
console.log('Tx hash:', mintResult.hash);

// Mint another token for Vitalik (mintTo parameter is provided);
const vitalikMintUnsignedTx = await collection.mint(
    2,
    '0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045'
);

// We need to sign transaction and send it with our signer (as wallet here)
await wallet.sendTransaction(vitalikMintUnsignedTx);

const vitalikMintResult = await wallet.sendTransaction(vitalikMintUnsignedTx);
console.log('Tx hash:', vitalikMintResult.hash);

Local minting with token URI

// Initialize collection
const collection = new Collection({
   {
    chainId: ChainId.BSCT, // chain id of network you want to operate on
    collectionAddress: '0x93760dd3cfda89c7bc01b1cd931419c7c8d86907', // contract address on network above
    senderAddress: '0x21453911eb364c7DF9291d2f427fd04Fa7234667', // sender address
    }
});

// Execute mint for myself (mintTo parameter is not provided, it'll use signer address)
const mintUnsignedTx = await collection.mint(
    1,
    'QmNNvuUaB5cd8mP7oMhcEeax1AMSHcWfp2GzY3YfoZJLD3'
);

const mintResult = await wallet.sendTransaction(mintResult);
console.log('Tx hash:', mintResult.hash);

// Mint another token for Vitalik (mintTo parameter is provided);
const vitalikMintUnsignedTx = await collection.mintToWithTokenURI(
    2, // token id
    '0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045', // mint receiver
    'ipfs://QmNNvuUaB5cd8mP7oMhcEeax1AMSHcWfp2GzY3YfoZJLD3' // tokenURI, used if no baseTokenUri is defined for collection
);

// We need to sign transaction and send it with our signer (as wallet here)
await wallet.sendTransaction(vitalikMintUnsignedTx);

const vitalikMintResult = await wallet.sendTransaction(vitalikMintUnsignedTx);
console.log('Tx hash:', vitalikMintResult.hash);

Get all user collections

const collections = await Wallet.getUserCollections(address);

// Returns
collections = [
    {
        address: {
            '0x4': '0x694505a3fA42F315A4Ee0510c58DAC4c2284876e',
            '0x61': '0x93760dD3CFDa89C7bc01b1Cd931419c7c8d86907',
        }, // Record<ChainId, string> - address on another chain
        name: 'OmniCollection', // collection name
        id: '0x1557f36e46a2d0d492e756f4a41d3f6ffbc6bb9e670a6fab65c5676c4bfdec80', // collection id
        availableBrokers: ['axelar', 'layerZero'], // available brokers, BridgeBroker enum values: [BridgeBroker.Axelar, BridgeBroker.LayerZero]
        image: null, // image url or string if there is no contract metadata
        description: '', // collection description, empty if there is no contract metadata
        creationDate: '2022-09-12T11:20:15.181Z', // contract creation date as Date object
    },
];

Get current collection facets

const currentFacets = await Collection.getFacets(
    chainId,
    sourceCollectionAddress
);

currentFacets = [
    {
        name: 'DiamondCutFacetOnlyOwnerAccess', // FacetName
        tags: ['Default'], // Array<FacetTag>
    },
    {
        name: 'DiamondLoupeFacetv2',
        tags: ['Default'],
    },
    {
        name: 'ERC721TransferableFacet',
        tags: ['Default', 'Transfer'],
    },
    {
        name: 'ERC721BaseTokenURIFacet',
        tags: ['Metadata'],
    },
    {
        name: 'ERC721CoreFacet',
        tags: ['ERC721Core'],
    },
];

Add diamond facet to collection

const collection = new Collection({
    chainId: ChainId.BSCT, // chain id of network you want to operate on
    collectionAddress: '0x93760dd3cfda89c7bc01b1cd931419c7c8d86907', // contract address on network above
    senderAddress: '0x21453911eb364c7DF9291d2f427fd04Fa7234667', // sender address
});

const receipt = await wallet.sendTransaction(
    await collection.addFacet(FacetName.ERC721TokenURIFacet) // Add ERC721TokenURIFacet facet to the collection
);
await receipt.wait();

Remove diamond facet from collection

const collection = new Collection({
    chainId: ChainId.BSCT, // chain id of network you want to operate on
    collectionAddress: '0x93760dd3cfda89c7bc01b1cd931419c7c8d86907', // contract address on network above
    senderAddress: '0x21453911eb364c7DF9291d2f427fd04Fa7234667', // sender address
});

const receipt = await wallet.sendTransaction(
    await collection.removeFacet(FacetName.ERC721TokenURIFacet) // Remove ERC721TokenURIFacet facet from the collection
);
await receipt.wait();

Add and remove diamond facet from collection in one tx

const collection = new Collection({
    chainId: ChainId.BSCT, // chain id of network you want to operate on
    collectionAddress: '0x93760dd3cfda89c7bc01b1cd931419c7c8d86907', // contract address on network above
    senderAddress: '0x21453911eb364c7DF9291d2f427fd04Fa7234667', // sender address
});

const unsignedTx = await collection.editFacets(
    [FacetName.ERC721TransferableFacet], // add ERC721TransferableFacet to the collection
    [FacetName.ERC721TokenURIFacet] // remove ERC721TokenURIFacet from the collection
);
const receipt = await wallet.sendTransaction(unsignedTx);
await receipt.wait();

Get all available facets

const facets = await Diamond.getAvailableFacets(chainId);

facets = [
    {
        name: 'DiamondCutFacetOnlyOwnerAccess', // FacetName
        tags: ['Default'], // Array<FacetTag>
        address: '0x377ab91429907c25c294d9080Bcf822fb4c3A0c6', // Contract address for given chain
    },
    {
        name: 'ERC721CoreFacet',
        tags: ['ERC721Core'],
        address: '0xd42Adf40aF93Ae7DDd1627a982A861ff8e1337ed',
    },
    {
        name: 'ERC721MinterRoleMintableFacet',
        tags: ['Minting'],
        address: '0xe8f2D4b2044084d4D3F4ADbF0A05bF58E5A66C86',
    },
    {
        name: 'ERC721OwnerMintableFacet',
        tags: ['Minting'],
        address: '0xE7814b05611e00dEd99601Fd4d8Fe9bc652849Ff',
    },
    {
        name: 'ERC721TokenURIFacet',
        tags: ['Metadata'],
        address: '0xce775FB20641E8F4953Af6c20aEE6eCA8C430415',
    },
    {
        name: 'ERC721TransferableFacet',
        tags: ['Default', 'Transfer'],
        address: '0x7DB0D800859Ea85fa2C104D21870d231D7bEE5d8',
    },
    {
        name: 'DiamondLoupeFacetv2',
        tags: ['Default'],
        address: '0xa7bc05483ef820Df1E0b66F97F45BA6c3E60E9C4',
    },
    {
        name: 'ERC721ContractURI',
        tags: ['Default'],
        address: '0x6363dB59bd149d0f6779B100Cc7d18c632e32923',
    },
    {
        name: 'ERC721OwnerMintableWithTokenURIFacet',
        tags: ['Minting'],
        address: '0x8eEb29354Ce5058f421761256Ec51b662863024f',
    },
    {
        name: 'ERC721BaseTokenURIFacet',
        tags: ['Metadata'],
        address: '0x6313Caa8C1DA125c1f7E94F41cdFb64aebF8DFd4',
    },
];
0.6.7

2 years ago

0.6.6

2 years ago

0.6.9

2 years ago

0.6.8

2 years ago

0.6.10

2 years ago

0.6.3

2 years ago

0.6.2

2 years ago

0.6.5

2 years ago

0.6.4

2 years ago

0.6.1

2 years ago

0.6.0

2 years ago

0.5.1

2 years ago

0.5.0

2 years ago

0.4.2

2 years ago

0.4.1

2 years ago

0.4.0

2 years ago

0.3.2

2 years ago

0.3.1

2 years ago

0.3.0

2 years ago

0.2.0

2 years ago

0.1.12

2 years ago

0.1.11

2 years ago

0.1.10

2 years ago

0.1.9

2 years ago

0.1.8

2 years ago

0.1.7

2 years ago

0.1.6

2 years ago

0.1.5

2 years ago

0.1.4

2 years ago

0.1.3

2 years ago

0.1.2

2 years ago