Error: The JSON parameter could not be used because there was no schema for it, when trying to init the contract

I’ve added schema-embed but still can’t pass parameter on init func, following is my code

/// The parameter type for the contract function `init` and `setMetadataUrl`.
#[derive(Serialize, SchemaType, Clone)]
struct SetMetadataUrlParams {
    /// The URL following the specification RFC1738.
    url:  String,
    /// The hash of the document stored at the above URL.
    hash: Option<Sha256>,
}

/// Initialize contract instance with no initial tokens.
/// Logs a `Mint` event for the single token id with no amounts.
#[init(
    contract = "cis2-bridgeable",
    parameter = "SetMetadataUrlParams",
    event = "BridgeableEvent",
    enable_logger,
    crypto_primitives
)]
fn contract_init<S: HasStateApi>(
    ctx: &impl HasInitContext,
    state_builder: &mut StateBuilder<S>,
    logger: &mut impl HasLogger,
    _crypto: &impl HasCryptoPrimitives,
) -> InitResult<State<S>> {
    // Get the instantiater of this contract instance.
    let invoker = Address::Account(ctx.init_origin());

    let params: SetMetadataUrlParams = ctx.parameter_cursor().get()?;

    // Create the metadata_url
    let metadata_url = MetadataUrl {
        url:  params.url.clone(),
        hash: params.hash,
    };

    // Construct the initial contract state.
    let mut state = State::new(state_builder, metadata_url.clone());

    state.grant_role(&invoker, Roles::Admin, state_builder);

    // Log event for the newly minted token.
    logger.log(&BridgeableEvent::Cis2Event(Cis2Event::Mint(MintEvent {
        token_id: TOKEN_ID,
        amount:   TOKEN_AMOUNT_ZERO,
        owner:    invoker,
    })))?;

    // Log event for where to find metadata for the token
    logger.log(&BridgeableEvent::Cis2Event(Cis2Event::TokenMetadata::<
        _,
        ContractTokenAmount,
    >(TokenMetadataEvent {
        token_id: TOKEN_ID,
        metadata_url,
    })))?;

    // Log event for the new admin.
    logger.log(&BridgeableEvent::GrantRole(GrantRoleEvent {
        address: invoker,
        role:    Roles::Admin,
    }))?;

    Ok(state)
}

Can you please provide more detailed steps?

So you built the contract with cargo concordium -e ...?

And then deployed the resulting module? And then initialized an instance from it?

Can you give the address?

Build Command:
cargo concordium build --schema-embed --schema-out schema.bin --out cis2-bridgeable-pixp.wasm.v1

Deploy Command:
concordium-client module deploy cis2-bridgeable-pixp.wasm.v1 --sender 4D3RtGf7zbg7JtBrrsjXVuTMCNgDcnr5M1TKpXqTTBtHENTWtR --name cis2-bridgeable-pixp --grpc-ip node.testnet.concordium.com

Init Command:
concordium-client contract init 03a289788898f41f5c418e46e347179855e7f70909aef6959e224c59c7a005ea --sender 4D3RtGf7zbg7JtBrrsjXVuTMCNgDcnr5M1TKpXqTTBtHENTWtR --parameter-json init.json --energy 30000 --contract cis2-bridgeable-pixp --grpc-ip node.testnet.concordium.com

Init Params:
{
“url”: “metadata.json · GitHub
}

The contract in this module (03a289788898f41f5c418e46e347179855e7f70909aef6959e224c59c7a005ea) is called cis2-bridgeable not cis2-bridgeable-pixp.

Why are you trying to initialize cis2-bridgeable-pixp?

Hey @afzalimdad9 as per @abizjak 's comment you can see it from your init function that your contract name is not cis2-bridgeable-pixp it is cis2-bridgeable.

/// Initialize contract instance with no initial tokens.
/// Logs a `Mint` event for the single token id with no amounts.
#[init(
    contract = "cis2-bridgeable",
    parameter = "SetMetadataUrlParams",
    event = "BridgeableEvent",
    enable_logger,
    crypto_primitives
)]

And also, the metadata you are passing seems not right. Your SetMetadataUrlParams expects a url as a String and a hash as an Option so something like the below you will need as your init.json.
init.json
{
“url”: “metadata.json · GitHub”,
“hash”: {
“Some”: [
“SomeDummySHA256OfMetadata”
]
}
}
command
concordium-client --grpc-ip node.testnet.concordium.com contract init <YourModuleRef> --contract <YourContractName> --energy 9999 --sender <YOUR-ADDRESS> --parameter-json PATH-TO/init.json --schema dist/schema.bin

1 Like