You can use ethers.js to interact with a smart contract on Pivotal by instantiating a Contract object using the ABI and address of a deployed contract:
For write-only contracts, provide a Signer object instead of a Provider object:
CONTRACT_ADDRESS is the address of the deployed contract.
Once you have created a Contract object, you can use it to call desired methods on the smart contract:
const privateKey = 'PRIVATE_KEY';
const signer = new ethers.Wallet(privateKey, provider);
const abi = [
… // ABI of deployed contract
];
const contractAddress = "CONTRACT_ADDRESS"
// read only
const contract = new ethers.Contract(contractAddress, abi, provider);
// write only
const contract = new ethers.Contract(contractAddress, abi, signer);
async function setValue(value) {
const tx = await contract.set(value);
console.log(tx.hash);
}
async function getValue() {
const value = await contract.get();
console.log(value.toString());
}