Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix inheritance example in FT token contract #371

Merged
merged 1 commit into from
Nov 19, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
fix inheritance example in FT token contract
Ben-Rey committed Nov 19, 2024
commit a92080579bd5a19143adf5645abee4ca73a3e426
41 changes: 22 additions & 19 deletions docs/build/smart-contract/basic-concepts/inheritance.mdx
Original file line number Diff line number Diff line change
@@ -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.