Skip to content

Commit

Permalink
adding documentation (#53)
Browse files Browse the repository at this point in the history
  • Loading branch information
fersirni authored Aug 15, 2022
1 parent 92e20de commit eb8eaee
Show file tree
Hide file tree
Showing 3 changed files with 125 additions and 54 deletions.
125 changes: 125 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -379,6 +379,68 @@ const contract = new HRC20('0x...00', ABI, wallet)
// returns a number value.
const name = await contract.decimals() // 18
```
#### mint

Mints an amount of tokens and transfers them to the account increasing the total supply.

```ts
import { HttpProvider } from '@harmony-js/network'
import { PrivateKey, HarmonyShards, HRC20 } from 'harmony-marketplace-sdk'
import * as ABI from './abi.json'

const wallet = new PrivateKey(
new HttpProvider(HarmonyShards.SHARD_0),
'45e497bd45a9049bcb649016594489ac67b9f052a6cdf5cb74ee2427a60bf25e'
)

// A contract instance
const contract = new HRC20('0x...00', ABI, wallet)

// returns a Harmony Transaction instance.
const tx = await contract.mint('0x...01', 10)
```

#### burn

Destroys an amount of tokens from the account, reducing the total supply.

```ts
import { HttpProvider } from '@harmony-js/network'
import { PrivateKey, HarmonyShards, HRC20 } from 'harmony-marketplace-sdk'
import * as ABI from './abi.json'

const wallet = new PrivateKey(
new HttpProvider(HarmonyShards.SHARD_0),
'45e497bd45a9049bcb649016594489ac67b9f052a6cdf5cb74ee2427a60bf25e'
)

// A contract instance
const contract = new HRC20('0x...00', ABI, wallet)

// returns a Harmony Transaction instance.
const tx = await contract.burn(10)
```

#### burnFrom

Destroys amount tokens from account, deducting from the caller’s allowance.

```ts
import { HttpProvider } from '@harmony-js/network'
import { PrivateKey, HarmonyShards, HRC20 } from 'harmony-marketplace-sdk'
import * as ABI from './abi.json'

const wallet = new PrivateKey(
new HttpProvider(HarmonyShards.SHARD_0),
'45e497bd45a9049bcb649016594489ac67b9f052a6cdf5cb74ee2427a60bf25e'
)

// A contract instance
const contract = new HRC20('0x...00', ABI, wallet)

// returns a Harmony Transaction instance.
const tx = await contract.burnFrom('0x...01', 10)
```

## HRC721 API

Expand Down Expand Up @@ -649,6 +711,69 @@ const contract = new HRC721('0x...00', ABI, wallet)
const name = await contract.name() // Blockcoders NFT
```

#### mint

Mints a token with tokenId and transfers it to the account.

```ts
import { HttpProvider } from '@harmony-js/network'
import { PrivateKey, HarmonyShards, HRC721 } from 'harmony-marketplace-sdk'
import * as ABI from './abi.json'

const wallet = new PrivateKey(
new HttpProvider(HarmonyShards.SHARD_0),
'45e497bd45a9049bcb649016594489ac67b9f052a6cdf5cb74ee2427a60bf25e'
)

// A contract instance
const contract = new HRC721('0x...00', ABI, wallet)

// returns a Harmony Transaction instance.
const tx = await contract.mint('0x...01', 1)
```

#### safeMint

Safely mints a token with tokenId and transfers it to the account.

```ts
import { HttpProvider } from '@harmony-js/network'
import { PrivateKey, HarmonyShards, HRC721 } from 'harmony-marketplace-sdk'
import * as ABI from './abi.json'

const wallet = new PrivateKey(
new HttpProvider(HarmonyShards.SHARD_0),
'45e497bd45a9049bcb649016594489ac67b9f052a6cdf5cb74ee2427a60bf25e'
)

// A contract instance
const contract = new HRC721('0x...00', ABI, wallet)

// returns a Harmony Transaction instance.
const tx = await contract.mint('0x...01', 1)
```

#### burn

Destroys tokenId. The caller must own tokenId or be an approved operator.

```ts
import { HttpProvider } from '@harmony-js/network'
import { PrivateKey, HarmonyShards, HRC721 } from 'harmony-marketplace-sdk'
import * as ABI from './abi.json'

const wallet = new PrivateKey(
new HttpProvider(HarmonyShards.SHARD_0),
'45e497bd45a9049bcb649016594489ac67b9f052a6cdf5cb74ee2427a60bf25e'
)

// A contract instance
const contract = new HRC721('0x...00', ABI, wallet)

// returns a Harmony Transaction instance.
const tx = await contract.burn(1)
```

## HRC1155 API

The `HRC1155` implements the abstract class [Base Token](#base-token).
Expand Down
8 changes: 0 additions & 8 deletions src/contracts/hrc721.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,14 +103,6 @@ export class HRC721 extends BaseToken {
return this.call<string>('name', [], txOptions)
}

public async increaseAllowance(spender: string, value: BNish, txOptions?: ITransactionOptions): Promise<Transaction> {
return this.send('increaseAllowance', [spender, value], txOptions)
}

public async decreaseAllowance(spender: string, value: BNish, txOptions?: ITransactionOptions): Promise<Transaction> {
return this.send('decreaseAllowance', [spender, value], txOptions)
}

public mint(account: string, tokenId: BNish, txOptions?: ITransactionOptions): Promise<Transaction> {
return this.send('mint', [account, tokenId], txOptions)
}
Expand Down
46 changes: 0 additions & 46 deletions src/tests/hrc721.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -406,52 +406,6 @@ describe('HRC721 Contract Interface', () => {
})
})

