Class

FabricERC20Contract

FabricERC20Contract(name) → {void}

Constructor

# new FabricERC20Contract(name) → {void}

Implements ERC20-like token logic using repositories and adapters, providing standard token operations such as balance queries, transfers, approvals, minting and burning.

ERC20 token contract base for Hyperledger Fabric

sequenceDiagram participant Client participant Contract participant WalletRepo participant TokenRepo participant Ledger Client->>Contract: Transfer(ctx, to, value) Contract->>WalletRepo: read(from) Contract->>WalletRepo: read(to) Contract->>Ledger: putState(updated balances) Contract-->>Client: success
Parameters:
Name Type Description
name string

The contract name used to scope token identity

View Source contracts/erc20/erc20contract.ts, line 19

void
Example
class MyTokenContract extends FabricERC20Contract {
  constructor() { super('MyToken'); }
}
// The contract exposes methods like Transfer, Approve, Mint, Burn, etc.

Methods

# async Allowance(ctx, owner, spender) → {number}

Returns the amount of tokens which is allowed to withdraw from owner.

Returns the amount of tokens which is allowed to withdraw from owner.

Parameters:
Name Type Description
ctx Context

the transaction context

owner String

The owner of tokens

spender String

The spender who are able to transfer the tokens

View Source contracts/erc20/erc20contract.ts, line 624

Return the amount of remaining tokens allowed to spent

number

# async Approve(ctx, spender, value) → {Boolean}

Allows spender to spend value amount of tokens from the owner.

Allows spender to spend value amount of tokens from the owner. New Approve calls override the previous allowance.

Parameters:
Name Type Description
ctx Context

the transaction context

spender String

The spender

value number

The amount of tokens to be approved for transfer

View Source contracts/erc20/erc20contract.ts, line 613

Return whether the approval was successful or not

Boolean

# async BalanceOf(ctx, owner) → {Number}

BalanceOf returns the balance of the given account.

BalanceOf returns the balance of the given account.

Parameters:
Name Type Description
ctx Context

the transaction context

owner String

The owner from which the balance will be retrieved

View Source contracts/erc20/erc20contract.ts, line 576

Returns the account balance

Number

# async Burn(ctx, amount) → {Object}

Burn redeem tokens from minter's account balance

.

Burn redeem tokens from minter's account balance

Parameters:
Name Type Description
ctx Context

the transaction context

amount number

amount of tokens to be burned

View Source contracts/erc20/erc20contract.ts, line 656

The balance

Object

# async BurnFrom(ctx, account, amount) → {Object}

BurnFrom redeem tokens from account allowence and balance

.

BurnFrom redeem tokens from account allowence and balance

Parameters:
Name Type Description
ctx Context

the transaction context

account number

account from where tokens will be burned

amount number

amount of tokens to be burned

View Source contracts/erc20/erc20contract.ts, line 667

The balance

Object

# async ClientAccountBalance(ctx) → {Number}

ClientAccountBalance returns the balance of the requesting client's account.

ClientAccountBalance returns the balance of the requesting client's account.

Parameters:
Name Type Description
ctx Context

the transaction context

View Source contracts/erc20/erc20contract.ts, line 676

Returns the account balance

Number

# async Decimals(ctx) → {Number}

Return the number of decimals the token uses e.g.

Return the number of decimals the token uses e.g. 8, means to divide the token amount by 100000000 to get its user representation.

Parameters:
Name Type Description
ctx Context

the transaction context

View Source contracts/erc20/erc20contract.ts, line 557

Returns the number of decimals

Number

# async Initialize(ctx, name, symbol, decimals, totalSupply)

Set optional infomation for a token.

Set optional infomation for a token.

Parameters:
Name Type Description
ctx Context

the transaction context

name String

The name of the token

symbol String

The symbol of the token

decimals String

The decimals of the token

totalSupply String

The totalSupply of the token

View Source contracts/erc20/erc20contract.ts, line 636

# async Mint(ctx, amount) → {Object}

Mint creates new tokens and adds them to minter's account balance

.

Mint creates new tokens and adds them to minter's account balance

Parameters:
Name Type Description
ctx Context

the transaction context

amount number

amount of tokens to be minted

View Source contracts/erc20/erc20contract.ts, line 646

The balance

Object

# async Symbol(ctx) → {String}

Return the symbol of the token.

Return the symbol of the token. E.g. “HIX”.

Parameters:
Name Type Description
ctx Context

the transaction context

View Source contracts/erc20/erc20contract.ts, line 547

Returns the symbol of the token

String

# async TotalSupply(ctx) → {Number}

Return the total token supply.

Return the total token supply.

Parameters:
Name Type Description
ctx Context

the transaction context

View Source contracts/erc20/erc20contract.ts, line 566

Returns the total token supply

Number

# async Transfer(ctx, to, value) → {Boolean}

Transfer transfers tokens from client account to recipient account.

recipient account must be a valid clientID as returned by the ClientAccountID() function.

Parameters:
Name Type Description
ctx Context

the transaction context

to String

The recipient

value number

The amount of token to be transferred

View Source contracts/erc20/erc20contract.ts, line 589

Return whether the transfer was successful or not

Boolean

# async TransferFrom(ctx, from, to, value) → {Boolean}

Transfer value amount of tokens from from to to.

Transfer value amount of tokens from from to to.

Parameters:
Name Type Description
ctx Context

the transaction context

from String

The sender

to String

The recipient

value number

The amount of token to be transferred

View Source contracts/erc20/erc20contract.ts, line 601

Return whether the transfer was successful or not

Boolean