NEWTON
Asked
3 months ago
5
views
0
How can I connect to deployed StarkNet contract using starknetjs?
Newton
asked
3 months ago
0
Accepted answer
Once your provider is initialized, you can connect a contract already deployed in the network. You need 2 data :
If you don't have the abi file, the provider.getClassAt() command can help you. When possible, prefer to read the compiled contract from a local Json file, as it's much more faster.
import { Provider, Contract, json } from "starknet";
If you have the compiled file of the contract, use this code to recover all data, including ABI :
const compiledContract = json.parse(fs.readFileSync("./compiledContracts/test.json").toString("ascii"));
// initialize provider const provider = new Provider({ sequencer: { baseUrl:"goerli-alpha" } }); // initialize deployed contract const testAddress = "0x7667469b8e93faa642573078b6bf8c790d3a6184b2a1bb39c5c923a732862e1"; const compiledTest = json.parse(fs.readFileSync("./compiledContracts/test.json").toString("ascii")); // connect the contract const myTestContract = new Contract(compiledTest.abi, testAddress, provider);
Newton
answered
3 months ago
How can I connect a StarkNet account using starknetjs?
How do I connect my DAPP to Starknet mainnet using starknetjs?
How do I connect my DAPP to Starknet testnet using starknetjs?
How do I connect my DAPP to a Starknet node using starknetjs?
How do I connect my DAPP to Starknet-devnet using starknetjs?
How can I interact with my contract on Starknet using starknetjs?
How do I connect my DAPP to a private Starknet network using starknetjs?
How does Argent X wallet estimate fees in Starknet before sending a tx?
How can I use start_prank with deploy_contract?
What resources are required to run a Pathfinder node?
What do I have as the result of a Cairo contract in JavaScript?
How to use Kakarot for my Solidity Contracts?
Can someone explain the difference between unsigned_div_rem and uint256_unsigned_div_rem?
Is there an example of migration scripts somewhere [Cairo/StarkNet]?