Is there an analogue of Rust's `add_custom_asset` in TS SDK?

Rust has a handy function for adding assets to inputs: add_custom_asset.

In TypeScript SDK I see that there is the forward parameter, but it doesn’t allow to specify the destination address.

So, is there a similar function to Rust or what should I do in order to add an input with a custom destination in TS?


Hey @mpoplavkov,

Not a complete like for like with add_custom_asset in the RS SDK, however we do have access to the transaction request on the contract invocation scope. Here we can add coin outputs for other addresses.

    // Setup / deploy the contract
    const contract = new ContractFactory(contractBytecode, abi, wallet);
    const contractInstance = await contract.deployContract({ gasPrice });
    // Create the invocation scope
    const scope = contractInstance.functions.my_contract_function().txParams({ gasPrice });
    // Funding the transaction
    await scope.fundWithRequiredCoins();
    // Get the transaction request
    const transactionRequest = await scope.getTransactionRequest();
    // Add coin output for recipient address
    transactionRequest.addCoinOutput(receiver.address, 10_000, BaseAssetId);
    // Submit transaction
    const response = await wallet.sendTransaction(transactionRequest);
    await response.waitForResult();
    // Get result of contract function (my_contract_function)
    const { value } = await[scope], response, false, contract);

Not necessary, but I also added how you could build out the result of the contract call from a tx request through a FunctionInvocationResult .


FYI: the solution above works in the 0.75.0 version and doesn’t work in 0.73.0


This topic was automatically closed 20 days after the last reply. New replies are no longer allowed.