{"id":15155513,"url":"https://github.com/pawelpisarek/eth-observable","last_synced_at":"2026-01-21T17:32:24.301Z","repository":{"id":57153367,"uuid":"112841718","full_name":"PawelPisarek/eth-observable","owner":"PawelPisarek","description":"observable ethereum wraper","archived":false,"fork":false,"pushed_at":"2017-12-27T20:44:01.000Z","size":156,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-15T19:48:42.429Z","etag":null,"topics":["angular4","blockchain","dapp","ethereum","ethereum-contract","observable","solidity","truffle-framework","web3js"],"latest_commit_sha":null,"homepage":null,"language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/PawelPisarek.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-12-02T12:50:15.000Z","updated_at":"2017-12-06T08:46:09.000Z","dependencies_parsed_at":"2022-09-06T16:11:55.160Z","dependency_job_id":null,"html_url":"https://github.com/PawelPisarek/eth-observable","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PawelPisarek%2Feth-observable","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PawelPisarek%2Feth-observable/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PawelPisarek%2Feth-observable/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PawelPisarek%2Feth-observable/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/PawelPisarek","download_url":"https://codeload.github.com/PawelPisarek/eth-observable/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247653417,"owners_count":20973826,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["angular4","blockchain","dapp","ethereum","ethereum-contract","observable","solidity","truffle-framework","web3js"],"created_at":"2024-09-26T18:22:38.243Z","updated_at":"2026-01-21T17:32:24.244Z","avatar_url":"https://github.com/PawelPisarek.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# eth-observable\n\nWraper to _web3_ to instatly reload data from _smart contract_ :tada:\n\n\n# Installation\n\n`npm install eth-observable --save`\n\n# Example:\nhttps://github.com/PawelPisarek/truffle-angular-starter\n\n## 1. Create enum to represent smartcontract data. Every smartcontract service has own enum\n```\nexport enum ContractEnum {\n  PING, PONG\n}\n```\n\n## 2 Create staticData, deployed interface and ContractValues class\n### eg PongStaticData, PongDeployed, PongContract\n```\nexport class PongStaticData {\n  constructor(public pongval: string, public creator: string) {\n  }\n}\nexport interface PongDeployed extends TruffleContract {\n  pongval\n  getAddress;\n  getPongvalTransactional()\n  getPongvalConstant()\n  setPongval(_pongval, from)\n  getPongvalTxRetrievalAttempted()\n  kill()\n}\n\nexport class PongContract implements ContractValues\u003cPongDeployed, PongStaticData\u003e {\n\n  constructor(public deployed: PongDeployed, public contract: PongStaticData) {\n  }\n\n  getDeployed(): PongDeployed {\n    return this.deployed;\n  }\n\n  getStaticData(): PongStaticData {\n    return this.contract;\n  }\n}\n```\n\n\n##  3. Create service to manage smart contract\n```\nimport {default as Web3} from \"web3\";\nimport {InitializeContract, DeployedAndStaticData, ValuesContract, EthObservable, initializeContractHelper,\n  hideValuesHelper,\n  AppState,\n  ContractValues, TruffleContract} from \"eth-observable\";\nimport * as pong_artifacts from \"../../../build/contracts/Pong.json\";\n\n@Injectable()\nexport class PongService implements InitializeContract\u003cContractEnum\u003e, ValuesContract\u003cPongDeployed, PongStaticData\u003e {\n  private pongSource = new Subject\u003cDeployedAndStaticData\u003cPongDeployed, PongStaticData, string\u003e\u003e();\n  pong$ = this.pongSource.asObservable();\n  public dependsOnModifier = [true, true];\n\n  constructor() {\n  }\n\n  getUniqueName(): ContractEnum {\n    return ContractEnum.PONG;\n  }\n\n  initialize(contractFactoryService: EthObservable, contractsEnum: InitializeContract\u003cContractEnum\u003e, app: AppState): Observable\u003cany\u003e {\n    return initializeContractHelper(contractFactoryService, this, this, pong_artifacts, this.pongSource, app);\n  }\n\n  hideValues(array: any[]): any[] {\n    return hideValuesHelper(array, this.dependsOnModifier);\n  }\n\n  getContractValuesPromise(deployed: PongDeployed, web3: Web3, hideVal: InitializeContract\u003cany\u003e): Promise\u003cContractValues\u003cPongDeployed, PongStaticData\u003e\u003e {\n    const values = [deployed.pongval, deployed.getAddress.call()];\n    return Promise.all(hideVal.hideValues(values))\n      .then(data =\u003e {\n        return new PongContract(deployed, new PongStaticData(data[0], data[1]));\n      });\n  }\n}\n```\n\n## 4. Enjoy observable data from smart contract\n```\n export class ContractSenderComponent implements OnInit {\n  pong: DeployedAndStaticData\u003cPongDeployed, PongStaticData, string\u003e;\n  amount: number;\n\n  constructor(public _ethObservable: EthObservable, private _pongService: PongService) {\n  }\n\n  ngOnInit() {\n    this._pongService.pong$.subscribe((data) =\u003e {\n      this.pong = data;\n    });\n  }\n\n  onSubmit() {\n    this.pong.deployed.setPongval(this.amount, {from: this.pong.yoursAccounts});\n    this._ethObservable.refresh(this._pongService);\n  }\n\n  initialize(appState: AppState) {\n    return this._pongService.initialize(this._ethObservable, this._pongService, appState);\n  }\n}\n\n```\n\n## 5. Initialize all data\n```\nexport class AppComponent {\n    this._ethObservable.createConnection(new Web3(new Web3.providers.HttpProvider('http://localhost:8545')));\n    new Promise(res =\u003e {\n      this._ethObservable.web3.eth.getAccounts((err, accs) =\u003e {\n        if (err != null) {\n          alert(\"There was an error fetching your accounts.\");\n          return;\n        }\n        if (accs.length === 0) {\n          alert(\"Couldn't get any accounts! Make sure your Ethereum client is configured correctly.\");\n          return;\n        }\n        this.accounts = accs;\n        this.account = this.accounts[0];\n        console.dir(this.accounts);\n        return res(this.account);\n      });\n    }).then((k: string) =\u003e {\n      const appState = new AppState(new Map(), new Map(), new Map(), k);\n      this._ethObservable.getAccounts()\n        .map(contractEnum =\u003e {\n          this._ethObservable.getContract(appState.mapAllContractFunction.get(contractEnum), appState);\n          return contractEnum;\n        })\n        .subscribe();\n      this.ping.initialize(appState).subscribe();\n      this.pong.initialize(appState).subscribe();\n    });\n  }\n}\n```\n\n```\n{{ ping?.staticData.address  }}\n```\n\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpawelpisarek%2Feth-observable","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpawelpisarek%2Feth-observable","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpawelpisarek%2Feth-observable/lists"}