Deploy Your Own Royalty Splitter Contract with BuildBear’s No-Code Deployment
This article was originally published at BuildBear Tutorials.
In this tutorial, you’ll deploy your Royalty Splitter Contract by leveraging BuildBear’s No-Code deployment and learn how it works.
BuildBear has integrated with CookBook, providing an intuitive platform for effortless contract deployment. For more details on this integration, please refer to: https://www.buildbear.io/resources/guides-and-tutorials/Cookbook_BuildBear
The Royalty Splitter contract allows for the fair distribution of payments among a group of accounts. This can be done in equal parts or based on specified percentages. The allocation is determined by assigning each account a number of shares.
When the contract receives Ether, each account can then claim a proportionate amount based on their assigned shares. The distribution of shares is established when the contract is deployed and cannot be changed afterward.
let’s deploy the contract and delve into its functionalities.
For those new to BuildBear, start by signing up at buildbear.io.
Upon logging in, you will be greeted by a page resembling the image below:
Click on the Create BuildBear Testnet option to initiate the configuration of your test blockchain. You can either fork from existing Mainnets or construct a new Testnet from scratch.
Add your Private Testnet to your MetaMask wallet by using the “Add to Metamask” button:
Next, proceed by clicking the One-Click Deploy button:
As illustrated above, BuildBear supports over 30 frequently utilized contracts. However, for the scope of this tutorial, our focus will be on the Royalty Splitter contract.
As Shown above, enter the contractor arguments. These variables are crucial in determining the distribution of payments among the participants. It is important to note that once the contract is deployed, the distribution of shares cannot be updated.
accounts
: An array containing the Ethereum addresses of the accounts to which the payments will be split. Each account represents a participant who will receive a portion of the payments.
shares
: An array specifying the number of shares assigned to each account. The distribution of shares determines the proportion of the payments that each account is entitled to claim. The total number of shares is typically calculated based on equal parts or percentages assigned to each account.
You have the choice to deploy the contract using unlocked accounts or your own wallet. Once you’ve made your selection, click on Deploy. Subsequently, follow the provided link to be directed to the contract page on the Explorer.
We transferred 100 ETH to the contract in order to test its functions using the MetaMask wallet.
Let’s claim the tokens from the contract by entering the payee’s wallet address as shown below.
Now, let’s move to the “Read the Contract” section and query the “totalReleased” function to view the total amount released.
As shown above, the contract successfully transferred the 100 ETH it received to the payee’s address as expected.
Understanding the Smart Contract
Let’s delve into how the smart contract operates.
let’s go through the functions present in the smart contract.
Write functions:
release(address payable account)
: Allows a payee to claim their releasable Ether. It transfers the Ether to the account.
release(IERC20 token, address account)
: Allows a payee to claim their releasable ERC20 token. It transfers the token to the account.
Read functions:
totalShares()
: Returns the total number of shares in the contract.
totalReleased()
: Returns the total amount of Ether released from the contract.
totalReleased(IERC20 token)
: Returns the total amount of a specific ERC20 token released from the contract.
shares(address account)
: Returns the number of shares assigned to a specific account.
released(address account)
: Returns the amount of Ether released to a specific account.
released(IERC20 token, address account)
: Returns the amount of a specific ERC20 token released to a specific account.
payee(uint256 index)
: Returns the address of a payee at a given index.
releasable(address account)
: Returns the amount of Ether that can be claimed by a specific account.
releasable(IERC20 token, address account)
: Returns the amount of a specific ERC20 token that can be claimed by a specific account.
🎉🎉 Congratulations!
You have successfully deployed a Royalty Splitter Smart Contract and gained an understanding of how the contract works.
About BuildBear:
BuildBear is a platform for testing dApps at scale, for teams. It provides users with their own private Testnet to test their smart contracts and dApps, which can be forked from any EVM chain. It also provides a Faucet, Explorer, and RPC for testing purposes.
BuildBear aims to build an ecosystem of tools for testing dApps at scale for the teams.