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:
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?
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
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:
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.
Swap insights and ask questions about “Build on Agoric”.
Ask a question or share your thoughts about this lesson.