Hot answers tagged

9

In response to question 4: Reuse and modularity We discuss reuse and modularity, of which inheritance is one of many mechanisms: Michelson has no mechanism for code reuse, except for calling existing "library" contracts directly. As far as I understand, Archetype includes no user-extendable mechanisms for code reuse. Actions (akin to methods) ...


6

Here is a complement to Arvid's answer regarding Archetype: Reuse and modularity Indeed Archetype's extensions are reusable codes to add features to a contract. For example, using the 'transferable' extension on a role adds to the contract the necessary actions (ie entry points) to transfer the role to another address. For example, invoking the '...


4

I believe what you are looking for is this: sp.send(sp.address("tz1"), sp.tez(420)) I can't find much documentation for sp.send but I have seen many SmartPy examples with sp.send and sp.amount


4

With respect to question 3, following @ezy remark, SmartPy has some inlining capabilities including with new opcodes as shown in the Inline Michelson template (of the new version, currently https://SmartPy.io/dev). It's accessible here: https://smartpy.io/dev/index.html?template=inlineMichelson.py. import smartpy_michelson as mi ... @sp.entry_point ...


4

Do Archetype/Ligo provide everything that Michelson can currently do, or are there limitations with either? I think if something is possible in Michelson and not in Ligo, it is probably a bug worth reporting, the Ligo devs usually quickly answer these kinds of issues. Archetype however is purposely not Turing complete and in particular you cannot do ...


4

No, you do not need to specify the type of the keys of values. Instead, without needing the declare the map, you simply use it and the types are inferred. To construct a mapping called m, use m = sp.map(...). To access element k, write m[k]. For an example, refer to the FA1.2 template in the SmartPy online IDE.


4

As of the current Babylon protocol and the upcoming Carthage, the RPC only provides you the ability to retrieve the value for a known key that you provide to the RPC. But even in this scenario you need to provide not the readable key you stored, but a hash of that key as that is how it is represented internally. This answer describes how to call the RPC The ...


4

The contract you point to takes a single parameter of type address. Thus, as you write, it only has the default entrypoint. In taquito, the main entry point can be call through contract.methods.main. So your call should be: contract.methods.main(contractAddress).send()


4

You have to do it manually... Here's one approach for compute log(x) assuming you are representing x as a fraction find integer m through binary search such that 2^m <= x < 2^(m+1) (m may be negative) let m' = m + (1 if |x/2^(m+1)-1| < |x/2^m-1| else 0) (the closests of m or m+1) let x' = x / 2^m', note that |x'-1| < 1/3 and log(x) = log(2^m' x'...


4

Your understanding is quite correct. SmartPy is a Python library, not a Python-inspired language so we use Python everywhere and overload Python's constructions. This approach is called meta-programming and is extremely important for bigger templates. Control operators such as if, for, while cannot be overloaded in Python. So we have our own pure-python ones ...


4

You have access to a "time" with sp.now so you can compute conditions, etc. There is nothing like "send in 30 minutes". You need external input to trigger operations Tezos. You can compute with timestamps and forbid some actions for a period. Deducting the balance to the sender means sending the amount to the contract. Recipient will not ...


3

Contratry to my initial answer, as FFF pointed out, the problem is that an entrypoint in SmartPy cannot return a value to the calling contract, nor in the underlying Michelson language. The typical solution is based on continuation-passing style. The idea is that the calling contract also provides a call back, in the form of an contract. The parameter type ...


3

The SmartPy contract explorer allows you to see all the entry point of a given contract in any of the networks (main and test) along with autogenerated forms to interact with all those entrypoints. Example: https://smartpy.io/test2/explore.html?address=KT1APXAZKofAtPsxFKPLbjMJohe1rXaGJoYc


3

To find all the entrypoints and their types using tezos-client you can use the following command: tezos-client get contract entrypoints for <src> To check a specific entrypoint you can also use: tezos-client get contract entrypoint type of <entrypoint> for <src> You can find more about available commands in the official documentation.


3

I cannot answer all your questions but at least, I can say that, in SmartPy.io, the storage sent to ConseilJS is the content of the tab "Storage" (in either Michelson or Micheline formats) and the code is similarly the content of one of the corresponding tabs. Depending on the form you're using, you need to set Michelson or Micheline (the latter is quite ...


3

Give ConseilJS a try. Here’s a set of tutorials: https://medium.com/the-cryptonomic-aperiodical/blockchain-development-with-tezos-698aa930e50f If you just want straight code samples, check this out: https://gist.github.com/anonymoussprocket/148d82fc9bf6c413be04155a90d57be6


3

There are several example templates, such as FA2 (real world token contracts) and Collatz (small demo and test template). https://www.smartpy.io/dev/?template=FA2.py https://www.smartpy.io/dev/?template=collatz.py For your example, the error message is clearly unhelping but you should define an entry point to receive the value in a contract. You cannot use ...


3

I am unsure how to interpret params.target, so i modified getBalance by adding an entrypoint and address @sp.entry_point def getBalance(self, params): sp.transfer(sp.as_nat(self.data.balances[params.arg.owner].balance), sp.tez(0), sp.contract(sp.TNat, params.contractAddress , entry_point = "viewBalance").open_some()) Here is my view ...


3

I have a contract for binary log that uses few multiplications and can be adjusted for any fixed point precision: https://github.com/Sophia-Gold/michelson/blob/master/log2fix.tz. I don't think it can be written in SmartPy because last I checked it lacks shifts. Depending on your needs you could use this with change of base or Arthur's method.


3

Use now = sp.timestamp(10). We used to allow now = 10 but this is not well typed. (also, obviously, the exception message should be better)


2

There is no way of iterating over all values in a big_map in the language to which SmartPy compiles (Michelson). So it doesn't surprise me that this doesn't work in SmartPy either. Indeed, according the SmartPy documentation: e.values(): Returns the list of values of a map, sorted by keys. Here, I presume that map refers exclusively to normal, "simple" ...


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=...


2

We maintain an index of all historic bigmap data at TzStats. To fetch all current keys and values in a bigmap call https://api.tzstats.com/explorer/bigmap/:id/values If your bigmap is very large you can page through the result with limit and offset parameters (default is 100 entries, max is 500). See our bigmap docu for more details and examples. If you ...


2

The SmartPy manual (https://smartpy.io/demo/reference.html#_cryptography) says that: sp.check_signature(k, s, b): Determine whether the signature s (a sp.TSignature value) has been produced by signing b (a sp.TBytes value) with the private key corresponding to k (a sp.TKey public key value). It simply computes a boolean after checking that the data in 'b' ...


2

Looking at https://smartpy.io/dev/reference.html#_chain_id, you can see that you can basically currently do three things in SmartPy: Define chain_id constants with things like sp.chain_id_cst("0x9caecab9"). Get the current chain_id for your chain sp.chain_id. Verify that they match with sp.verify_equal. There are no helper lists of chain_id constants that ...


2

You can probably use this to play with it (skip the Lorentz part but start with the smart contract). https://assets.tqtezos.com/token-contracts/1-fa12-lorentz#interactusingtezos-client


2

Just send xtz to this contract adress as you would do for any other adresss


2

As already said elsewhere, DIG has been added several months ago in Michelson. Your Lorentz script is extremely outdated.


2

You are using invalid addresses.


2

When you send an operation, it first goes to the mempool, and only then bakers include it into the block. So there is some delay... I highly recommend you use tzkt.io explorer, because it also checks operations in the mempool so you will see them right after sending or if it's stuck in the mempool. For example:


Only top voted, non community-wiki answers of a minimum length are eligible