Receiving Payments

Learn how to receive payments via a smart contract.

Receive payments

We can now store addresses and split ratios inside a smart contract. Let’s update our contract so that it can also receive payments. Let’s start by writing a failing test for this:

Press + to interact
it("can receive transactions in Ether", async () => {
const Contract =
await ethers.getContractFactory(
"Partnership"
);
const [owner, person1] =
await hre.ethers.getSigners();
const addresses = [
owner.address,
person1.address,
];
const splitRatios = [1, 1];
const contract = await Contract.deploy(
addresses,
splitRatios
);
await contract.deployed();
// send ether to contract
await owner.sendTransaction({
to: contract.address,
value: ethers.utils.parseEther("1.0"),
});
});

Let’s take a look at the code above:

  • Lines 23–26: We use the owner.sendTransaction() function to send Ethers the contract from the ...