4
votes
Accepted
How much storage do numbers take?
Integers have arbitrary precision, meaning that the only size limit is the gas_limit/storage_limit.
$ ./tezos-codec describe ground.Z binary schema
+-----------------+----------------------+----------...
4
votes
Accepted
How can I avoid sp.TOption type when using sp.unpack()?
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(...
3
votes
Accepted
Why can I not subtract 2 local variables of type nat from each other and assign that result to another local variable in a view in smartpy?
Subtractions are implicitly taken as int due to the possibility of negative results. Therefore, the variable sub is of type int here.
To resolve this, wrap sub as sp.as_nat(sub) on the dividend.
3
votes
Which hash function is used when converting an address from raw bytes?
It’s not hashed. You simply need to compute the base58 translation with the right prefix.
Proof that it’s not hashed: this process is reversible.
3
votes
Accepted
Is it possible to convert types in SmartPy?
Yes and no.
There are no built-in convertors in Michelson.
Some operations are doable nonetheless.
For example, the string manipulations template demonstrates kind of extreme string manipulations in ...
3
votes
Accepted
Convert address to string in LIGO
You cannot convert an address to a string in Michelson. You could cheat by going through pack and inspecting the binary representation but it is unlikely something you would want to do.
2
votes
What is a 'valid case' for bls12_381_fr?
Edo2net is not the default protocol in sandbox.
You will need to provide the --protocol-hash arg:
tezos-sandbox mini \
--size 1 \
--number-of-boot 2 \
--protocol-hash ...
2
votes
Accepted
Smartpy Michelson errors only on deployment (inconsistent_annotations, inconsistent_types)
That was fixed in granadanet by this merge request: https://gitlab.com/tezos/tezos/-/merge_requests/2815
You need to add self.add_flag("initial-cast") in the contract constructor to solve ...
2
votes
Accepted
error Type sp.TInt / sp.TNat mismatch
Doing math on nats casts them to an int. The value needs to be casted back to a nat after the subtraction:
self.data.shop_items[item_to_purchase.key].amount = sp.as_nat(self.data.shop_items[...
1
vote
Accepted
How can I assign values for a map-type in an archetype test script?
I think you should try with this:
const tmdMap : Array<[ string, Bytes ]> = [[" ", tmdBytes]]
In typescript, tuple and array have the same literal [].
And here, it is a tuple into an ...
1
vote
How can I assign values for a map-type in an archetype test script?
The expected type reads "an array of pairs of string and bytes", and [" ", tmdBytes] is just a pair, hence I guess the following value should make ti:
const tmdMap : Array<[ ...
1
vote
Accepted
How do you submit a pair when calling an entrypoint on a contract with Taquito?
Your code is correct, but you have to use the methodsObject property instead of methods if you want to use a JavaScript object as the parameter of the contract call.
Alternatively, you can split the ...
1
vote
Accepted
Why does unpacking a record that has a key containing bounded data fail with `to_value sp.TBounded` in smartpy?
It is unsafe without a dynamic check.
We need to determine what the most natural and/or appropriate decision is (very possibly: continue forbidding it).
1
vote
Accepted
Receiving a "doesn't have a comparable type" error when returning a list from an on-chain view
You cannot compare lists in Tezos.
However, you can use scenario.verify_equal.
1
vote
Accepted
Smartpy restrict entrypoint for originated addresses (KT1)
If you are specifically interested in the address of your caller there a simpler solution than the one proposed by @rodrigo-quelhas: sp.sender is an implicit account if and only if it is exactly sp....
1
vote
Smartpy restrict entrypoint for originated addresses (KT1)
You can use: https://github.com/RomarQ/tezos-sc-utils
Usage:
Utils = sp.io.import_script_from_url("https://raw.githubusercontent.com/RomarQ/tezos-sc-utils/main/smartpy/utils.py");
# And ...
1
vote
Accepted
value is invalid for type
As you can see in the explorer, the addLiquidity entrypoint accepts parameter of type
(pair address (pair nat (pair nat timestamp))
But you pass (according to the original Dexter contract):
(pair (...
1
vote
What is a 'valid case' for bls12_381_fr?
Can you give more information on your setup? Like which hash do you use?
In the latest versions of BLS12-381 (used by Edo), it has been decided to pad the bytes for Fr elements. Some users requested ...
1
vote
Accepted
What's the best way to convert from TMutez to TBytes?
You can use sp.pack on expressions of most regular types. It computes a serialized representation of your data.
Only top scored, non community-wiki answers of a minimum length are eligible