I have deployed a contract using truffle on the testrpc network. I need to write a Javascript code that can connect to the contract and run the functions of the contract but I can't figure out how to do that.
Edit:
I am now using truffle-contract
and truffle-artifactor
in order to connect to deployed contracts. Here is the artifactor code :
var Web3 = require('web3');
var fs = require("fs");
var Artifactor = require("truffle-artifactor");
var provider = new Web3.providers.HttpProvider("http://localhost:8545");
var contract = require("truffle-contract");
var temp = require("temp").track();
var path = require("path");
var requireNoCache = require("require-nocache")(module);
var abiVal = JSON.parse(fs.readFileSync('./build/contracts/DINRegistry.json'))
var contractData = {
contract_name: "DINRegistry",
abi: abiVal
}
var dirPath = temp.mkdirSync({
dir: path.resolve("./"),
});
var my_path = '/home/lee/Music/DIN-master';
var expected_filepath = path.join(my_path, '/build/contracts/DINRegistry.json')
function artifactCreator() {
const artifactor = new Artifactor(my_path);
artifactor.save({
contract_name: "DINRegistry",
abi: abiVal
}, "./DINRegistry.sol.js")
}
artifactCreator();
The code isn't able to create the file DINRegistry.sol.js
. What is incorrect in this code?