Split
When using the Split smart contract, additional top-level functionality is available to use.
To access the top-level functionality, provide the split
contract type when creating the contract instance:
const contract = await sdk.getContract(
"{{contract_address}}",
"split", // Provide the "split" contract type
);
In addition to the methods listed below, the pack contract supports the following extensions:
balanceOf
Get the amount of funds that a recipient is entitled to from the split contract.
const balance = await contract.balanceOf("{{recipient_address}}");
Configuration
balanceOfAllRecipients
Get the amount of funds that each recipient is entitled to from the split contract.
const balances = await contract.balanceOfAllRecipients();
Configuration
balanceOfToken
Get the amount of non-native tokens that a recipient is entitled to from the split contract.
const balance = await contract.balanceOfToken("{{recipient_address}}");
Configuration
balanceOfTokenAllRecipients
Get the amount of non-native tokens that each recipient is entitled to from the split contract.
const balances = await contract.balanceOfTokenAllRecipients();
Configuration
distribute
Distribute funds held by the contract in the native currency to all recipients.
const txResult = await contract.distribute();
distributeToken
Distribute funds held by the contract in a non-native currency to all recipients.
const txResult = await contract.distributeToken("{{token_contract_address}}");
Configuration
get - Owner
Retrieve the wallet address of the owner of the smart contract.
const owner = await contract.owner.get();
Configuration
get - Permissions
Get a list of wallet addresses that are members of a given role.
const members = await contract.roles.get("{{role_name}}");
Configuration
getAll - Permissions
Retrieve all of the roles and associated wallets.
const allRoles = await contract.roles.getAll();
Configuration
getAllRecipients
Get all the recipients of the split contract.
const recipients = await contract.getAllRecipients();
Configuration
getRecipientSplitPercentage
Get the split percentage of a specific recipient.
const splitPercentage = await contract.getRecipientSplitPercentage(
"{{recipient_address}}",
);
Configuration
grant - Permissions
Make a wallet a member of a given role.
const txResult = await contract.roles.grant(
"{{role_name}}",
"{{wallet_address}}",
);
Configuration
revoke - Permissions
Revoke a given role from a wallet.
const txResult = await contract.roles.revoke(
"{{role_name}}",
"{{wallet_address}}",
);
Configuration
set - Owner
Set the owner address of the contract.
const txResult = await contract.owner.set("{{wallet_address}}");
Configuration
setAll - Permissions
Overwrite all roles with new members.
This overwrites all members, INCLUDING YOUR OWN WALLET ADDRESS!
This means you can permanently remove yourself as an admin, which is non-reversible.
Please use this method with caution.
const txResult = await contract.roles.setAll({
admin: ["0x12", "0x123"],
minter: ["0x1234"],
});
Configuration
verify - Permissions
Check to see if a wallet has a set of roles.
Throws an error if the wallet does not have any of the given roles.
const verifyRole = await contract.roles.verify(
["admin", "minter"],
"{{wallet_address}}",
);
Configuration
withdraw
Withdraw funds owed to a recipient from the split contract.
const txResult = await contract.withdraw("{{recipient_address}}");
Configuration
withdrawToken
Withdraw non-native tokens owed to a recipient from the split contract.
const txResult = await contract.withdraw(
"{{recipient_address}}",
"{{token_contract_address}}",
);