Skip to main content

Questions tagged [smartpy]

Discussion about the SmartPy language

Filter by
Sorted by
Tagged with
0 votes
3 answers
204 views

Conversion of address to bytes

I converted contract address to bytes using pack , and the result is this 050a00000016014b168ccb96310249aade4ce010e4e2ec8dd4602900 pasting this on online byte to string tool shows an error Invalid UTF-...
lee brune's user avatar
3 votes
1 answer
210 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 ...
JJJ's user avatar
  • 557
3 votes
1 answer
197 views

Is it possible to convert types in SmartPy?

For example, converting a TMutez into a TString?
Darius's user avatar
  • 649
3 votes
2 answers
379 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 ...
Geoff's user avatar
  • 233
3 votes
1 answer
74 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. ...
Darius's user avatar
  • 649
2 votes
1 answer
253 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 ...
Daly's user avatar
  • 442
2 votes
1 answer
99 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: ...
0x10's user avatar
  • 359
2 votes
2 answers
176 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 ...
0x10's user avatar
  • 359
1 vote
1 answer
567 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 ...
Geoff's user avatar
  • 233
1 vote
1 answer
49 views

RLP decoding on tezos

I have a code where a string "TEST" is encoded using RLP, https://smartpy.io/ide?cid=QmNVpo55Ss43aZiyrkdbEWcmmQEAsR2qHLKsPcLbqie7yu&k=8d516a673d972f3204f0 How do we decode the obtained ...
Kin's user avatar
  • 184
1 vote
1 answer
179 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 &...
Hexa's user avatar
  • 61
1 vote
1 answer
188 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 ...
JJJ's user avatar
  • 557
1 vote
1 answer
47 views

How do we achieve a variable type of struct in smartPy

I am translating following code in solidity to smartpy. How do we achieve a variable type of struct in smartPy. Types.AssetTransferDetail[] memory _assetDetails = new Types....
theBatMan's user avatar
1 vote
1 answer
471 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 ...
Daly's user avatar
  • 442
1 vote
1 answer
96 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 ...
JJJ's user avatar
  • 557
1 vote
1 answer
39 views

rlp encoding of solidity

there are two functions on solidity function encodeString(string memory self) internal pure returns (bytes memory) { return encodeBytes(bytes(self)); } /** ...
Kin's user avatar
  • 184
0 votes
1 answer
52 views

call another contract onchain view

first we deploy fa2 contract from a contract like this deployed_fa2 = sp.create_contract_operation(contract=FA2_contract.SingleAssetToken(admin=sp.self_address, metadata=metadata,token_metadata=...
Sandip Bhujel's user avatar
0 votes
1 answer
154 views

Minting several Nfts in one operation

I'm using the fa2_nft_minimal.py smart contract that has the following entry point for minting: @sp.entry_point def mint_many(self, to_, metadata): token_id = sp.compute(self.data....
Rafael Viana's user avatar
0 votes
1 answer
37 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 ...
JJJ's user avatar
  • 557