diff --git a/README.md b/README.md index e925206..e5fff5b 100644 --- a/README.md +++ b/README.md @@ -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 @@ -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). diff --git a/src/contracts/hrc721.ts b/src/contracts/hrc721.ts index e63f381..0eef833 100644 --- a/src/contracts/hrc721.ts +++ b/src/contracts/hrc721.ts @@ -103,14 +103,6 @@ export class HRC721 extends BaseToken { return this.call('name', [], txOptions) } - public async increaseAllowance(spender: string, value: BNish, txOptions?: ITransactionOptions): Promise { - return this.send('increaseAllowance', [spender, value], txOptions) - } - - public async decreaseAllowance(spender: string, value: BNish, txOptions?: ITransactionOptions): Promise { - return this.send('decreaseAllowance', [spender, value], txOptions) - } - public mint(account: string, tokenId: BNish, txOptions?: ITransactionOptions): Promise { return this.send('mint', [account, tokenId], txOptions) } diff --git a/src/tests/hrc721.spec.ts b/src/tests/hrc721.spec.ts index d01f816..5eb55d9 100644 --- a/src/tests/hrc721.spec.ts +++ b/src/tests/hrc721.spec.ts @@ -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)