How to implement the proposal validation?
Here we will see how a buyer can validate a proposal with the createTransaction function.
Good to Know
In this example, we will use reactJS, Ether.js and formik to handle the form on the frontend. You will find a full code example with all imports at the end of tutorial.
① The proposal validation process
To validate a proposal the buyer have to send the validated amount to the escrow contract, in our Dapp, this step happen by clicking on the validate proposal button in the ValidateProposalModal
component.
But let's see how the process is organized
1 - ServiceDetail
component : you will have in this component the mapping of all proposal, it use the ProposalItem
component.
2-ProposalItem
component : this component will display all the proposal details and it use the ValidateProposalModal
3-ValidateProposalModal
component : this component will display a modal with all the information of the proposal, including the fee's summary, total, account balance
Validate proposal button : on submit, it will call ValidateProposal function
Decline button : used to decline a proposal
Contact the seller button : used to contact and chat with the seller with the xmtp decentralized instant message service
Let's focus on ValidateProposalModal
component
4-ValidateProposal
component : this component is the core of the proposal validation process.
As you can see below it take a few parameter
signer: Signer
: This parameter is of typeSigner
and is required. It represents the Ethereum account that will sign the transaction.provider: Provider
: This parameter is of typeProvider
and is required. It represents the Ethereum network provider that will be used to submit the transaction.serviceId: string
: This parameter is of typestring
and is required. It represents the ID of the service concerned by the proposal.proposalId: string
: This parameter is of typestring
and is required. It represents the ID of the proposal that is being validated.rateToken: string
: This parameter is of typestring
and is required. It represents the address of the ERC-20 token that is being used to pay for the service. If this is set toethers.constants.AddressZero
, then the payment is being made in Ethercid: string
: This parameter is of typestring
and is required. It represents the IPFS CID of the evidence that is being used to validate the proposal.value: ethers.BigNumber
: This parameter is of typeethers.BigNumber
and is required. It represents the amount of tokens or that is being used to pay for the service.
Then you have the createTranscation
call, the proposal will be validated as soon as the transcation is validated
==> If the used token is ETH then the createTransaction is directly call with the right parameter
==> If the token is another ERC-20 token then you have have to pass trought a few more validation step as
Check the ERC-20 token balance
Check the token allowance
Then we can create the new createTransaction
See the Full Code Implemented on Our Demo DAPP
Last updated