-
-
Save andelf/f05f5403e352346e04aad0deec48aad1 to your computer and use it in GitHub Desktop.
const TronWeb = require('tronweb'); | |
const HttpProvider = TronWeb.providers.HttpProvider; | |
const fullNode = new HttpProvider("https://api.trongrid.io"); | |
// const fullNode = new HttpProvider("http://192.168.1.162:8090"); | |
const solidityNode = new HttpProvider("https://api.trongrid.io"); | |
const eventServer = new HttpProvider("https://api.trongrid.io"); | |
const privateKey = "3481E79956D4BD95F358AC96D151C976392FC4E3FC132F78A847906DE588C145"; | |
const tronWeb = new TronWeb(fullNode, solidityNode, eventServer, privateKey); | |
const CONTRACT = "TR7NHqjeKQxGTCi8q8ZY4pL8otSzgjLj6t"; // USDT | |
const ACCOUNT = "TEQH6py1Pi8YHNgi9cPMHCKLboBTUZrsYT"; | |
async function main() { | |
let { | |
transaction, | |
result | |
} = await tronWeb.transactionBuilder.triggerSmartContract( | |
CONTRACT, 'transfer(address,uint256)', { | |
feeLimit: 1_000_000, | |
callValue: 0 | |
}, | |
[{ | |
type: 'address', | |
value: ACCOUNT | |
}, { | |
type: 'uint256', | |
value: 1000000 | |
}] | |
); | |
if (!result.result) { | |
console.error("error:", result); | |
return; | |
} | |
console.log("transaction =>", JSON.stringify(transaction, null, 2)); | |
const signature = await tronWeb.trx.sign(transaction.raw_data_hex); | |
console.log("Signature:", signature); | |
transaction["signature"] = [signature]; | |
const broadcast = await tronWeb.trx.sendRawTransaction(transaction); | |
console.log("result:", broadcast); | |
const { message }= broadcast; | |
if (message) { | |
console.log("Error:", Buffer.from(message, 'hex').toString()); | |
} | |
} | |
main().then(() => { | |
console.log("ok"); | |
}) | |
.catch((err) => { | |
console.trace(err); | |
}); |
It's not offline. You are making a request to Tron API with your private key to sign.
I think the offline signing means you sign data with local private key instead of wallet in node.
I think the offline signing means you sign data with local private key instead of wallet in node.
:)),I think the same, Do you have any source for this? I can't find anything
I think the offline signing means you sign data with local private key instead of wallet in node.
:)),I think the same, Do you have any source for this? I can't find anything
Idk, but in code u sign offline, u only take from TronAPI transaction to create him, but sign is offline, broadcast is yeah push to TronAPI node too.
https://github.com/tronprotocol/tronweb/blob/master/src/lib/trx.js#L702-L761
const signature = await tronWeb.trx.sign(transaction.raw_data_hex);
should change to const signature = await tronWeb.trx.sign(transaction);
for the tronweb version 5.2.0
This doesn't work on tronweb 2.0.30 .
I changed
await tronWeb.trx.sign(transaction.raw_data_hex);
toawait tronWeb.trx.sign(transaction);
and
feeLimit: 1_000_000,
tofeeLimit: 1000000,
then ok .