I know the web3 beta version way to create a contract is

var myContract = new web3.eth.Contract([abi], 'createAtAddress'});

However, I want to use a stable version of web3 and I've been using

var web3 = new Web3(new Web3.providers.HttpProvider("http://localhost:8545"));

var myContract = web3.eth.contract([abi])
var contractInstance = myContract.at('0x486351a2b3f3f63c04aeec19281cc7293cab8337');

However with this, I can only interact with a preexisting contract. How can I create a new contract at a certain address?

The docs say

var contractInstance = MyContract.new({from: 'createAtAddress, gas: 1000000});

but for some reason that doesn't work.


You are missing the data part when calling new. So the actual code of the contract is not known when you try to create the contract. Try this:

var contractInstance = MyContract.new({from: 'createAtAddress, gas: 1000000, data: contractcode});

where contractcode ist the hex string containing the opcodes of your contract code that is returned after compiling.

See also the JavaScript-API documentation

Not the answer you're looking for? Browse other questions tagged or ask your own question.