hicommonwealth / offchain-workers

A Substrate node template with an offchain-worker module integrated.
The Unlicense
2 stars 0 forks source link

[Question] How to send request to the Smart Contract from within offchain worker? #1

Open evgeny-s opened 3 years ago

evgeny-s commented 3 years ago

Hello. The question is in the title. I want to send signed transaction to the Smart Contract. How can I do this? Maybe some code snippets? Thanks

drewstone commented 3 years ago

You have to construct the Call directly in the offchain worker and sign it using the tools provided. You can see how it is done for a custom function here: https://substrate.dev/recipes/off-chain-workers/transactions.html#sending-signed-transactions.

Instead of the custom function, you would want to construct a call for the contracts runtime.

evgeny-s commented 3 years ago

Yes, I am not familiar with Rust. From what I can see, how it is done for the usual transaction: Screenshot from 2021-04-22 18-00-36

I was able to send usual transaction like this:

let results = signer.send_signed_transaction(
            |_account| {
                Call::submit_test_data("Hello World data".as_bytes().to_vec())
            }
        );

The big question - how to instantiate the Call instance to be able to send transactions to Smart Contract.