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
Return Value
Returns an object where each recipient address is a key and the value is the balance of that recipient.
{
[key: string]: BigNumber;
}
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
Return Value
Returns an object where each recipient address is a key and the value is the balance of that recipient.
{
[key: string]: BigNumber;
}
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
Return Value
An object containing role names as keys and an array of wallet addresses as the value.
<Record<any, string[]>>
getAllRecipients
Get all the recipients of the split contract.
const recipients = await contract.getAllRecipients();
Configuration
Return Value
{
/**
* The address of the recipient
*/
address: string;
/**
* The split of the recipient as a percentage of the total amount
*
* I.e. If a recipient has a split of 50%, and the asset sells for 100 ETH,
* the recipient will receive 50 ETH.
*/
splitPercentage: number;
}
[];
getRecipientSplitPercentage
Get the split percentage of a specific recipient.
const splitPercentage = await contract.getRecipientSplitPercentage(
"{{recipient_address}}",
);
Configuration
address
The wallet address of the recipient to check the split percentage of.
Must be a string
.
Return Value
Returns the split percentage of the recipient.
{
/**
* The address of the recipient
*/
address: string;
/**
* The split of the recipient as a percentage of the total amount
*
* I.e. If a recipient has a split of 50%, and the asset sells for 100 ETH,
* the recipient will receive 50 ETH.
*/
splitPercentage: number;
}
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
owner
The wallet address of the new owner.
Must be a string
.
const txResult = await contract.owner.set(
"{{wallet_address}}",
);
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
roles
An object containing role names as keys and an array of wallet addresses as the value.
const txResult = await contract.roles.setAll(
{
admin: ["0x12", "0x123"], // Grant these two wallets the admin role
minter: ["0x1234"], // Grant this wallet the minter role
},
);
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}}",
);