Skip to content

Commit

Permalink
Merge pull request #371 from massalabs/fix-inheritance-example
Browse files Browse the repository at this point in the history
fix inheritance example in FT token contract
  • Loading branch information
Ben-Rey authored Nov 19, 2024
2 parents a43707b + a920805 commit d3740d9
Showing 1 changed file with 22 additions and 19 deletions.
41 changes: 22 additions & 19 deletions docs/build/smart-contract/basic-concepts/inheritance.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -11,29 +11,32 @@ This example showcases a token contract that follows the Massa Fungible Token (F
By using inheritance, you can easily create a new token with customized properties while reusing the FT standard functions.

```ts
import { Args } from '@massalabs/as-types';
import { u256 } from 'as-bignum/assembly';
export * as FT from '@massalabs/sc-standards/assembly/contracts/FT/token';

export function constructor(_: StaticArray<u8>): StaticArray<u8> {
const token_name = "My Token";
const token_symbol = "MTK";
const decimals: u8 = 18;
const totalSupply = u256.fromU64(123456);

FT.constructor(
new Args()
.add(token_name)
.add(token_symbol)
.add(decimals)
.add(totalSupply)
.serialize(),
);
import { Args } from "@massalabs/as-types";
import { u256 } from "as-bignum/assembly";
import { constructor as ftConstructor } from "@massalabs/sc-standards/assembly/contracts/FT/token";
export * from "@massalabs/sc-standards/assembly/contracts/FT/token";

export function constructor(_: StaticArray<u8>): void {
const tokenName = "My Token";
const tokenSymbol = "MTK";
const decimals: u8 = 18;
const totalSupply = u256.fromU64(123456);

ftConstructor(
new Args()
.add(tokenName)
.add(tokenSymbol)
.add(decimals)
.add(totalSupply)
.serialize()
);
}
```

## Why use inheritance with the FT standard?

Using the FT standard as a base allows you to inherit its well-defined functionalities without needing to reimplement core token mechanics. This approach ensures that your token will be compatible with existing Massa applications and services that follow the FT standard, facilitating interoperability and reliability.

## Customization with Inheritance
Extending the FT standard allows you to add new functions or modify existing ones, tailoring the token contract to your specific needs. For example, you could implement custom transfer logic, introduce new events, or include access control mechanisms for minting and burning tokens.

Extending the FT standard allows you to add new functions or modify existing ones, tailoring the token contract to your specific needs. For example, you could implement custom transfer logic, introduce new events, or include access control mechanisms for minting and burning tokens.

0 comments on commit d3740d9

Please sign in to comment.