02 Getting started with Scrypto
2.4 Compiling, Publishing, and Running Hello Blueprint
Now that we’ve speedrun through the composition of a Hello blueprint, let’s actually get a feel how this works instead of just looking at code. In this section, we’ll finally start compiling and running our Hello blueprint so we can walkthrough the feel of interacting with components on Radix.
//Compiling and Testing with Resim (Radix Engine Simulator)
To test our blueprint locally we will use the
This course assumes that you’ve already installed the Scrypto toolchain, so if you aren’t getting a response from using
resim command in our terminal. We used the scrypto command to create new packages; resim is another command we can use to interact with the local Radix Engine simulator. This means that we can have a local ledger that records state from accounts and resources we create as well as execute transactions from function and component calls. It allows us to get an impression of how the Radix Engine would treat the Scrypto packages we create as if it were deployed on a live network.This course assumes that you’ve already installed the Scrypto toolchain, so if you aren’t getting a response from using
scrypto or resim command, please visit the Install the Scrypto Toolchain documentation page.You can check scrypto and resim versions using
scrypto --version and resim --versionThis course also assumes you have some basic understanding of how to use resim, if you haven’t yet, it might be good to review Using Resim documentation page. You may always use resim --help to familiarize yourself with the toolchain.
Before we begin, it’s always good to practice the habit of entering the resim reset command in your terminal. This can potentially save you lots of time in the future and help build a habit of always starting the local ledger with a clean state as every time you want to test your Scrypto packages. Often times we can forget that that there is previous state on ledger which can corrupt our experience of the current session.
Before we begin, it’s always good to practice the habit of entering the resim reset command in your terminal. This can potentially save you lots of time in the future and help build a habit of always starting the local ledger with a clean state as every time you want to test your Scrypto packages. Often times we can forget that that there is previous state on ledger which can corrupt our experience of the current session.
//Creating a New Account
The process of deploying a Scrypto package locally requires the creation of an account which is done by entering
resim new-account.jakemai@Jakes-MacBook-Pro ~ % resim new-accountA new account has been created!Account component address: account_sim1c95kjj52qfh6rss4f5axjr9c03zvlgae2ehpwjxzyz0tr6rqqhv4q0Public key: 035c92f68b86da0dfbb7af525ba99030a16bd1bbfd91797ba89241063af421e612Private key: a39cfbdf7dcd3d085e8ce775001e8b54cee29cd547715857a2058a7b1c2070f2Owner badge: resource_sim1ntzvh2cd59pnwfqkkre0rflfhshrhptkweyf7vzefw08u0l38my5ut:#1#Here we see a few things such as the account address, your standard key pairs to sign transactions, and an owner badge. Let’s first hone in on the
Account component address. As we’ve mentioned in Chapter 1.3: Primer on Scrypto, accounts on Radix are also components. They’re components that are instantiated from built-in blueprints within the Radix Engine, which makes them a little bit special from other components, but the principles are the same: they come from a blueprint and the account component are instantiated from it, which is then globalized and given a ComponentAddress that you see there. Now that we have this address, we can interact with it, which you can do by simply running resim show [account_address].jakemai@Jakes-MacBook-Pro ~ % resim show account_sim1c95kjj52qfh6rss4f5axjr9c03zvlgae2ehpwjxzyz0tr6rqqhv4q0Component Address: account_sim1c95kjj52qfh6rss4f5axjr9c03zvlgae2ehpwjxzyz0tr6rqqhv4q0Blueprint ID: { package_address: package_sim1pkgxxxxxxxxxaccntxxxxxxxxxx000929625493xxxxxxxxxrn8jm6, blueprint_name: "Account" }Owned Fungible Resources: 1└─ resource_sim1tknxxxxxxxxxradxrdxxxxxxxxx009923554798xxxxxxxxxakj8n3: 10000 XRDOwned Non-fungibles Resources: 1└─ resource_sim1ntzvh2cd59pnwfqkkre0rflfhshrhptkweyf7vzefw08u0l38my5ut: 1 ? └─ #1#Metadata: 0jakemai@Jakes-MacBook-Pro ~ %Doing so shows the account’s
The concept of owner badges is pertinent in Scrypto which will be expanded more in Chapter 4: Introduction to Auth. For now, just keep it in your back pocket that something called an owner badge exist. It’s not something we’ll interact with much at this stage of the course.
ComponentAddress, the blueprint package the account component was instantiated from, and a couple of resources the account owns. Every new account on resim starts with 10,000 XRD test tokens, but if you notice, the account also owns a non-fungible resource as well. This is the Owner badge that was outputted when we first created a new account. The concept of owner badges is pertinent in Scrypto which will be expanded more in Chapter 4: Introduction to Auth. For now, just keep it in your back pocket that something called an owner badge exist. It’s not something we’ll interact with much at this stage of the course.
//Deploying our Blueprint Package
Once we now have an account, we can now build and deploy our Scrypto package locally. Make sure in your terminal, that you’ve navigated to the root of your Scrypto package folder. Since I haven’t done that, I need to do so!
To print the current working directory you can use the the
pwd command in Linux/MacOS or you can use echo %cd% to achieve a similar result in Windows.Now you build and deploy our Scrypto package with the following command: resim publish .
jakemai@Jakes-MacBook-Pro ~ % cd Documents jakemai@Jakes-MacBook-Pro Documents % cd hellojakemai@Jakes-MacBook-Pro hello % resim publish .......Success! New Package: package_sim1p459ys8rg44wvgljqrs893wnr326a7q9hggew3976uqmn3m8dakg3djakemai@Jakes-MacBook-Pro hello %It will take some time to run as it compiles your package and all its dependencies. When the command is done executing, it will output the
PackageAddress.Note: you will probably get a different
PackageAddress.//Instantiating our Component
Now that we have the
PackageAddress we can now use that to interact with our deployed blueprint and instantiate a component from it by calling the instantiate_hello function of our blueprint. We can use resim call-function [package_address] [blueprint_name] [function] to do so.jakemai@Jakes-MacBook-Pro hello % resim call-function package_sim1p459ys8rg44wvgljqrs893wnr326a7q9hggew3976uqmn3m8dakg3d Hello instantiate_helloTransaction Status: COMMITTED SUCCESSTransaction Cost: 0.64530740402 XRDLogs: 0Events: 7Outputs: 3Balance Changes: 3New Entities: 2└─ Component: component_sim1cqyc5nhr5jsu6wjgms82acvq08px0nudm4cgkhpy6xwhw2x7krqldx└─ Resource: resource_sim1thzj3axceqx6xz20uafqqeku636xf62hx0he9udl7t0pdfuspd5mcujakemai@Jakes-MacBook-Pro hello %You’ll receive an output that’s similar to this that shows the transaction was successful, albeit, I’ve taken the liberty to condense my output for readability. If you’ve been adventurous and actually changed your Hello blueprint instantiation function based on what you learned last section, you’ll need to call the function based on how you’ve constructed it.
While there are a few things going on here, the important outputs we want to highlight are within the
While there are a few things going on here, the important outputs we want to highlight are within the
New Entities section, which is where the ComponentAddress of our instantiated and globalized component as well as the ResourceAddress of the hello_token.Recall where we delineated the difference between blueprints and components. Here is an example of what instantiating a component from a blueprint means. When we published the package, we made our package addressable on the ledger. This means that people can query the ledger to find blueprints that we published and instantiate components from them.
If you’d like to understand more what each output means the table below summarizes the result:
Caption
Description
Transaction Status
Outputs if the transaction was successful or not along with details on the errors.
Transaction Cost
This section describes the fees you had to pay to execute this transaction. We will cover fee payment in another section.
Logs
If the method or function you called logged some information you will see it here.
Events
The Radix Engine emits system events of things happening during the execution of a transaction.
Outputs
This section shows the output of every step outlined in the previous section.
Balance Changes
This section captures the resources moved between vaults.
New Entities
This section outputs the different entities along with their address that were created during the transaction.
//Calling Our First Method
Now that we have an instantiated Hello component, all the methods defined by its blueprint are exposed to us and callable. We are going to call the
free_token method using the resim call-method [component_address] [method] command.jakemai@Jakes-MacBook-Pro hello % resim call-method component_sim1cqyc5nhr5jsu6wjgms82acvq08px0nudm4cgkhpy6xwhw2x7krqldx free_tokenTransaction Status: COMMITTED SUCCESSTransaction Cost: 0.41404469655 XRDLogs: 1└─ [INFO ] My balance is: 1000 HelloToken. Now giving away a token!Events: 8Outputs: 3Balance Changes: 4New Entities: 0jakemai@Jakes-MacBook-Pro hello %You can read the
Balance Changes section which can somewhat tell you that the ResourceAddress denoting the Hello Tokens we received earlier is being moved around. But a clearer indication that we received a Hello Token is by entering the resim show [account_address] again to inspect our account component.//Inspecting Our Account
jakemai@Jakes-MacBook-Pro hello % resim show account_sim1c95kjj52qfh6rss4f5axjr9c03zvlgae2ehpwjxzyz0tr6rqqhv4q0Component Address: account_sim1c95kjj52qfh6rss4f5axjr9c03zvlgae2ehpwjxzyz0tr6rqqhv4q0Blueprint ID: { package_address: package_sim1pkgxxxxxxxxxaccntxxxxxxxxxx000929625493xxxxxxxxxrn8jm6, blueprint_name: "Account" }Owned Fungible Resources: 2├─ resource_sim1tknxxxxxxxxxradxrdxxxxxxxxx009923554798xxxxxxxxxakj8n3: 10000 XRD└─ resource_sim1thzj3axceqx6xz20uafqqeku636xf62hx0he9udl7t0pdfuspd5mcu: 1 HT└─ resource_sim1ntzvh2cd59pnwfqkkre0rflfhshrhptkweyf7vzefw08u0l38my5ut: 1 ? └─ #1#Metadata: 0jakemai@Jakes-MacBook-Pro hello %As highlighted in the snippet above, we received a new resource in our account component with a symbol “HT” denoting our Hello Token!
Need Help?
Do you have a question and need assistance while working on your project? Then join the RDX Works team and community members on the #Scrypto channel of our Discord server, where you can ask as many questions as you like and we will gladly help you!
Do you have a question and need assistance while working on your project? Then join the RDX Works team and community members on the #Scrypto channel of our Discord server, where you can ask as many questions as you like and we will gladly help you!