Sending Invitation Payments using an Address
In this document, we'll explain how to send a payment to someone using their agoric1... address from an Agoric smart contract using a deposit facet.
Using a depositFacet
Let's take a look at the following code snippet from the Swaparoo contract:
const secondDepositFacet = await E(depositFacetFromAddr).lookup(
secondPartyAddress,
'depositFacet',
);
await E(secondDepositFacet).receive(secondSeatInvitation);
return 'invitation sent';Step-by-Step Explanation
Retrieving the Deposit Facet:
depositFacetFromAddris an object that provides a lookup function for deposit facets associated with addresses. The Swaparoo contract is provided with anamesByAddressAdminby the proposal (swaparoo.proposal.js). The contract makesdepositFacetFromAddrusingfixHub().- An example of an address might be
agoric1ydzxwh6f893jvpaslmaz6l8j2ulup9a7x8qvvq.
- An example of an address might be
- The lookup function is called with
secondPartyAddressand'depositFacet'as arguments to retrieve the deposit facet associated with thesecondPartyAddress. - The resulting deposit facet is stored in the
secondDepositFacetvariable.
Making the Payment:
secondDepositFacetrepresents the deposit facet obtained in the previous step.- The
receivemethod is called onsecondDepositFacet, passingsecondSeatInvitationas an argument. secondSeatInvitationis an Invitation to participate in the second seat (recall that invitations are payments).- Since
receiveis another asynchronous operation, theawaitkeyword is again used to wait for it to complete. - By calling
receiveon the deposit facet withsecondSeatInvitation, the payment represented bysecondSeatInvitationis transferred or deposited into a purse associated withsecondDepositFacet.
Returning a Result:
- After the payment has been successfully made by calling
receive, the function returns the string'invitation sent'to indicate that the invitation has been sent.
Deposit Facets in Agoric
In the Agoric smart contract framework, deposit facets are used as a way to transfer and manage digital assets and payments between parties. By calling the receive method on a deposit facet and passing in a payment or offer, the smart contract can deposit or transfer assets into the account associated with that facet.
Deposit facets provide an abstraction layer for handling payments and ensure that the transfers are performed securely and reliably within the smart contract.
Video Walkthrough
As you're going through this tutorial it may be helpful to watch this video walkthrough.