I've looked for hours online for how to interact with contracts but I've yet to find an efficient way to do so. My contract is deployed at 0x09B81faA7fB51E5Af79b0241243e58297aC84158
on the ropsten network. I just want to know how to call my method
function getChallengeNumber() public view returns (bytes32) {
return challengeNumber;
}
and
function mint(uint256 nonce, bytes32 challenge_digest) public returns (bool success) {
Obviously I can interact with ropsten but I want to set up a script that can find solutions for the PoW method "mint" and then push solution when it find them.
I've found a bunch of fragmented explanations but nothing that comes close to comprehensive. I can interact with it via remix. I figured out how to call methods that do not alter the state of the network with python but I haven't yet to find any way to interact with my contract in a sustainable way.
Any guidance would be appreciated.
Building off @goodvibrations answer. Because I only have a JSON file I'm working with, I've changed the update method somewhat.
async function deploy(web3, account, gasPrice, contractName, contractArgs) {
const json_file = fs.readFileSync(ARTIFACTS_DIR + contractName + ".json", {encoding: "utf8"});
const json_obj = JSON.parse(json_file);
const abi = json_obj['abi'];
const bin = json_obj['bytecode'];
const contract = new web3.eth.Contract(JSON.parse(abi));
const options = {data: "0x" + bin} //arguments: contractArgs}; <-- I got rid of this because my constructor doesn't accept any arguments
const transaction = contract.deploy(options);
const receipt = await send(web3, account, gasPrice, transaction);
return new web3.eth.Contract(JSON.parse(abi), receipt.contractAddress);
}
But now I get a new error.
(node:5672) UnhandledPromiseRejectionWarning: Error: Provider not set or invalid
at Object.InvalidProvider (~/node_modules/web3/node_modules/web3-core-helpers/src/errors.js:38:16)
at RequestManager.send (~/node_modules/web3/node_modules/web3-core-requestmanager/src/index.js:128:32)
at sendRequest (~/node_modules/web3/node_modules/web3-core-method/src/index.js:705:42)
at Eth.send [as getGasPrice] (/home/lnielsen/node_modules/web3/node_modules/web3-core-method/src/index.js:726:13)
Am I misunderstanding the implementation?