Hot answers tagged

12

The BigMap container is a special map (dictionary) whose storage is only read or written per key on demand. The motivation to have such a container is the following. Suppose that you have a contract containing lots of more or less independent data and you don't want to read / write all of the data at once but only a small part of it. Think of crypto-kitties,...


8

The new CLI and RPC for big map expect hash of a script expression, instead of the raw expression. To obtain the hash you can e.g.: tezos-client hash data '"tz1bwsEWCwSEXdRvnJxvegQZKeX5dj6oKEys"' of type address This will print hashes in bunch of different formats - you want the one with the label Script-expression-ID-Hash, e.g. ...


7

Let's find out. We start by running a sandbox node. We'll originate two contracts, one for maps, the other for bigmap. parameter (pair address nat); storage (big_map address nat); code { UNPAIR; UNPAIR; DIP { SOME }; UPDATE; NIL operation; PAIR; }; (this is the big_map version, the map version is the same with the type "bigmap" ...


6

The cli command is tezos-client get big map value for <key> of type <type of the key> in <contract>. By adding the -l option, we also get the RPC: /chains/main/blocks/head/context/contracts/<contract address>/big_map_get. Actually, you do not need to know the big map index, if several big_maps with the same type of keys are stored, ...


5

As of Taquito release v6.1.0-beta.0 Taquito offers a new API for Maps which support pairs as keys in Maps and BigMaps. Here's a link to documentation & examples on Accessing Map values using Pairs


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

As of 004_Pt24m4xi: You can use the big_map_get RPC to get individual values out. There is also a tezos-client command for this. (By passing -l we can see how it works through the RPC.) $ tezos-client -l get big map value for 1 of type nat in KT1Qu32f8N5RLPoku5n8itiGaJ1a3eJDj5gu ... >>>>2: http://localhost:18731/chains/main/blocks/head/context/...


4

This is not something you will be able to achieve with Taquito (at least not for now, that will change in the future) and you have to use an indexer API. I recommend Better Call Dev API, you can easily get the number of keys with a fetch call to api.better-call.dev/v1/bigmap/${network}/${big_map_id}/keys (the big map ID should be available in Taquito by ...


4

The tezos-client and tezos-node RPC have no such feature. If you don't mind using an API other then the node RPC you can find this in the new version of the tzstats indexer (GET /explorer/contract/{hash} returns an object with a key bigmap_ids which is an array) see https://api.babylonnet.tzstats.com/explorer/contract/KT1E5toJrALhVPuKpHWTbRVjgEvWWR98sVKj ...


3

It is not possible using Taquito alone. You must use an indexer to extract all the key/value pairs from a big map (Better Call Dev is developed by Baking Bad who also offers an indexer API). This will however be possible in the near future as Taquito will soon be able to plug into any indexer and extract all the values from a big map.


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

AFAIK a restriction in Athens is that a bigmap must be first element in the storage definition. Thats why KT1JPvBo4Sv7n1WDzcKWEXTVRDU9HQhaZdzd does not have a bigmap but KT1EMy5cDrUQgNYZgtN4wX2n39MBqHGQQCiK does. If you use type big_map somewhere else it gets translated into a regular map.


2

As of Taquito release v6.1.0-beta.0 Taquito offers a new API for Maps which provides you with get and set calls. The API does not offer an optional default value param, You will have to catch the error and assign your value. We will change the behaviour of get to return undefined on the unknown key. I will update this issue when it is released. You can ...


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

big_map is extremely expensive. It allows you to put as much data as you want in the contract, but you end up paying more in counterpart. Check this example: It produces 2 identical contacts, one uses a map and the other uses a big map. import smartpy as sp class MyContract(sp.Contract): def __init__(self, **kargs): self.init(**kargs) @sp....


2

Quick way (using Pytezos library): >>> from pytezos.michelson.pack import get_key_hash >>> get_key_hash({"string": "KT1PWx2mnDueood7fEmfbBDKx1D9BAnnXitn"}, {"prim": "address"}) 'exprvAHu1SyoiSzyh9w7GPfifvyrNiMb442y7Q2MA8tcPCGPajxRH6' Where first argument is the key (Micheline JSON), and the second ...


1

The main benefit of big_maps with respect to maps is that the gas costs of big_map operations don't depend on the number of elements stored in the big_map. Regarding storage size, when you store a key-value mapping in a big_map, you store the value but not the key; instead you store the hash of the key. This hash always takes exactly 32 bytes. The rest of ...


1

I ended up using ConseilJS for this. I used the TezosMessageUtils.encodeBigMapKey function in ConseilJS to create the hash key. Here's an example of how to convert the key to the hash : const packedKey = TezosMessageUtils.encodeBigMapKey(Buffer.from(TezosMessageUtils.writePackedData(secretHash, "bytes"), "hex")); You need to put the ...


1

You have 2 solutions for this problem: Use an indexer to get the values contained in the big map; Use an off-chain view to paginate the values if they can be accessed sequentially Off-chain example: Code with tests: https://smartpy.io/ide?cid=QmNeBqAbS4yotpDpdv7SPb7G3a3aHZpEoeKyzHnGuMHtcT&k=cb7d23e3d4856e707cba Explorer: https://tzcomet.io/#/explorer%...


1

Yes, the context queried in the RPC is the context resulting from the operations in that block. This can be demonstrated thus: Consider the contract store_string.tz: parameter string ; storage (option string); code { CAR; SOME; NIL operation; PAIR; }; It takes a string as a parameter and stores it. We originate the contract in a ...


1

What is script_expr? Prior to the Babylon protocol, a contract could only have one big map. This big map had to be located in a storage structured like this: or (big_map ...) .... There is a deprecated route to query a big map in the location. Since Babylon, a contract can have multiple big maps. Each of these big maps have a unique id (an integer). Using ...


1

script_expr in this RPC means any Michelson expression. It is used to specify the key of the big_map that the RPC queries.


1

@arvidj is right of course and you cannot iterate on a bigmap. You need to keep your sum in the storage. You also have another error: if it was a map, you would still need to use a local variable to accumulate the sum. This is introduced by total = sp.newLocal('total', ...). What the error is telling you is that your v is escaping it`s scope. With 1, we ...


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