# Which token contract I should to use?

**URL:** <https://forum.fuel.network/t/which-token-contract-i-should-to-use/373>\
**Category:** Sway\
**Created:** [December 13, 2022, 3:44pm UTC](https://forum.fuel.network/t/which-token-contract-i-should-to-use/373 "2022-12-13T15:44:26Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![fuel](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.fuel.network/fuel/32/1677_2.png) [@fuel](https://forum.fuel.network/u/fuel)\
**Post date:** [December 13, 2022, 3:44pm UTC](https://forum.fuel.network/t/which-token-contract-i-should-to-use/373/1 "2022-12-13T15:44:26Z")

</div>

Hey everyone  
I have an issue  
I’m tried to fork token contract from swayswap, but my compiler started give me error like `Expected an identifier`[right here](https://github.com/FuelLabs/swayswap/blob/c7064169ed20785cf0668ab9d19b3806462d9d24/packages/contracts/swayswap_helpers/src/main.sw#L17)

```rust
pub fn get_b256(key: b256) -> b256 {
    asm(r1: key, r2) {
        move r2 sp;
        cfei i32;
        srwq r2 r1; //👈🏻 err "Expected an identifier" right here
        r2: b256
    }
}

```

I noticed that swayswap contract use only `get_msg_sender_address_or_panic` func and replaced it on my token contract and after `forc build && cargo test `  
I see output like that

```auto
Compiled library "core".
  Compiled library "std".
  Compiled library "token_abi".
  Compiled contract "token_contract".
  Bytecode size is 13312 bytes.
    Finished test [unoptimized + debuginfo] target(s) in 0.27s
     Running tests/harness.rs (target/debug/deps/tests-7993d6f5897492f9)

running 1 test
test token_contract ... FAILED

failures:

---- token_contract stdout ----
thread 'token_contract' panicked at 'error: Could not connect to fuel core server.', /Users/alexey/.cargo/registry/src/github.com-1ecc6299db9ec823/fuels-test-helpers-0.23.0/src/node.rs:321:9
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
thread 'token_contract' panicked at 'called `Result::unwrap()` on an `Err` value: RecvError(())', /Users/alexey/.cargo/registry/src/github.com-1ecc6299db9ec823/fuels-test-helpers-0.23.0/src/node.rs:307:14

failures:
    token_contract

test result: FAILED. 0 passed; 1 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.52s

error: test failed, to rerun pass '--test tests'

```

What I’m doing wrong?

Here is a question: Is it ok to use token contract like that or maybe you have basic token contract?

---

<div class="post-metadata">

**Author:** ![fuel](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.fuel.network/fuel/32/1677_2.png) [@fuel](https://forum.fuel.network/u/fuel)\
**Post date:** [December 13, 2022, 5:14pm UTC](https://forum.fuel.network/t/which-token-contract-i-should-to-use/373/2 "2022-12-13T17:14:18Z")

</div>

The test was refactored and fixed, swayswap used old versions of packages  
[Token contract](https://github.com/chlenc/fuel-project/blob/master/token_contract/src/main.sw)  
[Token contract test](https://github.com/chlenc/fuel-project/blob/master/token_contract/tests/harness.rs)

**Btw I still don’t understand is it ok to use token contract from swayswap**

---

<div class="post-metadata">

**Author:** ![furnic](https://avatars.discourse-cdn.com/v4/letter/f/97f17d/32.png) [@furnic](https://forum.fuel.network/u/furnic)\
**Post date:** [December 13, 2022, 6:32pm UTC](https://forum.fuel.network/t/which-token-contract-i-should-to-use/373/3 "2022-12-13T18:32:54Z")

</div>

This mostly depends on what you’re trying to achieve.  
If you need a Non-Fungible Token I recommend you check out [sway-libs/sway\_libs/src/nft at master · FuelLabs/sway-libs · GitHub](https://github.com/FuelLabs/sway-libs/tree/master/sway_libs/src/nft).

On the other hand, if you want to create a Fungible Token (similar to an erc-20 token), it’s actually very simple, but also very different from how it’s done on Ethereum.

On Fuel, **any contract can be a token contract**. Contracts on Fuel have access to the `mint` opcode, and tokens minted by a contract automatically have an `AssetId` equivalent to the `ContractId` of the minting contract.

In practice, you’ll want to use the sway standard library for this. The `std::token` module has the helper functions needed for managing tokens, including minting, burning and transferring functionality.

At a bare minimum, you will need to add a function to your contract `abi` to allow some authorized user to mint tokens, and when you implement this function in your contract simply import and use the stdlib function you need. For example:

```auto
contract;

use std::token::mint_to;

impl MyTokenAbi for Contract {
    fn mint(amount: u64, to: Identity) {
    mint_to(amount, to);
}

```

For reference: [sway/token.sw at a036dc5a5b6c604f6374b040559ededd4161240e · FuelLabs/sway · GitHub](https://github.com/FuelLabs/sway/blob/a036dc5a5b6c604f6374b040559ededd4161240e/sway-lib-std/src/token.sw#L38)

Hope that helps!

---

<div class="post-metadata">

**Author:** ![fuel](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.fuel.network/fuel/32/1677_2.png) [@fuel](https://forum.fuel.network/u/fuel)\
**Post date:** [December 13, 2022, 7:19pm UTC](https://forum.fuel.network/t/which-token-contract-i-should-to-use/373/4 "2022-12-13T19:19:03Z")

</div>

Thanks for the detailed answer, everything is now clear with tokens ❤

---

<div class="post-metadata">

**Author:** ![david](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.fuel.network/david/32/32_2.png) [@david](https://forum.fuel.network/u/david)\
**Post date:** [December 14, 2022, 12:14pm UTC](https://forum.fuel.network/t/which-token-contract-i-should-to-use/373/5 "2022-12-14T12:14:14Z")

</div>

Hey, I’ve started drafting a specification for a Sway token standard, seems relevant here:

> [@SRC-20: Fungible token standard](https://forum.fuel.network/t/src-20-fungible-token-standard/186):
>
> Summary SRC-20 is a standard for fungible tokens built in Sway. Abstract SRC-20 defines a common interface for Sway smart contracts that issue fungible tokens. Given that the Fuel VM supports native assets, this standard will be primarily concerned with asset metadata (name, symbol, supply, decimals), as well as other optional functions (mint, burn). Note: while most SRCs will be numbered sequentially, the number SRC-20 was chosen to align with the EVM’s famous “ERC-20 standard”, as well oth…

Would love feedback!

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex022/uploads/fuel/original/2X/5/57d5a345cc15a64b636e0d56e042857f8a0e80b1.png) [@system](https://forum.fuel.network/u/system)\
**Post date:** [January 4, 2023, 8:15am UTC](https://forum.fuel.network/t/which-token-contract-i-should-to-use/373/6 "2023-01-04T08:15:04Z")

</div>

This topic was automatically closed 20 days after the last reply. New replies are no longer allowed.