describe('increaseAllowance', () => {
it('should return the transaction', async () => {
const stub = sinon.stub(contract, 'send').withArgs('increaseAllowance', [TEST_ADDRESS_1, TOKEN_GOLD], TX_OPTIONS)
stub.resolves()

await contract.increaseAllowance(TEST_ADDRESS_1, TOKEN_GOLD, TX_OPTIONS)
expect(stub.calledOnce).to.be.true
expect(stub.callCount).to.be.equals(1)
})

it('should throw an error if spender is not provided', async () => {
expect(contract.increaseAllowance('', TOKEN_GOLD, TX_OPTIONS)).to.be.rejectedWith(Error)
})

it('should throw an error if value is not provided', async () => {
expect(contract.increaseAllowance(TEST_ADDRESS_1, '', TX_OPTIONS)).to.be.rejectedWith(Error)
})

it('should throw an error if params are not provided', async () => {
expect(contract.increaseAllowance('', '')).to.be.rejectedWith(Error)
})
})

describe('decreaseAllowance', () => {
it('should return the transaction', async () => {
const stub = sinon.stub(contract, 'send').withArgs('decreaseAllowance', [TEST_ADDRESS_1, TOKEN_GOLD], TX_OPTIONS)
stub.resolves()

await contract.decreaseAllowance(TEST_ADDRESS_1, TOKEN_GOLD, TX_OPTIONS)
expect(stub.calledOnce).to.be.true
expect(stub.callCount).to.be.equals(1)
})

it('should throw an error if spender is not provided', async () => {
expect(contract.decreaseAllowance('', TOKEN_GOLD, TX_OPTIONS)).to.be.rejectedWith(Error)
})

it('should throw an error if value is not provided', async () => {
expect(contract.decreaseAllowance(TEST_ADDRESS_1, '', TX_OPTIONS)).to.be.rejectedWith(Error)
})

it('should throw an error if params are not provided', async () => {
expect(contract.decreaseAllowance('', '')).to.be.rejectedWith(Error)
})
})

describe('mint', () => {
it('should return the transaction', async () => {
const stub = sinon.stub(contract, 'send').withArgs('mint', [TEST_ADDRESS_1, TOKEN_GOLD], TX_OPTIONS)
Expand Down

0 comments on commit eb8eaee

Please sign in to comment.