I want to mint native asset but I keep getting an error
FuelError: The transaction reverted with an unknown reason: 0
This is my function
const mintTokens = async () => {
if (!provider || !account) {
return;
}
const wallet = Wallet.fromAddress(account, provider);
if (!wallet) {
return;
}
console.log("mintTokens");
const token = new Token(TOKEN_CONTRACT_ID, wallet);
const subID = "0x0000000000000000000000000000000000000000000000000000000000000000";
const mintAmount = bn(1000);
const recipientAddress = Address.fromString(account);
const recipientIdentity = { Address: { bits: recipientAddress.toB256() } };
const { waitForResult } = await token.functions.mint(recipientIdentity, subID, mintAmount).call();
console.log("waitForResult: ", waitForResult);
const txResult = await waitForResult();
console.log("txResult: ", txResult);
const mintedAssetId = getMintedAssetId(token.id.toB256(), subID);
console.log("mintedAssetId: ", mintedAssetId);
}
My token contract
contract;
mod errors;
mod interface;
use standards::{src20::SRC20, src3::SRC3, src5::SRC5};
use std::{
asset::{
burn,
mint_to,
},
call_frames::msg_asset_id,
constants::DEFAULT_SUB_ID,
context::msg_amount,
string::String,
};
storage {
DECIMALS: u8 = 9u8,
NAME: str[8] = __to_str_array("FuelCoin"),
SYMBOL: str[4] = __to_str_array("Fuel"),
total_supply: u64 = 0,
}
impl SRC20 for Contract {
#[storage(read)]
fn total_assets() -> u64 {
1
}
#[storage(read)]
fn total_supply(asset: AssetId) -> Option<u64> {
if asset == AssetId::default() {
Some(storage.total_supply.read())
} else {
None
}
}
#[storage(read)]
fn name(asset: AssetId) -> Option<String> {
if asset == AssetId::default() {
Some(String::from_ascii_str(from_str_array(storage.NAME.read())))
} else {
None
}
}
#[storage(read)]
fn symbol(asset: AssetId) -> Option<String> {
if asset == AssetId::default() {
Some(String::from_ascii_str(from_str_array(storage.SYMBOL.read())))
} else {
None
}
}
#[storage(read)]
fn decimals(asset: AssetId) -> Option<u8> {
if asset == AssetId::default() {
Some(storage.DECIMALS.read())
} else {
None
}
}
}
impl SRC3 for Contract {
#[storage(read, write)]
fn mint(recipient: Identity, sub_id: Option<SubId>, amount: u64) {
let sub_id = match sub_id {
Some(s) => s,
None => DEFAULT_SUB_ID,
};
require(sub_id == DEFAULT_SUB_ID, "incorrect-sub-id");
storage
.total_supply
.write(amount + storage.total_supply.read());
mint_to(recipient, DEFAULT_SUB_ID, amount);
}
#[payable]
#[storage(read, write)]
fn burn(sub_id: SubId, amount: u64) {
require(sub_id == DEFAULT_SUB_ID, "incorrect-sub-id");
require(msg_amount() >= amount, "incorrect-amount-provided");
require(
msg_asset_id() == AssetId::default(),
"incorrect-asset-provided",
);
storage
.total_supply
.write(storage.total_supply.read() - amount);
burn(DEFAULT_SUB_ID, amount);
}
}