Skip to content

Instantly share code, notes, and snippets.

@frozeman
Last active February 17, 2016 17:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save frozeman/8f0863a47568f6b1c5b6 to your computer and use it in GitHub Desktop.
Save frozeman/8f0863a47568f6b1c5b6 to your computer and use it in GitHub Desktop.
New contract object
// un"addresses" contract object
var myContrac2 = new web3.eth.contract(abi)
myContrac2.address = '0x12345678...'; // add address later
// initiate with address
var myContrac = new web3.eth.contract(abi, address)
// deploy contract
eventemitter = new web3.eth.contract(abi).deploy(param1, {data: '0x23456'});
eventEmitter.on('mined', function(err, address){
    new web3.eth.contract(abi, address);
 });
eventEmitter.on('transactionHash', function(err, hash){
 });
new web3.eth.contract(abi).deploy.getData(param1, {data: '0x23456'})
> 0x23456780000005345345
// contract object events and methods
myContrac.call({from: '0x1234...'}).myMethod(param1 , cb) // calls cb with result
myContrac.transact({from: '0x1234...'}).myMethod(param1, cb) // calls cb with tx hash, in the future we could return a event transmitter
myContrac.getData.myMethod(param1) // get only the data of the call '0x23456787654323456765432340000000000000000000000034'
@frozeman
Copy link
Author

frozeman commented Feb 7, 2016

intersting idea, but the main problem is namespace problems, which i try to avoid. What if you name your contract event "mined"? then it would clash..

@frozeman
Copy link
Author

frozeman commented Feb 7, 2016

The new keyword is necessary when creating a new instance, to make it clear that it is a new instance, imo:

var contract = new web3.eth.contract(abi, address);

@tcoulter
Copy link

Ah, not sure what I was thinking. new looks good. 👍

@frozeman
Copy link
Author

Moved it to here: ethereum/EIPs#68

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment