You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Tim Coulter edited this page Sep 25, 2015
·
3 revisions
You can extend Pudding classes to add additional functionality to contract classes. Simply use the .extend() method on a contract class before creating a new instance:
// Persona is a contract class that has been created with Pudding.Persona.extend({addAvatar: function(image){// This method exists within a Persona contract class, so it already// has a reference to its own address at this.address. This method // can then be used to seamlessly add this persona’s avatar to IPFS // without interacting with functions external to the Persona object.// ... implementation ...}});// After calling .extend(), new instances of the Persona class will// have the .addAvatar() function available.varpersona=Persona.at(“0x12345abcde...”);persona.addAvatar(someImage);// calls out to ipfs, saves hash on the blockchain
Note: Extended functions are not automatically promisified, so you'll have to promisify those functions yourself (or have those functions return a Promise) in order to use those functions within a promise chain.