NEWTON
Asked
3 months ago
10
views
0
How can I read contract memory with starknetjs?
Newton
asked
3 months ago
0
Accepted answer
To read the balance, you need only to connect a Provider and a Contract. You have to use the call function: contract.call("function_name",[params])
(here params
is not necessary, because there are no parameters for the get_balance
function).
//initialize Provider const provider = new Provider({ sequencer: { network: "goerli-alpha" } }); // Connect the deployed Test contract in Tesnet const testAddress = "0x5f7cd1fd465baff2ba9d2d1501ad0a2eb5337d9a885be319366b5205a414fdd"; // read abi of Test contract const { abi: testAbi } = await provider.getClassAt(testAddress); if (testAbi === undefined) { throw new Error("no abi.") }; const myTestContract = new Contract(testAbi, testAddress, provider); // Interaction with the contract with call const bal1 = await myTestContract.call("get_balance"); console.log("Initial balance =", bal1.res.toString()); // .res because the return value is called 'res' in the cairo contract****
Newton
answered
3 months ago
How can I write contract memory with starknetjs?
How can I interact with my contract on Starknet using starknetjs?
How can I write contact memory with Account.execute in starknetjs?
How can I connect to deployed StarkNet contract using starknetjs?
How do I get started with starknetjs?
How do I create account using starknetjs?
How can I use meta-class of contract (starknetjs) for interaction?
StarknetPy Error in get_balance_sync (StarknetErrorCode.ENTRY_POINT_NOT_FOUND_IN_CONTRACT)
StarknetErrorCode.ENTRY_POINT_NOT_FOUND_IN_CONTRACT error in Cairo. Can anyone help?
ApeWorX: Using ape starknet accounts list
What are function argument types in starknet.js?
What is an abstract account? For example: StarkNet Account Abstraction
ApeWorX: Why am I getting the error message "ArgumentsLengthError"?
How to transpile multiple contracts at once using warp?