Sponsored TXN - permit function payload creation

Hi all,

I’m trying to sponsor a txn on the backend. The example from https://github.com/Concordium/concordium-dapp-examples/tree/main/sponsoredTransactions is what I have been using.

I need to create a payload for the message. The example from the repo doesn’t show how to create one directly for the permit function.

Thanks.

The parameter for the permit function is created at the backend of the server. The server sends the transaction to the chain (the transaction is not send via the Browser wallet at the front end). E.g. here is the line for how to create the Transfer payload.

Hey @Doris,

I appreciate your effort. But the example above is for a semi-fungible token. please provide me an example of creating a mint payload through the permit function.

The sponsored transaction example in our repo showcases how you can use the transfer or the updateOperator entry points via the permit function (only these two entry points are supported in the contract to keep the example simple). I linked the NFT token contract and backend from our example here:
Smart Contract:

Backend:


It seems you want in addition to mint tokens via the sponsored transaction mechanism.
We have a semi-fungible token contract that showcases how you can set up the mint function in the smart contract to do that:

Then you can set the payload (at the backend) equal to the MintParams. For the cis2_multi smart contract (the above contract) it would look like this:

   let payload =  MintParams {
        owner:        <Address>,
        metadata_url: <MetadataUrl>,
        token_id:     <ContractTokenId>,
   };

   let message: PermitMessage = PermitMessage {
        contract_address: ContractAddress {
            index: smart_contract_index,
            subindex: 0,
        },
        nonce: request.nonce,
        timestamp: request.timestamp,
        entry_point: OwnedEntrypointName::new_unchecked("mint".into()),
        payload: concordium_rust_sdk::smart_contracts::common::to_bytes(&payload),
    };

Hey @Doris,

Thank you so much for this, Is there any frontend integration for this? Just curious to know if any :slight_smile:

Currently, we don’t have a front-end example that showcases the requested mint entrypoint out of the box. But I am confident that you can use the sponsored transaction example front end and adjust it for the mint entrypoint. Feel free to reach out if you have difficulties to do that.

2 Likes

I encountered this error when the txn is to simulate.

Error: Unable to submit transfer: {"code":500,"message":"Transaction simulation error. Your transaction would revert with the given input parameters: reason: InvalidAccountReference { contents: AccountAddress([165, 44, 226, 8, 186, 20, ...) }"}

Below is my permit message

    let mint_params = MintParams {
        owner: request.to,
        metadata_url: MetadataParams {
            url:  "https://gateway.pinata.cloud/ipfs/QmZ3939dLLFzvYZjFnkdqACe2n9TQA8Rx4efbjaYTXteeu".to_string(),
            hash: Some(vec![
                "f982b4603b9c116598d381d1aee90a7b5332377b209b6bbd8d7a4dfab18f2a80".to_string(),
            ]),
        },
        token_id: "1000".to_string(),
    };

I’m unable to trace this, what could be the possible reason?

The error comes from the rust-sdk: It means that your account does not exist on chain. Did you deploy/create the account [165, 44, 226, 8, 186, 20, …] on Concordium testnet?

1 Like

Thank you @Doris , I just encountered a strange error.

Error: Unable to submit transfer: {"code":500,"message":"Transaction simulation error. Your transaction would revert with the given input parameters: reason: InvalidContractAddress { contents: ContractAddress { index: 7754, subindex: 0 } }"}

The contract was deployed using the https://sctools.mainnet.concordium.software/.

The smart contract is deployed and has been used correctly. What could be the cause of this error?

Hi @Doris, from the rejection reasons, the reason for the invalid contract address is that a contract was not initialized. However on using the https://sctools.mainnet.concordium.software/., the contract was initialized in other to return its index. On my backend, we can also see from {"code":500,"message":"Transaction simulation error. Your transaction would revert with the given input parameters: reason: InvalidContractAddress { contents: ContractAddress { index: 7760, subindex: 0 } }"} that the index and the subindex are added properly. In my attempts to resolve this, I don’t seem to get hold of what the actual reason for this could be.

Maybe your backend is not connected to an up-to-date testnet node if it cannot find the contractAddress 7760 even it is initialized on testnet.