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 identifierright here
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
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?
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:
contract;
use std::token::mint_to;
impl MyTokenAbi for Contract {
fn mint(amount: u64, to: Identity) {
mint_to(amount, to);
}