As your first week at the prestigious Motoko School comes to an end, you're in awe of the wealth of knowledge and collaborative spirit that surrounds you. The school is a hub of innovation and creativity, drawing the brightest minds from around the world to master the art of building on the Internet Computer. 🏗️
One evening, while exploring the school's virtual library, you stumble upon a hidden section filled with stories of the school's successful alumni. You're fascinated by their accomplishments, yet you notice a common theme: many have built incredible wealth, but only a few have given back to the school. 🫢
At the same time, you overhear a conversation about the school's financial struggles and its inability to provide adequate resources for students in need. This revelation weighs heavily on your mind, and you feel compelled to find a solution that bridges the gap between the school's prosperous alumni and its underfunded programs. 💸
Inspired by the alumni stories, you envision a digital token that connects the past, present, and future of the Motoko School – the MotoCoin. This token would allow alumni and other investors to invest in the school's future while supporting its present needs. 🌱
You share your idea with a group of enthusiastic students, and together, you begin working tirelessly to bring MotoCoin to life. Built on the Internet Computer, the MotoCoin would enable investors, students, contributors to participate to the school's growth and success. 🚀
Your task is to create a ledger for a token that can be used as a currency for the school. The ledger is implemented as a canister.
We define the following types:
type Subaccount = Blob;
type Account = {
owner : Principal;
subaccount : ?Subaccount;
};
Your canister should implement the following interface:
actor {
// Returns the name of the token
name : shared query () -> async Text;
// Returns the symbol of the token
symbol : shared query () -> async Text;
// Returns the the total number of tokens on all accounts
totalSupply : shared query () -> async Nat;
// Returns the default transfer fee
balanceOf : shared query (account : Account) -> async (Nat);
// Transfer tokens to another account
transfer : shared (from: Account, to : Account, amount : Nat) -> async Result.Result<(), Text>;
// Airdrop 1000 MotoCoin to any student that is part of the Bootcamp.
airdrop : shared () -> async Result.Result<(),Text>;
}
- Define una variable llamada
ledger
, que es unTrieMap
. En esta estructura de datos, las claves son de tipoAccount
y los valores son de tipoNat
y representan el saldo de cada cuenta. Puedes usar las funciones auxiliares enaccount.mo
para ayudarte. - Implementa
name
, que devuelve el nombre del token como unText
. El nombre del token esMotoCoin
. - Implementa
symbol
, que devuelve el símbolo del token como unText
. El símbolo del token esMOC
. - Implementa
totalSupply
, que devuelve el número total de tokensMOC
en circulación. - Implementa
balanceOf
, que toma unaAccount
y devuelve el saldo de esta cuenta. - Implementa
transfer
que acepta tres parámetros: un objetoAccount
para el remitente (from
), un objetoAccount
para el destinatario (to
) y un valorNat
para la cantidad a transferir. Esta función debe transferir la cantidad especificada de tokens de la cuenta del remitente a la cuenta del destinatario. Esta función debe devolver un mensaje de error envuelto en un resultadoErr
si el remitente no tiene suficientes tokens en su cuenta principal. - Implementa
airdrop
que agrega 100 MotoCoin a la cuenta principal de todos los estudiantes que participan en el Bootcamp.
Para implementar airdrop, usa la función getAllStudentsPrincipal
en el canister con el ID rww3b-zqaaa-aaaam-abioa-cai
, esto devuelve la lista de todos los principales de los estudiantes que participan en el Bootcamp.
getAllStudentsPrincipal : shared () -> async [Principal];