add documentation to @harmony-js/contract

pull/21/head
Wen Zhang 5 years ago committed by Ganesha Upadhyaya
parent 3411de5cf8
commit 7ed3b6d8b7
  1. 33
      packages/harmony-account/guide.ts
  2. 107
      packages/harmony-contract/src/abi/abiCoder.ts
  3. 1
      packages/harmony-contract/src/events/eventFactory.ts
  4. 1
      packages/harmony-contract/src/methods/methodFactory.ts
  5. 1
      packages/harmony-contract/src/models/AbiItemModel.ts
  6. 1
      packages/harmony-contract/src/models/AbiModel.ts
  7. 2
      packages/harmony-core/src/harmonyExtension.ts
  8. 5
      packages/harmony-network/src/rpcMethod/rpc.ts
  9. 6
      packages/harmony-staking/src/stakingTransaction.ts

@ -233,8 +233,37 @@ Create a random account
- @harmony-js/utils
```typescript
import { Wallet } from '@harmony-js/account'
const wallet = new Wallet()
// constructor
const { Wallet } = require('@harmony-js/account');
const wallet = new Wallet(customMessenger);
// get signer
const wallet = new Wallet(customMessenger);
const key_1 = '45e497bd45a9049bcb649016594489ac67b9f052a6cdf5cb74ee2427a60bf25e';
console.log(wallet.addByPrivateKey(key_1));
console.log(wallet.signer)
// createAccount
console.log(wallet.accounts);
wallet.createAccount();
wallet.createAccount();
console.log(wallet.accounts);
// encryptAccount
const key_1 = '45e497bd45a9049bcb649016594489ac67b9f052a6cdf5cb74ee2427a60bf25e';
wallet.addByPrivateKey(key_1);
wallet.encryptAccount('one103q7qe5t2505lypvltkqtddaef5tzfxwsse4z7', '12345').then((value) => {
console.log(value);
})
// decrptAccount
const key_1 = '45e497bd45a9049bcb649016594489ac67b9f052a6cdf5cb74ee2427a60bf25e';
wallet.addByPrivateKey(key_1);
wallet.encryptAccount('one103q7qe5t2505lypvltkqtddaef5tzfxwsse4z7', '12345').then(() => {
wallet.decryptAccount('one103q7qe5t2505lypvltkqtddaef5tzfxwsse4z7', '12345').then((value) => {
console.log(value);
})
});
```
*
* @packageDocumentation

