Hi there. How to easily communicate to a smart contract i deployed? Crafting message or using a normal transaction

Apr 13, 2022, 10:27 PM
You can look at how various built-in contracts are implemented in TonWeb.
Apr 13, 2022, 10:28 PM
Thank you. and finally i found a ton dev community not russian
It's nice to be here ❤️
Apr 13, 2022, 10:28 PM
I wouldn't call it not Russian though 😁
Most of the knowledgeable and active people here are Russians.
Apr 13, 2022, 10:30 PM
No problem! I was just referring to the fact that the official ton dev (ENG) was full of russian messages
Apr 13, 2022, 10:31 PM
That's just bad moderation I guess :)
Apr 13, 2022, 10:34 PM
I'm testing tonweb on node with the example but the example contains async functions and it says "SyntaxError: await is only valid in async function". Am i doing smth wrong?
Apr 13, 2022, 10:41 PM
You will need to know the JavaScript on a decent level if you are going to use the TonWeb.
What examples are you talking about?
Apr 13, 2022, 10:43 PM
I fixed it by myself but i meant the example alone is not working. I needed to add personally the handling of the async stuff
Anyway thx for direction! :)
Apr 13, 2022, 10:47 PM
What example are you talking about? Can you point me to the problem directly?
Apr 13, 2022, 10:53 PM
copying and paste this in a raw .js gives me the async warning
Apr 13, 2022, 10:54 PM
Yeah, I see. That's because global awaits are not supported in CommonJS. You will need to wrap it in async function.
// This will do the trick
(async () => {
await doSomethnig();
})();
Apr 13, 2022, 10:55 PM
That worked too! Thx!
Apr 13, 2022, 10:57 PM
These examples are not meant to be just copied and pasted directly. It's just a rough idea of how to use the TonWeb. We will be rewriting all the documentation in the near future.
Apr 13, 2022, 10:57 PM
I have a generated keypair. How to import the secretKey in code? I tried passing it as a string (hex version) but didnt work
Apr 13, 2022, 11:21 PM
Secret key should be passed as Uint8Array.
nacl will give you the keys in the correct format already.
You can also do the following:

const secretKey = TonWeb.utils.hexToBytes('YOUR HEX');
const keyPair = TonWeb.utils.nacl.sign.keyPair.fromSecretKey(secretKey);
Apr 13, 2022, 11:29 PM
That's not true
Node.js supports global await, but you might need to update it and enable new features
Apr 13, 2022, 11:54 PM
Yes, it is only supported in ESM modules. So your file must have an .mjs extension and it must be compiled to ESM. It is rarely used in practice, so I've generalized.
Apr 13, 2022, 11:57 PM
How to switch to testnet tonweb? Am i forced to get an api key for https://testnet.toncenter.com/api/v2/jsonRPC?
Apr 14, 2022, 12:12 AM
You will need to set proper TonCenter URL when you initialize the TonWeb provider.
Apr 14, 2022, 12:13 AM
Ok Done. Default is mainnet. I was getting too confused haha
Looks like const secretKey = TonWeb.utils.hexToBytes('F2049F029029E092F90EF90290EF2F2E0F209'); gives me a Error: bad secret key size
Apr 14, 2022, 12:38 AM
Private key must have 64 bytes or 128 chars in HEX format.
Your HEX-string is incorrect in general, because it has odd number of chars.
Apr 14, 2022, 1:04 AM
I replaced it with random chars to hide it xd
Apr 14, 2022, 1:37 AM
Don't worry
People here are all super honest
You can post your private keys here no problem
Apr 14, 2022, 1:43 AM
It's still a testnet thing so ye, who cares
const secretKey = TonWeb.utils.hexToBytes('229715B35FE31CD0EC2DFCCEFDB381C2F9E6B284BE36D7D12B3933AD26E7B540');
const keyPair = TonWeb.utils.nacl.sign.keyPair.fromSecretKey(secretKey);
Apr 14, 2022, 1:46 AM
Just be sure it is not the same private key you use on the mainnet
Apr 14, 2022, 1:47 AM
nah it's not
Apr 14, 2022, 1:48 AM
)())))))
Apr 14, 2022, 2:12 AM

© 2024 Draquery.com All rights reserved.