Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create explainer for postal service contract #1106

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion main/.vitepress/config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -446,11 +446,16 @@ export default defineConfig({
text: 'Takeaway 2: Swaparoo Contract Overview',
link: '/guides/getting-started/swaparoo-how-to-swap-assets-explainer',
},

{
text: 'Takeaway 3: Sending Invitation Payments using an Address',
link: '/guides/getting-started/swaparoo-making-a-payment-explainer',
},

{
text: 'Takeaway 4: Postal Service Contract Overview',
link: '/guides/getting-started/postal-service-contract-explainer',
},
],
},
{
Expand Down
64 changes: 64 additions & 0 deletions main/guides/getting-started/postal-service-contract-explainer.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
# Understanding the Agoric Postal Service Contract

This contract is implemented using the Zoe Contract Facet (ZCF) and demonstrates how to create and manage a basic postal service. Let's break down the main components and functionalities of this contract.

## Contract Structure and Components
## 1. Contract Setup:
The contract starts with a setup that includes the terms of the service, typically the price of joining the postal service. This setup is done through the `start` function, which is a standard entry point for Agoric contracts. The function initializes the service and sets up any required assets or parameters.
```javascript
export const start = async (zcf) => {
const { joinPrice } = zcf.getTerms();
const { zcfSeat: postalSeat } = zcf.makeEmptySeatKit();
const mint = await zcf.makeZCFMint('PostalToken', AssetKind.NAT);

// Other initialization logic
};
```

## 2. Minting and Managing Assets:
The contract utilizes the `ZCFMint` object to mint new tokens or assets. In this example, tokens are created to represent the postal services or stamps.
```javascript
const mint = await zcf.makeZCFMint('PostalToken', AssetKind.COPY_BAG);
```

## 3. Handling User Requests:
User interactions with the contract are managed through invitations. These invitations allow users to perform specific actions, such as joining the postal service or sending a package.
```javascript
const joinHandler = userSeat => {
const { give, want } = userSeat.getProposal();

// Ensure the payment is sufficient
assert(give.Price.value >= joinPrice.value, 'Insufficient payment');

// Process the request and update the contract state
userSeat.exit();
return 'Welcome to the postal service';
};

const publicFacet = Far('API', {
makeJoinInvitation: () => zcf.makeInvitation(joinHandler, 'Join Postal Service'),
});
```

## 4. Public Facet:
The public facet of the contract exposes the functionality that external users can interact with. In this contract, users can create invitations to join the postal service.
```javascript
return { publicFacet };
```

## Deploying and Interacting with the Contract
To deploy this contract, developers use the Agoric CLI tools. The process typically involves bundling the contract code, deploying it to the blockchain, and setting up any necessary client-side interfaces to interact with the contract.

### 1. Deployment Script:
The deployment script automates the process of installing the contract on the blockchain.
```javascript
const deploy = async (homeP) => {
const { zoe } = homeP;
const bundle = await bundleSource('./src/contract.js');
const installation = await E(zoe).install(bundle);
console.log('Contract installed:', installation);
};
```

### 2. Client Interaction:
Users interact with the deployed contract through a web interface or directly using CLI commands. They can create and use invitations to join the service, make payments, and manage their assets.
Loading