thirdweb

Splits Code Examples

Last updated:

February 10, 2022

Easy copy and paste snippets to use thirdweb Splits module

Deploying a splits module

const app = sdk.getAppModule("<APP_MODULE_ADDRESS>"); const deploySplitModule = async () => { try { const splitsModule = await app.deploySplitsModule({ name: "Splits", description: "Splits Module", // Array of recipients and the shares we want to split with // the total number of shares = 5 // therefore `<RECIPIENT_ADDRESS_1>` will recieve 20% of the royalties // and `<RECIPIENT_ADDRESS_2>` will recieve 80% of the royalties recipientSplits: [ { address: "<RECIPIENT_ADDRESS_1>", shares: 1, }, { address: "<RECIPIENT_ADDRESS_2>", shares: 4, }, ], }); // In order to use a splits module, you must set it as the // recipient when deploying a module await app.deployNftModule({ name: "My NFT", symbol: "NFT", sellerFeeBasisPoints: 0, // use the address of the splits module as the recipient. feeRecipient: splitsModule.address, }); } catch (err) { console.log(err); } } deploySplitModule() // `feeRecipient` will be the address of the Splits module

Deploying a royalty splits module

Note: Minimum version needed from the sdk is @3rdweb/sdk@1.39.0

const deployRoyaltySplitsModule = async () => { try { await app.deployRoyaltySplitsModule({ name: "Royalty Split", description: "Royalty Splits Module", // Array of recipients and the shares we want to split with // the total number of shares = 5 // therefore `<RECIPIENT_ADDRESS_1>` will recieve 20% of the royalties // and `<RECIPIENT_ADDRESS_2>` will recieve 80% of the royalties recipientSplits: [ { address: "<RECIPIENT_ADDRESS_1>", shares: 1, }, { address: "<RECIPIENT_ADDRESS_2>", shares: 4, }, ], }); } catch (error) { console.log(error); } }; deployRoyaltySplitsModule();

Changing the royalty recipient address of an existing module

Replace <APP_MODULE_ADDRESS> with the address of the app under the NFT Collection module was created.

Replace <ROYALTY_SPLITS_ADDRESS> with the new recipient address, it needs to be a Royalty Splits module module.

const changeRecipient = async () => { // Updating the fee recipient requires the use of the app module // that the target module is deployed in const appModule = sdk.getAppModule("<APP_MODULE_ADDRESS>"); await appModule.setModuleRoyaltyTreasury("<MODULE_ADDRESS>", "<ROYALTY_SPLITS_ADDRESS>"); } changeRecipient()

Withdraw

const withdraw = async (walletAddress) => { try { await splits.withdraw(walletAddress); } catch (error) { console.log('Failed to withdraw. Error: ', error); } }; withdraw('<WALLET_ADDRESS>');

Get Recipient Split Percentages

const getRecipientSplitPercentages = async (walletAddress) => { try { await splits.getRecipientSplitPercentage(walletAddress); } catch (error) { console.log('Failed to get split percentages. Error: ', error); } }; getRecipientSplitPercentages('<WALLET_ADDRESS>');

Get All Recipients

const getAllRecipients = async () => { try { await splits.getAllRecipients(); } catch (error) { console.log('Failed to get all recipients. Error: ', error); } }; getAllRecipients();

Get

const get = async () => { try { await splits.get(); } catch (error) { console.log('Failed to get. Error: ', error); } }; get();

Distribute

const distribute = async () => { try { await splits.distribute(); } catch (error) { console.log('Failed to distribute. Error: ', error); } }; distribute();

Get Balance of Tokens for all Recipients

const getBalanceOfTokenForAllRecipients = async (tokenAddress) => { try { await splits.balanceOfTokenAllRecipients(tokenAddress); } catch (error) { console.log( 'Failed to get balances of a token for all recipients: ', error ); } }; getBalanceOfTokenForAllRecipients('<TOKEN_ADDRESS>');

Get Balance of Token

const getBalanceOfToken = async (walletAddress, tokenAddress) => { try { await splits.balanceOfToken(walletAddress, tokenAddress); } catch (error) { console.log('Failed to get balance of token for wallet. Error: ', error); } }; getBalanceOfToken('<WALLET_ADDRESS>', '<TOKEN_ADDRESS>');

Get Balance of All Recipients

const getBalanceOfAllRecipients = async () => { try { await splits.balanceOfAllRecipients(); } catch (error) { console.log('Failed to get balance of all recipients: ', error); } }; getBalanceOfAllRecipients();

Get Balance of

const getBalanceOf = async (walletAddress) => { try { await splits.balanceOf(walletAddress); } catch (error) { console.log('Failed to get get balance of address. Error: ', error); } }; getBalanceOf('<WALLET_ADDRESS');

Ready to build your first web3 app? Get early access & add web3 features to your project today.

Contents

Deploying a splits module

Deploying a royalty splits module

Changing the royalty recipient address of an existing module

Withdraw

Get Recipient Split Percentages

Get All Recipients

Get

Distribute

Get Balance of Tokens for all Recipients

Get Balance of Token

Get Balance of All Recipients

Get Balance of