0

I do the same as How can you transfer balances from one accountId to another in substrate runtime? and also have ReservableCurrencySelf::AccountId in type Currency. I've created an NFT with 100 units of BalanceOf. But when I try to buy this NFT, the balance in my account seems not right (image below). My balance was 1000 units before I buy. So how can I fix this bug? enter image description here

0

1 Answer 1

1

If you expected your balance to be 900 after purchasing the NFT, you need to ensure that you are actually setting the NFT value to 100 KIT units.

To give you an example of what I mean, Polkadot token decimals are set to 10

pub fn polkadot_chain_spec_properties() -> serde_json::map::Map<String, serde_json::Value> {
    serde_json::json!({
        "tokenDecimals": 10,
    })
    .as_object()
    .expect("Map given; qed")
    .clone()
}

So, I'm assuming that when you create the NFT, you are passing the value 100 to the extrinsic, which is not correct at all if you are using the default token decimals of the chain.

The default token decimals of substrate are 12 (I think), so if you want to set your NFT value to 100 unit, you need to pass the value 100_000_000_000_000 to the extrinsic.

You are also paying for fees, so the total cost of the transaction would never be 100 units, it will be a little bit more, but that's just another topic.

2
  • Thanks! Does polkadotjs api support us to convert between int and decimal like ethereum?
    – marethyu
    Commented Aug 9, 2022 at 15:12
  • Yep, there's a function for that within the @polkadot/util package called formatBalance. This post might be helpful stackoverflow.com/questions/64210673/…
    – andresvsm
    Commented Aug 10, 2022 at 8:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.