A Contract object is a meta-class, which communicates with a deployed smart contract on the blockchain and provides a simple JavaScript interface to call methods, send transactions, and query historic logs.Smart contracts only exist on the Quai account based ledger. They are not deployable on the UTXO based Qi ledger.
In practice, the contract utilities are used to connect, read, and call state changing functions on the Quai Ledger. The contract class can be used to interact with any type of contract on any zone chain in the network.
In order to interact with a contract in any read-only capacity, you must “connect” to it using a Provider. You’ll also need to pass the contract’s deployed address and the contract’s ABI.
Copy
Ask AI
// set up a remote node providerconst provider = new quais.JsonRpcProvider( "https://rpc.quai.network", undefined, { usePathing: true });// connect to the contract using the providerconst contract = new quais.Contract(contractAddress, contractABI, provider);
If you want to execute a contract state-changing operation, you’ll need to pass a Signer to the contract.
Copy
Ask AI
// get signer from pelagus providerconst provider = new quais.BrowserProvider(window.pelagus);const signer = provider.getSigner();// connect the signer to the contractconst contract = new quais.Contract(contractAddress, contractABI, signer);// call a state changing contract functionconst result = await contract.transferTo( "1.0", "0x1234567890123456789012345678901234567890");