Open Vonadise opened 2 years ago
The bigMap
method is going to be available on the storage of the contract, not the contract abstraction:
const contract = await tezos.contract.at('KT1WGc5s9WwGHi5TUGAGvX9dSP1sbD8qdEc6');
console.log("Showing schem...");
const schema1 = await contract.storage();
console.log(JSON.stringify(schema1, null, 2));
const schema = await schema1.bigMap('195502') // Should work now if the bigmap id is correct
console.log(JSON.stringify(schema, null, 2));
This method doesn't work
What error message do you get?
Error: No big map schema id is correct
I don't understand what your goal is from your code
I want to get a big map of a smart contract
The bigmap will be available on the storage by its name, the bigmap with the id 195502
is called proposals
so:
const schema1 = await contract.storage();
console.log(JSON.stringify(schema1, null, 2));
const schema = schema1.proposals
console.log(JSON.stringify(schema, null, 2));
Then you can use the get
method to look for a key in the bigmap.
How to use get to get this bigmap?
const contract = await tezos.contract.at('KT1WGc5s9WwGHi5TUGAGvX9dSP1sbD8qdEc6')
const schema = await contract.schema.EncodeBigMapKey
const schema1 = await contract.schema
const schemabigmap= await tezos.contract.getBigMapKeyByID('195502',schema,schema1 )
console.log(JSON.stringify(schemabigmap, null, 2));
I tried to do this, but an error appears No big map schema.
If I do so
const contract = await tezos.contract.at('KT1WGc5s9WwGHi5TUGAGvX9dSP1sbD8qdEc6')
const schema = await contract.bigMap('195502')
console.log(JSON.stringify(schema, null, 2));
Error: No big map schema
If I do so
const schema = await tezos.contract.getBigMapKey('KT1WGc5s9WwGHi5TUGAGvX9dSP1sbD8qdEc6','195502')
console.log(JSON.stringify(schema, null, 2));
Error: No big map schema
I think I misunderstood your previous reply, can you elaborate on "get a big map"? I thought you just wanted to get a bigmap to find a key/value pair, why are you interested in the bigmap schema? To find a key/value pair, you just do:
const storage = await contract.storage();
const proposal = await storage.proposals.get(1);
// returns undefined if the key doesn't exist or the associated value if the key exists
There is an error in your code: Error: Property "proposals" does not exist on type "unknown".
I want to get the data contained in the big map
Yeah, you have to explicitly type the storage variable:
const storage: any = await contract.storage();
const proposal = await storage.proposals.get(1);
This will work if you want to get a single value from the bigmap. You can use getMultipleValues
instead and pass an array of keys to get multiple values at once. If you need all the values from the bigmap, you will have to use an indexer API as Taquito doesn't support it yet.
thank you :)
I think I misunderstood your previous reply, can you elaborate on "get a big map"? I thought you just wanted to get a bigmap to find a key/value pair, why are you interested in the bigmap schema? To find a key/value pair, you just do:
const storage = await contract.storage(); const proposal = await storage.proposals.get(1); // returns undefined if the key doesn't exist or the associated value if the key exists
@claudebarde Getting the schema of the key/value pairs of the big map is pretty valuable to know how to interpret them. Had this problem as well and there seems no way to get this type of information out of the library. The only way I found was fetching tzkt.io. It would be pretty nice to get the schema of big maps just like for maps.
import { TezosToolkit } from '@taquito/taquito'; import { InMemorySigner } from '@taquito/signer';
async function example() { const provider = 'https://rpc.hangzhounet.teztnets.xyz'; const signer: any = new InMemorySigner('edskRdkUMmmBorjeetbGiU4cjZ1pbewF6ZmBMj7jCEWxA6pmgTooYTCStHZFitsEgnut7V3YpKt8ptgT1hgK5DuLS4baqXHQXj'); const tezos = new TezosToolkit(provider); tezos.setSignerProvider( signer ); try {
}
}
example();
Error: No big map schema Why this error appears and how to solve it Please help me :)