embarklabs/subspace

Docs: Add instructions for `subspace` contract object

Closed this issue · 2 comments

I could not find a docs repo, so making an issue here.

In the docs site starting at Tracking State section you introduce a subspace contract object, with no details on this anywhere in the docs. Its only shown in the repo readme:

const myContract = subspace.contract(myWeb3ContractInstance);

Later in the React section you also introduce using a web3.eth.contract object directly.

It would be helpful to explain the difference and how to create a subspace contract object earlier in the documentation.

Looking forward to getting this set up in my project :)

Thanks for the feedback! Indeed, this contract object should be better documented.
I'll update the docs shortly, but in the meanwhile, the subspace.contract method what it does is returning a web3.eth.contract object decorated with a .track() for solidity functions and events,

Basically these two snippets are equivalent, with the difference being that the second one is more readable IMO:

const myEventObservable$ = subspace.trackEvent(MyContractInstance, "MyEvent", {filter: {}, fromBlock: 1 });
const myRxContract = subspace.contract(MyContractInstance);
...
const myEventObservable$ = myRxContract.events.MyEvent.track({filter: {}, fromBlock: 1 });

The .track() method is available too for view functions, and has the same signature as web3.eth.Contract.call:

const myPropObservable$ = myRxContract.methods.myFunction(someArg).track({from: web3.eth.defaultAccount});

More details about using the subspace contract object are available here: https://subspace.status.im/api.html#contract-methods

embarklabs/subspace-docs@c3d8ebc
Added docs in Getting Started section