Hot answers tagged

10

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


5

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


5

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


5

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

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

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

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

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


4

First of all, Fi is no longer updated and Liquidity no longer supports Tezos, which leaves Ligo, SmartPy, Michelson and Morley. To this list, I would also add Archetype. All of these languages can be considered production-ready and well-documented. Your choice of implementation language should rather be guided by your specific needs. What type of testing ...


4

Your code above has some issues that I will describe below. Also, you are confusing off-chain metadata with on-chain metadata, tzip16 and tzip21 allow those structures because they were designed to be stored off-chain. (Only possible to store onchain with stringified JSON or in bytes.) In make_metadata you are trying to create a map with different value ...


4

For the example provided by Rafael, you can do the following in SmartPy. import smartpy as sp class Creator(sp.Contract): def __init__(self): self.init(address = sp.none) @sp.entry_point def generate_address(self): # Generate the address but don't append the operation contract = sp.create_contract_operation(sp....


3

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


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

1) How does an originated KT address delegate to a baker? During the origination of a smart contract, an initial delegate can be set. After origination, only the smart contract itself can change its delegate and it does that by calling the SET_DELEGATE Michelson instruction (called sp.set_delegate in SmartPy). 2) If a KT address delegates, can it do ...


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

You are guaranteed (if the crypto behind Tezos is not broken) that the person who signed the transaction knew the corresponding private key (in case of an implicit account) so, for all reasonable purposes, you should be good.


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)


3

sp.unpack gives you an option (because Michelson gives an option when you call UNPACK) that you need to open. You can do it like this myBytes = sp.unpack(packedString, t = sp.TBytes).open_some() if you're sure that packedString is indeed a packed sp.TBytes. If you're not 100% sure, you can add an optional error message to open_some().


3

The issue is caused by an invalid IPFS link. Steps to FIX the issue: Update the metadata (including views, etc...) Copy the generated JSON Upload the metadata JSON to IPFS You can use Pinata for this. Update the metadata link in the code Replace all occurences of sp.metadata_of_url("https://example.com") with sp.metadata_of_url("<...


3

You basically have no guarantee of synchronicity for several reasons. We’re talking about a blockchain with no instant finality (yet) so a transaction can be “reversed” in the (real world) future so when you send a transaction, you don’t know if it will still be there in 30 or 1000 blocks. Off chain views use a node that may or may not be synchronized with ...


3

sp.if gets translated to Michelson IF's, and cannot be used together with meta-programming e.g. ruturn statements since meta-programming gets applied before compilation. Meta-programming (Applied before compilation, useful for creating contracts with multiple configurations) if <condition>: do stuff... else: do something else... Applied at ...


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