I am new to the dApp development. I want to deploy a contract to Ethereum through a website i am building. However i don't want the user to do it through the solidity online compiler or mist wallet. I want the user to press a button and the contract to automatically deploy on the Ethereum (backend function). I am using meteor for this project. Any suggestions on how to implement something like that? Thank you
Can you run this in Geth console?
> var source = "contract demo { string public name = 'Petros'; function changeName(string _newName){ name = _newName; }}"; > var compiled = web3.eth.compile.solidity(source); > web3.eth.compile.solidity(source, function(err, res) { console.log(JSON.stringify(res)); });
The ABI will be compiled.demo.info.abiDefinition
.
If you make an asynchronous call in Javascript, then what you get is in the callback, it is not in the returned thingy.
So this does not work:
var thisWillBeUndefinedObviously = web3.eth.compile.solidity(source, function(err, res) { console.log(JSON.stringify(res)); });
-
Ok so my return would be console.log(JSON.stringify(res)) from the callback function got it. However it doesn't show anywhere the contract address or abi so i can retrieve my string later. Also i wasn't using geth. deployed a couple of contracts through mist and solidity-metamask. I downloaded it, first command you told me to run was undefined and the second is still syncing the blockchain – PetrosM Feb 1 '17 at 11:38
-
I edited my answer to tell you where is the ABI you missed. Compilation is one step. After, you need to deploy your contract, which gives you an address. The commands I gave you return undefined because they create variables. Call these variables to see what they have. Javascript 101. When you deployed through Mist, it did compile and deploy in 1 step. – Xavier Leprêtre B9lab Feb 1 '17 at 16:56
-
var source = "" + "contract demo {\n" + " string public name = 'Petros';\n" + " function changeName(string _newName){\n" + " name = _newName;\n" + " }\n" + "}\n"; var compiled = web3.eth.compile.solidity(source, function(err,res){ //necessary callback function console.log(compiled); }); console.log(compiled);
However the code doesn't appear to compile and nothing shows in the console – PetrosM Jan 31 '17 at 16:41console.log(compiled)
if it isres
that you get? – Xavier Leprêtre B9lab Jan 31 '17 at 17:10console.log(res)
which does return an object with too many options that i don't understand. However there is still the problem thatconsole.log(compiled);
in the end won't return anything. I can't find a way to interact to interact with the returnedres
object. i.e. how can i retrieve the string "petros" from the contract i deployed? – PetrosM Jan 31 '17 at 19:57