{"action":"created","issue":{"url":"https://api.github.com/repos/ethers-io/ethers.js/issues/369","repository_url":"https://api.github.com/repos/ethers-io/ethers.js","labels_url":"https://api.github.com/repos/ethers-io/ethers.js/issues/369/labels{/name}","comments_url":"https://api.github.com/repos/ethers-io/ethers.js/issues/369/comments","events_url":"https://api.github.com/repos/ethers-io/ethers.js/issues/369/events","html_url":"https://github.com/ethers-io/ethers.js/issues/369","id":388047042,"node_id":"MDU6SXNzdWUzODgwNDcwNDI=","number":369,"title":"Impossible to intercept contract method calls with Proxy","user":{"login":"dhl","id":265220,"node_id":"MDQ6VXNlcjI2NTIyMA==","avatar_url":"https://avatars2.githubusercontent.com/u/265220?v=4","gravatar_id":"","url":"https://api.github.com/users/dhl","html_url":"https://github.com/dhl","followers_url":"https://api.github.com/users/dhl/followers","following_url":"https://api.github.com/users/dhl/following{/other_user}","gists_url":"https://api.github.com/users/dhl/gists{/gist_id}","starred_url":"https://api.github.com/users/dhl/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dhl/subscriptions","organizations_url":"https://api.github.com/users/dhl/orgs","repos_url":"https://api.github.com/users/dhl/repos","events_url":"https://api.github.com/users/dhl/events{/privacy}","received_events_url":"https://api.github.com/users/dhl/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2018-12-06T03:59:34Z","updated_at":"2018-12-06T04:43:30Z","closed_at":null,"author_association":"NONE","body":"We have been using [BigNumber.js](https://github.com/MikeMcl/bignumber.js) for our project.\r\n\r\nTo make our numbers work with ethers.js `Contract` instances, we made a [Proxy](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Proxy)-based wrapper and use [Reflect.apply](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/apply) to wrap the individual method functions. The function interceptors convert all BigNumber.js arguments to ethers.js BigNumber, and when the method call resolves, the ethers.js BigNumber gets converted into BigNumber.js instances.\r\n\r\nIdeally, the proxy would wrap the contract instance directly. However, this is [impossible](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Proxy/handler/get#Invariants) due to the `functions` property of Contract being non-configurable. To get around this, we make a shallow clone of the contract to make it possible to intercept the method functions.\r\n\r\nIs there a better way to do this?"},"comment":{"url":"https://api.github.com/repos/ethers-io/ethers.js/issues/comments/444746587","html_url":"https://github.com/ethers-io/ethers.js/issues/369#issuecomment-444746587","issue_url":"https://api.github.com/repos/ethers-io/ethers.js/issues/369","id":444746587,"node_id":"MDEyOklzc3VlQ29tbWVudDQ0NDc0NjU4Nw==","user":{"login":"ricmoo","id":975687,"node_id":"MDQ6VXNlcjk3NTY4Nw==","avatar_url":"https://avatars3.githubusercontent.com/u/975687?v=4","gravatar_id":"","url":"https://api.github.com/users/ricmoo","html_url":"https://github.com/ricmoo","followers_url":"https://api.github.com/users/ricmoo/followers","following_url":"https://api.github.com/users/ricmoo/following{/other_user}","gists_url":"https://api.github.com/users/ricmoo/gists{/gist_id}","starred_url":"https://api.github.com/users/ricmoo/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ricmoo/subscriptions","organizations_url":"https://api.github.com/users/ricmoo/orgs","repos_url":"https://api.github.com/users/ricmoo/repos","events_url":"https://api.github.com/users/ricmoo/events{/privacy}","received_events_url":"https://api.github.com/users/ricmoo/received_events","type":"User","site_admin":false},"created_at":"2018-12-06T04:43:30Z","updated_at":"2018-12-06T04:43:30Z","author_association":"MEMBER","body":"Couldn’t you add a “customFunctions” to the contract prototype using a proxy, which would query the functions property and perform your wrapping?\r\n\r\nI think you may have problems dealing with tuples in the future though, depending on how robust your interception is... :s\r\n\r\nWhen people need to bridge these things, my general advice is to do the conversion to/from explicitly in the code that calls/returns the values. It is easy enough to add a `ethers.utils.BigNumber.prototype.toMyCustomBigNumber()` and similarly a `fromMyCustomBigNumber(value)` and that way things don’t get spooked later on when you start dealing across other libraries expecting a non-hijacked Object and chaos ensuing. :)"}}
{"actor":{"display_login":"ricmoo"}}