6

So I trying out the Mix IDE (1.03), and looking at the .html file from the sample project, there is a "contracts" global. Where is it defined?

function get() {
  var param = document.getElementById('query').value;
  var res = contracts['Sample'].contract.get();
  document.getElementById('queryres').innerText = res;
}

function set() {
  var key = document.getElementById('key').value;
  var res = contracts['Sample'].contract.set(key);
}
  • do you want to see where its defined? :) – niksmac May 7 '16 at 15:49
  • Yes, thank you, I edited the question. Yes I would like to know where it's defined. – Fernando Tiberti May 7 '16 at 19:19
4

Mix automatically generates the contracts array for you. You can manually create contract objects with code like the following:

var MyContract = web3.eth.contract(abiArray);

// instantiate by address
var contractInstance = MyContract.at([address]);

// deploy new contract
var contractInstance = MyContract.new([contructorParam1] [, contructorParam2], {data: '0x12345...', from: myAccount, gas: 1000000});

// Get the data to deploy the contract manually
var contractData = MyContract.new.getData([contructorParam1] [, contructorParam2], {data: '0x12345...'});
// contractData = '0x12345643213456000000000023434234'

https://github.com/ethereum/wiki/wiki/JavaScript-API#web3ethcontract

| improve this answer | |
4

"contracts" is inserted by Mix, you cannot change it. is there a specific reason why you need to access to the declaration?

| improve this answer | |
  • Just curiosity. And maybe to replicate this abstraction to use in other IDEs, as it seems pretty convenient. Also, how do you publish your app to the real world? Is there a build option that generates the contracts declaration for you? – Fernando Tiberti May 11 '16 at 22:37
  • to publish the dapp there is an option: "Deploy -> Deploy to network". There's also an option there to package the dapp – Yann May 12 '16 at 9:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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