Examples: query, "exact match", wildcard*, wild?ard, wild*rd
Fuzzy search: cake~ (finds cakes, bake)
Term boost: "red velvet"^4, chocolate^2
Field grouping: tags:(+work -"fun-stuff")
Escape special characters +-&|!(){}[]^"~*?:\ - e.g. \+ \* \!
Range search: properties.timestamp:[1587729413488 TO *] (inclusive), properties.title:{A TO Z}(excluding A and Z)
Combinations: chocolate AND vanilla, chocolate OR vanilla, (chocolate OR vanilla) NOT "vanilla pudding"
Field search: properties.title:"The Title" AND text
Answered
What should "data" contain when send transaction to smart contract recv_internal method using TON Wallet extension?

Hello, I have deployed smart contract and I want to send message to recv_internal function, which takes 4 arguments (int balance, int value, cell msg_full, slice msg_body).

I send transaction and it is processed in the blockchain:

ton.send("ton_sendTransaction",
[{
		to: "contract addr",
		value: "50000000",
		data: "serialized msg_body, hex format",
		dataType: "hex"
}]);

But recv_internal takes wrong msg_body and this results in a logic exception, because deserialized op from msg_body doesn't equal the passed one in data. Serialization and smart contract were tested, everything works fine.

Also I tried to pass in "data" serialized message, which described in docs, but wallet throw API Error.

What should I pass to the "data" argument?

  
  
Posted one year ago
Votes Newest

Answers


  1. It's important to note that the recv_internal function is only triggered by contract messages. This means it can only be triggered by a smart contract calling it from within its own function or from another contract.

  2. The reason you're receiving an API error is likely due to incorrect message structure. When calling the API, it's important to follow the correct message structure. Here's an example for calling the API after compiled the Tact language:

import {
    TonClient,
    WalletContractV4,
    internal,
    beginCell,
    toNano,
    contractAddress,
    Address,
    fromNano,
    TonClient4,
    Dictionary,
} from "ton";
import { mnemonicToPrivateKey } from "ton-crypto";
import { TestTest, storeInput } from "./output/sample_TestTest";
import * as dotenv from "dotenv";
dotenv.config();

let Address_1 = Address.parse("Your Address");

async function main() {
    // Create Client
    const client = new TonClient4({
        endpoint: "https://sandbox-v4.tonhubapi.com",
    });

    let mnemonics = (process.env.mnemonics || "").toString(); // Your mnemonics
    let keyPair = await mnemonicToPrivateKey([mnemonics]);

    // Create wallet contract
    let workchain = 0; // Usually you need a workchain 0
    let wallet = WalletContractV4.create({ workchain, publicKey: keyPair.publicKey });
    let wallet_address = client.open(wallet);
    console.log("Wallet Address: \n" + wallet_address.address);

    // Get balance
    let balance: bigint = await wallet_address.getBalance();
    console.log("Current deployment wallet balance = ", fromNano(balance).toString(), "💎TON");

    let init = await TestTest.init(Address_1);
    let contract_address = contractAddress(0, init);
    // let contract_dataFormat = GameCollections.fromAddress(contract_address);

    let contract_dataFormat = TestTest.fromAddress(contract_address);
    let contract = client.open(contract_dataFormat);

    const user_list: Dictionary<bigint, Address> = Dictionary.empty();
    user_list.set(0n, Address_1);

    const myDict_value: Dictionary<bigint, bigint> = Dictionary.empty();
    myDict_value.set(0n, toNano("0.1"));

    let packed_2 = beginCell()
        .store(
            storeInput({
                $$type: "Input",
                length: 6n, // How many items
                user_list: user_list,
                sending_value: myDict_value,
            })
        )
        .endCell();

    console.log("\nSending Txs......");
    let seqno: number = await wallet_address.getSeqno();

    let transfer = await wallet_address.sendTransfer({
        seqno: seqno,
        secretKey: keyPair.secretKey,
        messages: [
            internal({
                to: contract.address,
                value: toNano("0.6"),
                init: {
                    code: init.code,
                    data: init.data,
                },
                bounce: true,
                body: packed_2, 
            }),
        ],
    });
    console.log("==== Txs Sent ===");
}
main();

It's also important to note that recv_external is used when sending a message from outside the smart contract.

https://ton.org/docs/develop/smart-contracts/guidelines/external-messages

  
  
Posted one year ago
868 Views
1 Answer
one year ago
one year ago
Tags