@ -3,18 +3,109 @@
*
* `@harmony-js/contract` makes it easy to interact with smart contract on the Harmony Blockchain. This allows you to interact with smart contracts as if they were JavaScript objects.
*
* Develop can use this package to:
* - Interact with Smart Contracts
*
* ## How to use this package
*
* ## Harmony Smart Contract
* Create an Contract instance
* ### Deploy a contract to blockchain
* ```javascript
* // Step 1: Use Solidity to build a sample contract instance
* contract Inbox {
* string public message;
* constructor() public {
* message = "hello";
* }
* function setMessage(string memory newMessage) public {
* message = newMessage;
* }
* }
*
* // Step 2: Use truffle to compile the contract
* $ truffle compile
*
* // Step 3: Use truffle to deploy the contract (by truffle)
* $ truffle migrate --network local --reset
* $ truffle migrate --network testnet --reset
* ```
* [Tutorial: using truffle to compile and deploy smart-contract](https://github.com/harmony-one/HRC/tree/master/examples/dapp_Lottery)
*
* ### Interact with the contract
* ```javascript
* // Step 1: create a harmony instance
* const { Harmony } = require('@harmony-js/core');
* const { ChainID, ChainType } = require('@harmony-js/utils');
* const hmy = new Harmony(
* // let's assume we deploy smart contract to this end-point URL
* 'https://api.s0.b.hmny.io'
* {
* chainType: ChainType.Harmony,
* chainId: ChainID.HmyLocal,
* }
* )
*
* // Step 2: get a contract instance
* const getContractInstance = (hmy, artifact) => {
* return hmy.contracts.createContract(artifact.abi, address);
* }
* const inbox = getContractInstance(hmy, inboxJson)
*
* // Step 3: interact with the instance
* // Example 1: methods.myMethod.call()
* const message = await inbox.methods.message().call();
* console.log(message);
*
* // Example 2: methods.myMethod.send()
* inbox.methods.setMessage('666').send({
* gasLimit: '1000001',
* gasPrice: new hmy.utils.Unit('10').asGwei().toWei(),
* });
* ```
*
* ### Integrate MathWallet
* Using MathWallet to sign Transaction
* ```javascript
* import { waitForInjected, getExtAccount } from '../util/hmy-util'
* import { Harmony, HarmonyExtension } from '@harmony-js/core'
* import { ChainID, ChainType } from '@harmony-js/utils'
* // Step 0: set up MathWallet extension on Chrome
*
* // Step 1: Create a harmonyExtension instance
* const { Harmony, HarmonyExtension } = require('@harmony-js/core');
* let hmyEx, ExContract;
* export const initExtension = async() => {
* hmyEx = await new HarmonyExtension(window.harmony);
*
* exContract = hmyEx.contracts.createContract(abi, address);
* return exContract;
* };
*
* // Step 2: interact with hmyEx instance
* // wait for hmy inject into window
* async componentDidMount() {
* ...
* await waitForInjected()
* ...
* }
* // Example: methods.myMethod.send()
* onSubmit = async event => {
* const exContract = await initExtension()
* await exContract.methods.Mymethod().send({
* value: new hmy.utils.Unit('1').asOne().toWei(),
* })
* }
*
* // wait for injected
* export const waitForInjected = () => new Promise((resolve) => {
* const check = () => {
* if (!window.harmony) setTimeout(check, 250);
* else resolve(window.harmony);
* }
* check();
* });
* ```
*
* ## [More Examples: HRC repo](https://github.com/harmony-one/HRC/tree/master/examples)
* - Lottery
* - HRC 20
* - HRC 721
* - Node-dao
* - Node-faucet
*
* @packageDocumentation
* @module harmony-contract
*/

@ -1,6 +1,7 @@
/**
* @packageDocumentation
* @module harmony-contract
* @hidden
*/
import { isArray } from '@harmony-js/utils';

@ -1,6 +1,7 @@
/**
* @packageDocumentation
* @module harmony-contract
* @hidden
*/
import { AbiCoderClass } from '../abi/api';

@ -1,6 +1,7 @@
/**
* @packageDocumentation
* @module harmony-contract
* @hidden
*/
import { isArray } from '@harmony-js/utils';

@ -1,6 +1,7 @@
/**
* @packageDocumentation
* @module harmony-contract
* @hidden
*/
import { AbiItemModel } from './types';

@ -84,7 +84,7 @@ export class HarmonyExtension {
* ```javascript
* // Using Mathwallet instance
* export const initEx = async() => {
* hmyEx = await new HarmonyExtension(window.harmony);
* hmyEx = new HarmonyExtension(window.harmony);
* }
* ```
*/

@ -3,11 +3,6 @@
*
* `@harmony-js/network` provides functions to handle messenger, providers and subscriptions...
*
* Develop can use this package to:
* - messenger
* - providers
* - subscription
*
* ## How to use this package
*
* ### 1. Create a Message

@ -36,7 +36,6 @@ export const enum Directive {
DirectiveCollectRewards,
}
/** @hidden */
export class StakingTransaction extends TransactionBase {
private directive: Directive;
private stakeMsg: CreateValidator | EditValidator | Delegate | Undelegate | CollectRewards;
@ -322,7 +321,6 @@ export class CommissionRate {
}
}
/** @hidden */
export class CreateValidator {
validatorAddress: string;
description: Description;
@ -370,7 +368,6 @@ export class CreateValidator {
}
}
/** @hidden */
export class EditValidator {
validatorAddress: string;
description: Description;
@ -409,7 +406,6 @@ export class EditValidator {
}
}
/** @hidden */
export class Delegate {
delegatorAddress: string;
validatorAddress: string;
@ -428,7 +424,6 @@ export class Delegate {
}
}
/** @hidden */
export class Undelegate {
delegatorAddress: string;
validatorAddress: string;
@ -447,7 +442,6 @@ export class Undelegate {
}
}
/** @hidden */
export class CollectRewards {
delegatorAddress: string;
constructor(delegatorAddress: string) {

Loading…
Cancel
Save