-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
transfer examples for uniffi bindings
- Loading branch information
Showing
7 changed files
with
112 additions
and
40 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
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 @@ | ||
#include <iostream> | ||
#include "generated/zklink_sdk.hpp" | ||
|
||
using namespace std; | ||
using namespace zklink_sdk; | ||
|
||
int main() { | ||
string private_key = "0xbe725250b123a39dab5b7579334d5888987c72a58f4508062545fe6e08ca94f4"; | ||
AccountId account_id = 20; | ||
ZkLinkAddress to_address = "0xAFAFf3aD1a0425D792432D9eCD1c3e26Ef2C42E9"; | ||
SubAccountId from_sub_account_id = 1; | ||
SubAccountId to_sub_account_id = 1; | ||
TokenId token = 18; | ||
BigUint amount = "1234567899808787"; | ||
cout << "Original amount: " << amount << "\n"; | ||
amount = closest_packable_token_amount(amount); | ||
cout << "Converted amount: " << amount << "\n"; | ||
BigUint fee = "10000567777"; | ||
cout << "Original fee: " << fee << "\n"; | ||
fee = closest_packable_fee_amount(fee); | ||
cout << "Converted fee: " << fee << "\n"; | ||
Nonce nonce = 1; | ||
TimeStamp timestamp = 1693472232; | ||
string token_sybmol = "DAI"; | ||
|
||
TransferBuilder builder = { | ||
account_id, | ||
to_address, | ||
from_sub_account_id, | ||
to_sub_account_id, | ||
token, | ||
amount, | ||
fee, | ||
nonce, | ||
timestamp | ||
}; | ||
shared_ptr<Transfer> tx = Transfer::init(builder); | ||
shared_ptr<Signer> signer = Signer::init(private_key, L1SignerType::kEth{}); | ||
TxSignature signature = signer->sign_transfer(tx, token_sybmol, {}, {}); | ||
cout << signature.tx << "\n"; | ||
return 0; | ||
} |
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
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,44 @@ | ||
import zklink_sdk as sdk | ||
|
||
def main(): | ||
private_key = "0xbe725250b123a39dab5b7579334d5888987c72a58f4508062545fe6e08ca94f4" | ||
account_id = 20 | ||
to_address = "0xAFAFf3aD1a0425D792432D9eCD1c3e26Ef2C42E9" | ||
from_sub_account_id = 1 | ||
to_sub_account_id = 1 | ||
token = 18 | ||
amount = "1234567899808787" | ||
print("Original amount: " + amount) | ||
assert not sdk.is_token_amount_packable(amount) | ||
amount = sdk.closest_packable_token_amount(amount) | ||
assert sdk.is_token_amount_packable(amount) | ||
print("Converted amount: " + amount) | ||
fee = "10000567777" | ||
print("Original fee: " + fee) | ||
assert not sdk.is_fee_amount_packable(fee) | ||
fee = sdk.closest_packable_fee_amount(fee) | ||
assert sdk.is_fee_amount_packable(fee) | ||
print("Converted fee: " + fee) | ||
nonce = 1 | ||
timestamp = 1693472232 | ||
token_sybmol = "DAI" | ||
|
||
builder = sdk.TransferBuilder( | ||
account_id, | ||
to_address, | ||
from_sub_account_id, | ||
to_sub_account_id, | ||
token, | ||
amount, | ||
fee, | ||
nonce, | ||
timestamp | ||
) | ||
tx = sdk.Transfer(builder) | ||
signer = sdk.Signer(private_key, sdk.L1SignerType.ETH()) | ||
|
||
tx_signature = signer.sign_transfer(tx, "USDT", None, None) | ||
print(tx_signature) | ||
|
||
if __name__ == "__main__": | ||
main() |