Unable to Add NFT to market Place

Could anyone suggest me what I’m missing as I’m unable to add NFT to market place, here I’m sharing the screenshot of the error and here is my add-market.json file format

{

"nft_contract_address": { "index": 2109, "subindex": 0 },

"token_id": "00000157",

"price": "1",

"quantity":"1"

}

Without access to the contract we cannot be sure. But this looks like you are passing it incorrect arguments.

If you show me the contract or at least the schema for the entrypoint I can help debugging it.

@abizjak I was using the concordium client here is my command:

./concordium-client --grpc-ip 35.90.185.212 --grpc-port 10001 contract update 2113 --entrypoint add --parameter-json ./nft-artifacts/add-marketplace.json --schema ./dist/marketplace-contract/schema.bin --sender 4B7MN4Btj7mnSwYPXxCH8Aa46oL4FW7JtdNXE8SNi1GutgNf46 --energy 10000

Could you please suggest me Which parameters I’m missing?

As I’m running the command using concordium client which is giving me error:

Error: Updating contract instance failed: ‘add’ in ‘Market-Place-NFT’ at {“index”:2113,“subindex”:0} failed with code -1

What is ./dist/marketplace-contract/schema.bin?

@abizjak this is the location of the file where the schema of the contract resides

Yes, I want to get the contents of that file.

@abizjak Can you please provide me your email so I can share the file with you as it is not supported here in the attachment.

I may be wrong but if token_id , price, quantity are integers then you don’t need double quotes in parameter.json (“00000157”)

@blue Okay Let me check and Update you

Hello @abizjak I’m now able to add NFT using the old contract but Could you please suggest me What I’m missing in the Transfer Function (Transfer NFT to Another Account in market Place)

Payload:
{

“nft_contract_address”: {

  "index": 1625,

  "subindex": 0

},

“to”: “3yowPBLpS6nPXSPTEqq11ADrmQz8Yd2MEcgzXYYZYNtfjKV4u4”,

“token_id”: “00000201”

}

Command:
./concordium-client --grpc-ip 35.90.185.212 --grpc-port 10001 contract update 1817 --entrypoint transfer --parameter-json ./nft-artifacts/transfer-marketplace.json --schema ./dist/marketplace-contract/schema.bin --sender 4oJDR7mgQf5m7vtvVUMt3hbBc8je1VhsJsFDbJfWiBux9Ljge7 --energy 6000

I would need to see the contract to understand what error code -6 means. That is defined by the contract. If you can share the Rust code then I can help.

@abizjak Its from the NFT Minting Tutorial from the medium, let me share you the file.

This is the Transfer Function in Which I’m facing error:

#[receive(

contract = "Market-NFT",

name = "transfer",

parameter = "TransferParams",

mutable,

payable

)]

fn transfer<S: HasStateApi>(

ctx: &impl HasReceiveContext,

host: &mut impl HasHost<State<S>, StateApiType = S>,

amount: Amount,

) → ContractResult<()> {

let params: TransferParams = ctx

    .parameter_cursor()

    .get()

    .map_err(|_e| MarketplaceError::ParseParams)?;

let token: TokenState = host

    .state()

    .get_token(params.token_id, params.nft_contract_address)

    .ok_or(MarketplaceError::TokenNotListed)?

    .to_owned();

if let state::TokenListState::Listed(price) = token.get_curr_state() {

    ensure!(

        amount.cmp(&price).is_ge(),

        MarketplaceError::InvalidAmountPaid

    );

    let amounts = calculate_amounts(&amount, &host.state().commission);

    Cis2Client::transfer(

        host,

        params.token_id,

        params.nft_contract_address,

        concordium_cis2::TokenAmountU8(1),

        token.get_owner(),

        concordium_cis2::Receiver::Account(params.to),

    )

    .map_err(MarketplaceError::Cis2ClientError)?;

    host.invoke_transfer(&token.get_owner(), amounts.to_owner)

        .map_err(|_| MarketplaceError::InvokeTransferError)?;

    host.invoke_transfer(&ctx.owner(), amounts.to_marketplace)

        .map_err(|_| MarketplaceError::InvokeTransferError)?;

    host.state_mut()

        .delist_token(params.token_id, params.nft_contract_address, params.to);

} else {

    bail!(MarketplaceError::TokenNotListed)

};

ContractResult::Ok(())

}

Can you show what the ContractResulttype is?

I assume it is something like

type ContractResult<A> = Result<A, ContractError>

Can you show what the ContractError is?

@abizjak

use errors::MarketplaceError;

type ContractResult = Result<A, MarketplaceError>;

use concordium_std::*;

#[derive(Serialize, Debug, PartialEq, Eq, Reject)]

pub enum MarketplaceError {

ParseParams,

CalledByAContract,

TokenNotListed,

Cis2ClientError(Cis2ClientError),

CollectionNotCis2,

InvalidAmountPaid,

InvokeTransferError,

NoBalance,

NotOperator

}

From this I guess that this fails

ensure!(

            amount.cmp(&price).is_ge(),

            MarketplaceError::InvalidAmountPaid

        );

which means you probably have not transferred enough CCD. Does that make sense?

You should add an --amount flag to the concordium-client invocation, with the amount you wish to transfer.

@abizjak Okay Let me try as you mentioned but I have a question we are transferring an NFT to Other account address so do we have to add amount or the amount will de deducted from the another account address.

You cannot withdraw CCD from somebody else’s account. They have to authorize that.

You could write your contract in a way that you authorize the sale, and then the buyer needs to come and transfer CCD to the the contract to actual affect the sale. But I don’t see that being done in your contract.

@abizjak This worked for me Thank You for the Support