1

I would like to setup a smart contract that contains (as defined by smartpy) a BigMap storage.

I have the following code:

import smartpy as sp

class contract(sp.Contract):
  def __init__(self):
    self.init(bm=sp.big_map(tkey=sp.TString,tvalue=sp.TString))

  @sp.entry_point
  def setup(self):
    #populate BigMap during setup of contract
    pass

@sp.add_test(name="dama")
def test():
  contract=contract()
  scenario=sp.test_scenario()
  scenario+=contract
  scenario+=contract.setup()

This produces the following error in the smartpy.io IDE:

Error: 'AddedMessage' object has no attribute 'contract'

Traceback (most recent call last):

  module smartpyio line 236, in run
   test.eval()
  module smartpyio line 25, in eval
   self.f()
  SmartPy code line 13, in test (line 13)
   contract=Contract()
  SmartPy code line 5, in __init__ (line 5)
   self.init(bm=sp.big_map(tkey=sp.TString,tvalue=sp.TString))
  module smartpy line 727, in init
   self.setup()
  module smartpy line 800, in __call__
   return ExecMessage(self.contract, self.name, params, kargs)

This is clearly related to how SmartPy translate to a Michelson contract. Where am I going wrong? Also, how do I interact with a BigMap in order to populate it when a contract is originated? I would like to fill tkey and tvalue initially and then modify the tvalue through an entry point. How would I go about doing so?

Any help is much appreciated!

2

The first and main issue you have is that setup is a method of class sp.Contract that is broken when you redefine it in your contract. This should not be the case and must be fixed on the SmartPy side. So rename setup anything else and it will work.

A second issue, entry points take two parameters self and params, not just one.

A third issue, contract=contract() is problematic. Don't call everything contract.

You should not worry about types at first but if you wish, what you're doing is correct.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.