I have a contract that creates another contract in a function. I am testing the contract using Ganache. When calling this function using geth, it works fine. But when calling it using my dapp (yeoman, gulp, bower, etc.) it gives me "Error: invalid address" via the browser console.
I have copy and pasted the logic from my dapp into geth and it works as expected on geth, and the Ganache UI shows the transaction.
The following is the code:
web3 = new Web3(new Web3.providers.HttpProvider("HTTP://127.0.0.1:7545"));
web3.eth.defaultAccount = web3.eth.accounts[0];
var myContract = web3.eth.contract([abi left out for readability]);
var contractAddress = '0xae01c97dc970ad45f7be5d23ba72ae24640e90b1';
var contract = myContract.at(contractAddress);
function sendPurchaseTrade() {
contract.makePurchaseTrade('0x427d25b7c0B71C1944df51765c55Bea1961e0a44', {value: 200000, gas: 3000000});
}
The respective HTML page has a button with onclick="sendPurchaseTrade();".
Non state changing calls to the contract work with the dapp.
Any ideas as to why the exact same code will work on geth but not in my dapp?
web3.eth.defaultAccount
contain the address you expect it to? – user19510 Apr 2 '18 at 1:02