Comments (2)
I use web3dart and tron package to call the methods of the contract
For example, to call the transfer method
//class from web3dart you need contract abi and address
final DeployedContract _contract =
DeployedContract(abi, contractAddress);
// contractAddress is EthereumAddress, You have to rewrite EthereumAddress class to support Tron network address as well
// Only this part changes to call other methods
final _encodeParameters = _contract
.function('transfer')
.encodeCall([receiver!, _currentTransactionValue]);
final block =
await _getNowBlock(); // get now block from Tron protocol wallet/getnowblock
// class from Tron package
tron.TriggerSmartContract _value = tron.TriggerSmartContract(
data: _encodeParameters,
ownerAddress: hexToBytes(account.account.ethereumAddress.hex),
contractAddress: hexToBytes(token!.ethAddress.hex));
// class from Tron package
any.Any parameter = any.Any(
typeUrl: "type.googleapis.com/protocol.TriggerSmartContract",
value: _value.writeToBuffer());
// class from Tron package
tron.Transaction_Contract _transactionContract = tron.Transaction_Contract(
parameter: parameter,
type: tron.Transaction_Contract_ContractType.TriggerSmartContract,
);
// class from Tron package
tron.Transaction_raw rawData = tron.Transaction_raw(
contract: [_transactionContract],
expiration: fixnum.Int64(DateTime.now()
.toUtc()
.add(const Duration(hours: 1))
.millisecondsSinceEpoch),
timestamp: fixnum.Int64(
(DateTime.now().toUtc().millisecondsSinceEpoch / 1000).round()),
refBlockBytes: hexToBytes(block["raw_data"]["ref_block_bytes"]),
refBlockHash: hexToBytes(block["raw_data"]["ref_block_hash"]),
feeLimit: fixnum.Int64(10000000));
// class from web3dart package
Credentials credentials = account.account.accountCredentials;
final trSignature = await credentials.signTron(rawData
.writeToBuffer()); // I override Credentials class on web3dart to sign tron
// class from tron package
tron.Transaction _tr = tron.Transaction(
rawData: rawData,
signature: [hexToBytes(trSignature)]);
final String signedTransacation = bytesToHex(_tr.writeToBuffer());
final _send = {
"transaction": signedTransacation,
};
final txId = await httpClient.normalPost(
tronApi.buildApi("wallet/broadcasthex"),
data: _send); // send transaction to network
print("transaction id: ${txId["txId"]}");
If you want to call pure or View methods, you can use the following API and create a parameter like the one above.
for example:
call() async{
final DeployedContract _contract =
DeployedContract(abi, contractAddress);
final _encodeParameters =
_contract.function('balanceOf').encodeCallWitoutSelector([address]);
final Map<String, dynamic> _data = {
"owner_address": "410000000000000000000000000000000000000000",
"contract_address": "41a614f803b6fd780986a42c78ec9c7f77e6ded13c",
"function_selector": "balanceOf(address)",
"parameter": bytesToHex(_encodeParameters)
};
final data = await httpClient.normalPost(tronApi.buildApi("wallet/triggerconstantcontract"),data: _data);
}
For such calls, you can only use the Web3Dart package and do it with JSON RPC.
from dart_tron.
Sorry for my late answer. I assume this issue is fixed by now and closing this one. Please feel free to open a new issue any time.
from dart_tron.
Related Issues (7)
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from dart_tron.