Build on Agoric
Contract Deployment
To deploy our sellConcertTickets contract, we’ll use a core eval script. Think of it as a master plan that Agoric will evaluate to make sure our contract launches successfully. At the end of this level, you'll have:
- Installed the concert ticket contract on Zoe (Agoric's smart contract framework).
- Initialized the contract instance, defining ticket prices using the IST (Inter-Chain Stable Token) brand.
- Published the contract in Agoric’s naming service, so it's accessible under friendly names.
Level 2: Writing the Deployment Script ✍️
Our core eval script is going to be the blueprint for this contract's launch. We’ll use the startSellConcertTicketsContract function, which will handle all the setup. Here’s what it will look like:
const contractName = 'sellConcertTickets';
/**
* Core eval script to start contract
*
* @param {BootstrapPowers} permittedPowers
* @param {*} config
*/
export const startSellConcertTicketsContract = async (powers, config) => {
console.log('Core eval for', contractName);
const { bundleID = Fail`no bundleID` } = config?.options?.[contractName] ?? {};
const installation = await installContract(powers, {
name: contractName,
bundleID
});
const ist = await allValues({
brand: powers.brand.consume.IST,
issuer: powers.issuer.consume.IST
});
const terms = makeTerms(ist.brand, 1n * IST_UNIT);
await startContract(powers, {
name: contractName,
startArgs: {
installation,
issuerKeywordRecord: { Price: ist.issuer },
terms
},
issuerNames: ['Ticket']
});
console.log(contractName, '(re)started');
};
What’s Happening Here?
- Installing the Contract: We use installContract, which connects to Zoe and installs our contract’s unique bundleID.
- Setting Terms: The contract terms define the price in IST.
- Starting the Contract: This creates the live instance of our contract and gives it a spot in Agoric’s naming service. At this point, the contract is published and ready!
Level 3: Learning the Agoric Powers 🧙♂️
Agoric’s BootstrapPowers object is like our toolkit for launching contracts. Inside, you’ll find special abilities for publishing contracts, managing instances, and more. Here’s a breakdown of some BootstrapPowers objects you’ll encounter:
cd ~/MultiversX/SmartContracts/crowdfunding
- consume[name]: A promise you can use to access specific services, like Zoe itself.
- produce[name].resolve(value): This lets you “produce” something by resolving its promise with a value. So, you can make Zoe installations, instances, and even brands accessible across the Agoric system!
Level 4: Using the installContract Helper 🛠️
This helper is our go-to for installing the contract on Zoe. Here’s what it looks like:
export const installContract = async (
{ consume: { zoe }, installation: { produce: produceInstallation } },
{ name, bundleID }
) => {
const installation = await E(zoe).installBundleID(bundleID);
produceInstallation[name].reset();
produceInstallation[name].resolve(installation);
console.log(name, 'installed as', bundleID.slice(0, 8));
return installation;
};
Here, you’re using the helper to:
- Install the Bundle: Load the contract’s unique bundleID into Zoe.
- Resolve and Publish: This creates an installation that anyone can find via Agoric’s name service using the installation name.
Level 5: Launching the Contract 🚀
The final part is calling startContract() to activate the instance on Zoe. It also registers your issuer (IST in this case) so it’s all set up to handle payments and ticket sales. At this point, your contract is live, and users can find it as sellConcertTickets under agoricNames.
Bonus: Wrapping Up and Checking the Contract 💼
Once the contract is deployed, check it in Agoric’s naming service under the instance section. Look up your ticket issuer and brand for easy access so you can quickly check all the components are live and working.
Congrats! You’ve deployed a smart contract that can sell tickets on the Agoric blockchain.
Comments
You need to enroll in the course to be able to comment!