Tinkering with addresses in SmartPy
In Chapter 2, we read that a blockchain is made up of accounts and each account has an address serving as a unique identifier.
The unique identifier points to an account on the blockchain and it looks like this:
In this chapter we are going to learn how SmartPy handles addresses under the hood. In the later half of the chapter, we will add the ability to add ownership rights to our cryptobot!
Addresses can be of two types:
- An address of a user account eg: address of your Tezos wallet which you use to transfer XTZ to your friends.
- An address of a smart contract eg: address of your
Addresses are represented by type
## bot_manager is a variable ## that stores the address of the user ## who manages the cryptobot. my_address = sp.address("tz1Syu3KacZ8cy4286a4vaCeoMtwqVKHkaoj") self.init(bot_manager = my_address) ## Update bot_manager value ## in case you decide to sell your cryptobot self.data.bot_manager = sp.address("tz1dFyuNkiSabQrU1ie9yTKbiTje3YbuXjX1")
- Since addresses are fundamentally string values, we call
sp.addresson an address string to explicitly tell the compiler that this is an address value, and not a string.
New feature request!
In our current
Cryptobot contract implementation, there is no way to tell that you are the maker and manager of this
You are spending so much time evolving the cryptobot’s abilities, that you had forgotten about this tiny but crucial detail!
Step by step walkthrough:
bot_managerstate variable to the contract’s storage that will hold the address of the owner.
manager_addressas parameter to the initialization function and assign it to
Testing our code:
my_addressvariable and give it the address value of
my_addressas value to
manager_addressfunction argument and then use it to invoke the
When you’re finished:
- Click on “Check” to check your submission with the correct answer.
- Click on “Show Answer” in case you get stuck.
You can also tinker around with the final code on SmartPy’s online IDE. Try running the test by clicking on the ▶️ button!