Questions tagged [smartpy]
Discussion about the SmartPy language
13
questions
3
votes
1
answer
183
views
Why aren't the offchain views appearing?
I'm extending the smartpy FA2 template
#
FA2 = sp.import_script_from_url("https://smartpy.io/dev/templates/FA2.py")
class TezosLandNft(FA2.FA2):
...
which has the following offchain views ...
2
votes
1
answer
67
views
Why does `sp.pack('some string')` prepend `0x05010000002e` before the actual bytes?
If I pass in the string QmbPAr5RcCZZDRsNKnf2p1t6GK3Qu7oDH39HCK3aewUq3w to the sp.pack method in an entrypoint and perform and sp.trace in smartpy I expect to get the following bytes:
...
1
vote
1
answer
349
views
Smart contract calls another smart contract's method with SmartPy
How can I call a smart contract method from another smart contract with smartPy?
Use Case:
Lest's imagine that we have:
Smart contract with a function increment(a)
Smart contract with a function ...
3
votes
1
answer
63
views
How can I avoid sp.TOption type when using sp.unpack()?
Within my smartpy contract, I want to convert from one type into another using sp.pack() and sp.unpack.
Below is an example of the method I am trying to use, converting a string to bytes.
...
3
votes
1
answer
142
views
Is it possible to convert types in SmartPy?
For example, converting a TMutez into a TString?
3
votes
2
answers
279
views
Using sp.create_contract to generate pseudorandom numbers on-chain
In this answer, the answerer suggested that CREATE_CONTRACT could be used to generate a contract address which could then be used as a seed for a pseudorandom number in a contract.
What would a simple ...
2
votes
2
answers
99
views
How do you convert a string sent to an entrypoint into its byte representation?
I want to turn a string into the 0x byte format inside an entrypoint.
If I try to use sp.pack() the actual value I want gets prepended with pack instructions as detailed here
I'm looking for a runtime ...
2
votes
1
answer
156
views
Parse address to string in smartPy
Can we parse a varialble of type sp.TAddress to sp.TString like this:
strAddress = sp.string(sp.address("tz1-add")) or strAddress = str(sp.address("tz1-add"))?
Smart Contract Example:
import ...
2
votes
1
answer
26
views
Calling balance_of via smart contract gives error A FAILWITH instruction was reached with 19
I am trying to call "balance_of" entrypoint of fxhash contract (in ghostnet).
Deployed contract: https://better-call.dev/ghostnet/KT1FqmrtKA4Pz4cNDsikt8qrwEg8pdSCpYug/interact/check
I used &...
1
vote
1
answer
128
views
Is there a "standard" way to load off-chain metadata for all tokens from a single off-chain data source in an FA2 contract?
Let's say I want to create a fixed cap of 10,000 NFTs. I pre-generate the token_metadata and store it on IPFS. The token_ids are only recorded on the FA2 contract when they're bought.
If I don't want ...
1
vote
1
answer
445
views
Converting a hash into an int within a range
I have a contract where I'd like to convert a hash (sha256 in this case, but I'm open to any of the other hashing algorithms available) into an Int (or Nat) between 1 and 100.
I have the code that ...
1
vote
1
answer
78
views
How to add new record fields in data storage after contract deployment? Is storing JSON in a field viable?
AFAIK, there is no way to update storage types(ex: can't add a new record field to a Map<sp.Nat, sp.record(a=1)>) of a contract after deployment. (Correct me if I'm wrong). This means, after a ...
0
votes
1
answer
28
views
Declaration Error: Variable name "x" already in use
When calling a method that uses a local variable twice, I'm getting this error.
Example smartpy link. In this linked code I added a new method test_string_of_nat2 which triggers this behavior.
How ...