-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Update dependencies. - Added Sui Network support. - Added Aptos Network support.
- Loading branch information
1 parent
d0393f6
commit 089a568
Showing
221 changed files
with
22,628 additions
and
782 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import 'package:on_chain/on_chain.dart'; | ||
import 'provider_example.dart'; | ||
|
||
final AptosProvider aptosProvider = | ||
AptosProvider(AptosHttpService("https://api.testnet.aptoslabs.com/")); | ||
Future<AptosApiAccountData> getAccountInfo(AptosAddress address) async { | ||
final r = | ||
await aptosProvider.request(AptosRequestGetAccount(address: address)); | ||
return r; | ||
} | ||
|
||
Future<BigInt> getAccountSequence(AptosAddress address) async { | ||
final r = | ||
await aptosProvider.request(AptosRequestGetAccount(address: address)); | ||
return r.sequenceNumber; | ||
} | ||
|
||
Future<String> simulate(AptosSignedTransaction transaction) async { | ||
final r = await aptosProvider.request(AptosRequestSubmitTransaction( | ||
signedTransactionData: transaction.toBcs())); | ||
return r.hash; | ||
} | ||
|
||
Future<int> getChainId() async { | ||
final r = await aptosProvider.request(AptosRequestGetLedgerInfo()); | ||
return r.chainId; | ||
} | ||
|
||
Future<BigInt> gasEstimate() async { | ||
final r = await aptosProvider.request(AptosRequestEstimateGasPrice()); | ||
return BigInt.from(r.gasEstimate); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import 'package:on_chain/on_chain.dart'; | ||
import 'api_methods.dart'; | ||
|
||
void main() async { | ||
AptosEd25519Account getAccount() { | ||
return AptosEd25519Account( | ||
AptosED25519PrivateKey.fromBytes(List<int>.filled(32, 12))); | ||
} | ||
|
||
final recipient1 = AptosAddress( | ||
"0x89dd43dcedf165f975202fae5f8aecf03013ebc14bb3c09a1431313b4ee52b02"); | ||
final recipient2 = AptosAddress( | ||
"0xf9761c71494a2c4e3f989302f68ed03f83cd521dc1c22441fcc1aee4b324723d"); | ||
final account = getAccount(); | ||
final transactionPayload = AptosTransactionPayloadEntryFunction( | ||
entryFunction: AptosTransactionEntryFunction( | ||
moduleId: | ||
AptosModuleId(address: AptosAddress.one, name: "aptos_account"), | ||
functionName: 'batch_transfer', | ||
typeArgs: [], | ||
args: [ | ||
MoveVector<AptosAddress>([recipient1, recipient2]), | ||
MoveVector<MoveU64>([MoveU64.aptos("0.0001"), MoveU64.aptos("0.0002")]) | ||
])); | ||
final gasUnitPrice = await gasEstimate(); | ||
final sequenceNumber = await getAccountSequence(account.toAddress()); | ||
final chainId = await getChainId(); | ||
final expire = | ||
DateTime.now().add(const Duration(minutes: 5)).millisecondsSinceEpoch ~/ | ||
1000; | ||
final transaction = AptosRawTransaction( | ||
sender: account.toAddress(), | ||
sequenceNumber: sequenceNumber, | ||
transactionPayload: transactionPayload, | ||
maxGasAmount: BigInt.from(200000), | ||
gasUnitPrice: gasUnitPrice, | ||
expirationTimestampSecs: BigInt.from(expire), | ||
chainId: chainId); | ||
final authenticator = account.signWithAuth(transaction.signingSerialize()); | ||
final signedTx = AptosSignedTransaction( | ||
rawTransaction: transaction, | ||
authenticator: AptosTransactionAuthenticatorEd25519( | ||
publicKey: authenticator.publicKey, | ||
signature: authenticator.signature)); | ||
await simulate(signedTx); | ||
|
||
/// https://explorer.aptoslabs.com/txn/0x392868c085edc7ee6e260996e235190d320d38b28eaa8a28e23a52f1362d66d5?network=testnet | ||
} |
41 changes: 41 additions & 0 deletions
41
example/lib/example/aptos/create_object_using_script_transaction_example.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import 'package:blockchain_utils/utils/binary/utils.dart'; | ||
import 'package:on_chain/on_chain.dart'; | ||
import 'api_methods.dart'; | ||
|
||
void main() async { | ||
AptosSingleKeyAccount getAccount() { | ||
final account = | ||
AptosSecp256k1PrivateKey.fromBytes(List<int>.filled(32, 25)); | ||
return AptosSingleKeyAccount(account); | ||
} | ||
|
||
final sender = getAccount(); | ||
const script = | ||
"0xa11ceb0b060000000601000402040403080a051209071b3608512000000001000302000102000200000402030001060c000105010800066f626a656374067369676e65720a616464726573735f6f660e436f6e7374727563746f725265660d6372656174655f6f626a6563740000000000000000000000000000000000000000000000000000000000000001000001050b00110011010102"; | ||
final transactionPayload = AptosTransactionPayloadScript( | ||
script: AptosScript( | ||
byteCode: BytesUtils.fromHexString(script), | ||
typeArgs: [], | ||
arguments: [])); | ||
final gasUnitPrice = await gasEstimate(); | ||
final sequenceNumber = await getAccountSequence(sender.publicKey.toAddress()); | ||
final chainId = await getChainId(); | ||
final expire = | ||
DateTime.now().add(const Duration(minutes: 5)).millisecondsSinceEpoch ~/ | ||
1000; | ||
final transaction = AptosRawTransaction( | ||
sender: sender.publicKey.toAddress(), | ||
sequenceNumber: sequenceNumber, | ||
transactionPayload: transactionPayload, | ||
maxGasAmount: BigInt.from(200000), | ||
gasUnitPrice: gasUnitPrice, | ||
expirationTimestampSecs: BigInt.from(expire), | ||
chainId: chainId); | ||
final authenticator = sender.signWithAuth(transaction.signingSerialize()); | ||
final signedTx = AptosSignedTransaction( | ||
rawTransaction: transaction, | ||
authenticator: AptosTransactionAuthenticatorSignleSender(authenticator)); | ||
await simulate(signedTx); | ||
|
||
/// https://explorer.aptoslabs.com/txn/0x9fc9c8bc59b7897a549ac39562393924cf1da916c1f91ade52261c9239dcca3a/changes?network=testnet | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
// ignore_for_file: unused_local_variable | ||
|
||
import 'package:blockchain_utils/blockchain_utils.dart'; | ||
import 'package:on_chain/on_chain.dart'; | ||
|
||
void main() { | ||
const passphrase = "MRTNETWORK"; | ||
final mnemonic = | ||
Bip39MnemonicGenerator().fromWordsNumber(Bip39WordsNum.wordsNum24); | ||
final seed = Bip39SeedGenerator(mnemonic).generate(passphrase); | ||
final wallet = Bip44.fromSeed(seed, Bip44Coins.aptos); | ||
final defaultPath = wallet.deriveDefaultPath; | ||
final address = AptosAddress(defaultPath.publicKey.toAddress); | ||
final account = AptosEd25519Account( | ||
AptosED25519PrivateKey.fromBytes(defaultPath.privateKey.raw)); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import 'package:on_chain/on_chain.dart'; | ||
import 'api_methods.dart'; | ||
|
||
void main() async { | ||
/// the token created in `publish_ft_token_module_example` example | ||
AptosEd25519Account getAccount() { | ||
final account = AptosED25519PrivateKey.fromBytes(List<int>.filled(32, 36)); | ||
return AptosEd25519Account(account); | ||
} | ||
|
||
final account = getAccount(); | ||
|
||
final transactionPayload = AptosTransactionPayloadEntryFunction( | ||
entryFunction: AptosTransactionEntryFunction( | ||
moduleId: AptosModuleId(address: account.toAddress(), name: "dog"), | ||
functionName: 'mint', | ||
args: [account.toAddress(), MoveU64(BigInt.from(100000))])); | ||
final gasUnitPrice = await gasEstimate(); | ||
final sequenceNumber = await getAccountSequence(account.toAddress()); | ||
final chainId = await getChainId(); | ||
final expire = | ||
DateTime.now().add(const Duration(minutes: 5)).millisecondsSinceEpoch ~/ | ||
1000; | ||
final transaction = AptosRawTransaction( | ||
sender: account.toAddress(), | ||
sequenceNumber: sequenceNumber, | ||
transactionPayload: transactionPayload, | ||
maxGasAmount: BigInt.from(200000), | ||
gasUnitPrice: gasUnitPrice, | ||
expirationTimestampSecs: BigInt.from(expire), | ||
chainId: chainId); | ||
final serializeSign = transaction.signingSerialize(); | ||
final authenticator = account.signWithAuth(serializeSign); | ||
final signedTx = AptosSignedTransaction( | ||
rawTransaction: transaction, | ||
authenticator: AptosTransactionAuthenticatorEd25519( | ||
publicKey: authenticator.publicKey, | ||
signature: authenticator.signature)); | ||
await simulate(signedTx); | ||
|
||
/// https://explorer.aptoslabs.com/txn/0xf2e42c3bdff11f28c0e21884c9378cb20ac947880ca447d073c27b8cbc6a5a1b?network=testnet | ||
} |
61 changes: 61 additions & 0 deletions
61
example/lib/example/aptos/multi_agent_transfer_object_using_script_example.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
import 'package:blockchain_utils/utils/binary/utils.dart'; | ||
import 'package:on_chain/on_chain.dart'; | ||
import 'api_methods.dart'; | ||
|
||
void main() async { | ||
AptosSingleKeyAccount getRecipient() { | ||
final account = AptosED25519PrivateKey.fromBytes(List<int>.filled(32, 26)); | ||
return AptosSingleKeyAccount(account); | ||
} | ||
|
||
AptosSingleKeyAccount getAccount() { | ||
final account = | ||
AptosSecp256k1PrivateKey.fromBytes(List<int>.filled(32, 25)); | ||
return AptosSingleKeyAccount(account); | ||
} | ||
|
||
final sender = getAccount(); | ||
final recipient = getRecipient(); | ||
const String script = | ||
"0xa11ceb0b060000000701000602060a031017042706052d2d075a4b08a5012000000001000201030701000101040800020503040000060602010001070408010801060902010801050207030704060c060c0503010b000108010001060c010501090003060c0503010801010b0001090003060c0b000109000504636f696e066f626a656374067369676e6572064f626a6563740a4f626a656374436f72650a616464726573735f6f66087472616e7366657211616464726573735f746f5f6f626a6563740000000000000000000000000000000000000000000000000000000000000001010000010e0a010a0011000b0338000b0238010c040b000b040b011100380202"; | ||
final AptosAddress objectAddress = AptosAddress( | ||
"0x25bee59257280e4361b733d2cf9f320a1a8e2e5a6e760a79875f9dfcab05a0b0"); | ||
final transactionPayload = AptosTransactionPayloadScript( | ||
script: | ||
AptosScript(byteCode: BytesUtils.fromHexString(script), typeArgs: [ | ||
AptosTypeTagStruct(AptosStructTag( | ||
address: AptosAddress("0x1"), | ||
moduleName: 'aptos_coin', | ||
name: 'AptosCoin')) | ||
], arguments: [ | ||
objectAddress, | ||
MoveU64(BigInt.from(100)) | ||
])); | ||
final gasUnitPrice = await gasEstimate(); | ||
final sequenceNumber = await getAccountSequence(sender.publicKey.toAddress()); | ||
final chainId = await getChainId(); | ||
final expire = | ||
DateTime.now().add(const Duration(minutes: 5)).millisecondsSinceEpoch ~/ | ||
1000; | ||
final transaction = AptosRawTransaction( | ||
sender: sender.publicKey.toAddress(), | ||
sequenceNumber: sequenceNumber, | ||
transactionPayload: transactionPayload, | ||
maxGasAmount: BigInt.from(200000), | ||
gasUnitPrice: gasUnitPrice, | ||
expirationTimestampSecs: BigInt.from(expire), | ||
chainId: chainId); | ||
final digest = transaction.signingSerialize( | ||
secondarySignerAddresses: [recipient.publicKey.toAddress()]); | ||
final authenticator = sender.signWithAuth(digest); | ||
final recipientAuthenticator = recipient.signWithAuth(digest); | ||
final txauthenticator = AptosTransactionAuthenticatorMultiAgent( | ||
sender: authenticator, | ||
secondarySigner: [recipientAuthenticator], | ||
secondarySignerAddressess: [recipient.publicKey.toAddress()]); | ||
final signedTx = AptosSignedTransaction( | ||
rawTransaction: transaction, authenticator: txauthenticator); | ||
await simulate(signedTx); | ||
|
||
/// https://explorer.aptoslabs.com/txn/0xd23a797626830900976b198fcbce513ddd439ac9b3e8240630fdaee3a0feb42b?network=testnet | ||
} |
21 changes: 21 additions & 0 deletions
21
example/lib/example/aptos/parsing_dynamic_argument_example.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import 'package:on_chain/on_chain.dart'; | ||
import 'api_methods.dart'; | ||
|
||
void main() async { | ||
final module = await aptosProvider.request(AptosRequestGetAccountModule( | ||
address: AptosAddress("0x1"), moduleName: "aptos_governance")); | ||
final function = module.abi.findViewFunction("get_remaining_voting_power"); | ||
final arguments = AptosFunctionEntryArgumentUtils.parseArguments( | ||
function: function, | ||
values: [ | ||
"0xba08cec00a8cfa1deff6c9212dda8d198c8fa6ee1992f3ada76d645f99e3402b", | ||
0 | ||
]); | ||
await aptosProvider.request(AptosRequestExecuteViewFunctionOfaModule.bcs( | ||
entry: AptosTransactionEntryFunction( | ||
moduleId: AptosModuleId( | ||
address: AptosAddress("0x1"), | ||
name: "aptos_governance"), // Governance module | ||
functionName: "get_remaining_voting_power", // Function to execute | ||
args: arguments))); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
import 'package:http/http.dart'; | ||
import 'package:on_chain/on_chain.dart'; | ||
|
||
class AptosHttpService implements AptosServiceProvider { | ||
AptosHttpService(this.url, | ||
{Client? client, this.defaultTimeOut = const Duration(seconds: 30)}) | ||
: client = client ?? Client(); | ||
|
||
final String url; | ||
final Client client; | ||
final Duration defaultTimeOut; | ||
@override | ||
Future<AptosServiceResponse<T>> doRequest<T>(AptosRequestDetails params, | ||
{Duration? timeout}) async { | ||
final url = params.toUri(this.url); | ||
final defaultTimeOut = timeout ?? this.defaultTimeOut; | ||
if (params.type.isPostRequest) { | ||
final response = await client | ||
.post(url, headers: params.headers, body: params.body()) | ||
.timeout(defaultTimeOut); | ||
return params.parseResponse(response.bodyBytes, response.statusCode); | ||
} | ||
final response = | ||
await client.get(url, headers: params.headers).timeout(defaultTimeOut); | ||
return params.parseResponse(response.bodyBytes, response.statusCode); | ||
} | ||
} | ||
|
||
void main() async { | ||
/// Provider examples | ||
/// Initialize the AptosProvider with the Testnet HTTP service endpoint | ||
final AptosProvider provider = | ||
AptosProvider(AptosHttpService("https://api.testnet.aptoslabs.com/")); | ||
|
||
/// Define an Aptos address to interact with | ||
final address = AptosAddress( | ||
"0x89dd43dcedf165f975202fae5f8aecf03013ebc14bb3c09a1431313b4ee52b02"); | ||
|
||
/// Request account details for the specified address | ||
await provider.request(AptosRequestGetAccount(address: address)); | ||
|
||
/// Fetch the transaction history for the specified address | ||
await provider.request(AptosRequestGetAccountTransactions(address: address)); | ||
|
||
/// Retrieve all recent transactions from the Aptos network | ||
await provider.request(AptosRequestGetTransactions()); | ||
|
||
/// Execute a view function from the 'aptos_governance' module to get remaining voting power | ||
await provider.request(AptosRequestExecuteViewFunctionOfaModule.bcs( | ||
entry: AptosTransactionEntryFunction( | ||
moduleId: AptosModuleId( | ||
address: AptosAddress("0x1"), | ||
name: "aptos_governance"), // Governance module | ||
functionName: "get_remaining_voting_power", // Function to execute | ||
args: [ | ||
// Address to check voting power for | ||
AptosAddress( | ||
"0xba08cec00a8cfa1deff6c9212dda8d198c8fa6ee1992f3ada76d645f99e3402b"), | ||
MoveU64(BigInt.one) // Argument representing the proposal ID or context | ||
]))); | ||
|
||
final dynamicResult = | ||
await provider.requestDynamic(AptosRequestGetAccount(address: address)); | ||
// ignore: unused_local_variable | ||
final authentication = dynamicResult["authentication_key"]; | ||
|
||
/// ... | ||
} |
Oops, something went wrong.