Deploying Rev Splitter contract.
ethersjs
Installation instructions
First, install this package via the command below.
npm i @agreewe/revenue-splitter-eth-sdk
Get Deployment Cost
import { getDeploymentCostEstimate, DeploymentArgs } from '@agreewe/revenue-splitter-eth-sdk';
const params: DeploymentArgs = {
members: [
"ETH_WALLET_ADDRESS_MEMBER_1",
"ETH_WALLET_ADDRESS_MEMBER_2",
],
shares: [50, 50],
uuid: '697b36a1-864c-4f7c-b76a-91d44bfa0928'
};
/**
* @param provider - connected wallet provider
* @param params - deploymentArgs used to deploy the contract, instance of
* DeploymentArgs
*/
const feeEstimate = await getDeploymentCostEstimate(
deploymentWallet,
params
);
Deploy Transaction
import { deployContract, DeploymentArgs } from '@agreewe/revenue-splitter-eth-sdk';
const params: DeploymentArgs = {
members: [
"ETH_WALLET_ADDRESS_MEMBER_1",
"ETH_WALLET_ADDRESS_MEMBER_2",
],
shares: [50, 50],
uuid: '697b36a1-864c-4f7c-b76a-91d44bfa0928'
};
// // use ethers.js to create a wallet instance or pass injected wallet instance
// const deploymentWallet = new ethers.Wallet(
// "PRIVATE_KEY",
// new ethers.providers.JsonRpcProvider("http://localhost:8545")
// );
const txHash=
await deployContract(
provider,
params
)
Interact with contract
import { RevenueSplitter } from '@agreewe/revenue-splitter-eth-sdk';
/*
* @param contractAddress - Address of the deployed contract
* @param deploymentWallet - Wallet instance used to interact with the contract
*/
const revSplitterInstance = new RevenueSplitter(
contractAddress,
deploymentWallet
);
const provider = new ethers.providers.Web3Provider(window.ethereum);
const balance = await provider.getBalance(contractAddress);
const balanceETH = ethers.utils.formatEther(balance);
//distribute all
const distributeTx = await revSplitterInstance.distributeAll();
console.log(distributeTx);