I have created a solidity contract where I can store application
pragma solidity ^0.4.17;
contract Applications {
address applicant;
mapping(uint => string) Application;
function Applications() internal {
applicant = msg.sender;
}
modifier ifApplicant() {
if (applicant != msg.sender) {
revert();
} else {
_;
}
}
function setApplication(uint id, string data) public {
Application[id] = data;
}
function getApplication(uint id) ifApplicant public view returns (string) {
return Application[id];
}
}
When I try to access the setApplication method via web3 I get the above error Attempting to run transaction which calls a contract function, but recipient address is not a contract address
const Web3 = require('web3');
const contract = require('truffle-contract');
const web3 = new Web3(
new Web3.providers.HttpProvider('http://localhost:8545')
);
const ApplicationContract = require('./../blockchain/build/contracts/Applications.json');
const application = contract(ApplicationContract);
//web3 has deprecated sendAsync func whereas truffle-contract relies on it - this is patch hack
web3.currentProvider.sendAsync = web3.currentProvider.send;
application.setProvider(web3.currentProvider);
web3.eth.getAccounts().then(accounts => {
application.new(
{
from: accounts[0],
data:
'0x6060604052341561000f57600080fd5b336000806101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff16021790555061037a8061005e6000396000f30060606040526004361061004c576000357c0100000000000000000000000000000000000000000000000000000000900463ffffffff1680631f2f4bfd146100515780632ee68716146100ed575b600080fd5b341561005c57600080fd5b6100726004808035906020019091905050610153565b6040518080602001828103825283818151815260200191508051906020019080838360005b838110156100b2578082015181840152602081019050610097565b50505050905090810190601f1680156100df5780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b34156100f857600080fd5b610151600480803590602001909190803590602001908201803590602001908080601f01602080910402602001604051908101604052809392919081815260200183838082843782019150505050505091905050610269565b005b61015b610295565b3373ffffffffffffffffffffffffffffffffffffffff166000809054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff161415156101b657600080fd5b600160008381526020019081526020016000208054600181600116156101000203166002900480601f01602080910402602001604051908101604052809291908181526020018280546001816001161561010002031660029004801561025d5780601f106102325761010080835404028352916020019161025d565b820191906000526020600020905b81548152906001019060200180831161024057829003601f168201915b50505050509050919050565b806001600084815260200190815260200160002090805190602001906102909291906102a9565b505050565b602060405190810160405280600081525090565b828054600181600116156101000203166002900490600052602060002090601f016020900481019282601f106102ea57805160ff1916838001178555610318565b82800160010185558215610318579182015b828111156103175782518255916020019190600101906102fc565b5b5090506103259190610329565b5090565b61034b91905b8082111561034757600081600090555060010161032f565b5090565b905600a165627a7a723058200b7685150ea101e930185efc1657a5e630782e6b70be37899e6bf66e523478d10029',
gas: '4700000',
}
).then((contract) => {if (typeof contract.address !== 'undefined') {
const ApplicationContract = new web3.eth.Contract(
application.abi,
contract.address
);
ApplicationContract.methods
.setApplication(1, 'form')
.call({ from: accounts[0] })
.then(data => console.log(data))
.catch(err => console.log(err));
console.log(
'Contract mined! address: ' +
contract.address +
' transactionHash: ' +
contract.transactionHash
);
}
});
I am running ganache-cli
for local development.
PS: I am very new to Solidity
Best Answer
Run this from your command line
truffle networks --clean
this will clean your local network of previously built network...