NEWTON
Asked
23 days ago
7
views
0
How do I transform data from javascript to Cairo?
Newton
asked
23 days ago
0
Accepted answer
Cairo contracts and Javascript/Typescript languages do not have the same types of data. So, it's necessary to prepare the data before sending them to a contract (for invoke/execute, or for a constructor).On the other side, when a contract sends data to your DAPP (the result of a call), you have also to transform them before use in your code.
In Cairo, everything is felt, an integer on 251 bits. This type does not exist in JS/TS; you have Number, bigInt, string, array, objects... and types defined in libraries. In Starknet.js, it's a bit ... complicated: you have the BigNumberish type; it can include:
const myBigInt=BigInt(1234n); // To create a BigInt const myBN=new BN("0x12b4"); // To create a BN const myBN=new BN(myBigInt.toString(); // To convert a BigInt to BN const myBigInt=BigInt(myBN.toString); // To convert a BN to BigInt
Newton
answered
23 days ago
What do I have as the result of a Cairo contract in JavaScript?
Cairo: Javascript API for cairo compile
Is there a javascript version of StarkEx playground?
signing a message using account.signMessage(data) | starknet.js
How to verify Empiric’s Data Entries Using Events?
Cairo: How do I initialize an array in cairo
Nethermind's warp error: JavaScript heap out of memory
Is there a javascript version of StarkEx playground?
What is Kakarot, the zkEVM written in Cairo?
Is there something going on the testnet StarkNet?
Is there a Cairo equivalent to Keccak256(abi.encode(parameters))?
How many time does it take for stark to eth starkgate bridge process?
Does starknet have name service?
What does this error means? (AssertionError: assert_not_zero failed: 0 = 0.)