Mix.install([:poison, :jason, {:ecto, "~> 3.11", override: true}, {:web3_aptos_ex, "~>1.4.2"}])
Aptos SDK impl in elixir!
See the using example in:
- Aptos
- RPC Implementation
- Read Resource
- Send Transaction
- Chain Interactor
- Smart Contract Parser
- Mutiple Code Generator
Test Smart Contract Lists:
- hello_blockchain: 0xcd6e69ff3c22db037584fb1650f7ca75df721fb0143690fb33f2f3bd0c1fe5bd
If available in Hex, the package can be installed
by adding web3_aptos_ex
to your list of dependencies in mix.exs
:
def deps do
[
{:web3_aptos_ex, "~> 1.4.2"}
]
end
Documentation can be generated with ExDoc and published on HexDocs. Once published, the docs can be found at https://hexdocs.pm/web3_aptos_ex.
Namespace: Web3AptosEx.Aptos
import Web3AptosEx.Aptos
alias Web3AptosEx.Aptos
{:ok, client} = Aptos.RPC.connect("https://fullnode.testnet.aptoslabs.com/v1")
client
Aptos using the Ed25519 Algorithm for the Account.
priv = Web3AptosEx.Crypto.generate_priv()
{:ok, account} = Aptos.Account.from_private_key(priv)
account
{:ok, res} = Aptos.get_faucet(client, account)
Process.sleep(5000)
{:ok, account_ol} = Aptos.load_account(client, account)
account_ol
# it will works if account is actived(has any APT)
Aptos.RPC.get_resources(client, "0x3")
Web3AptosEx.Aptos.RPC.get_resource(client, "0x3", "0x1::account::Account")
💡 You could get handle in Explorer:
Web3AptosEx.Aptos.RPC.get_table_item(
client,
"0xe30b2ff6a515aa04729522512d50147d5cdd52ee3741c26ff1b97306b0b2b148",
"0x1::string::String",
"0x65f4a0954aa6e68d2381ff98b7676df2fe57beee3ca37a4a8a57fa621c1db872::addr_info::AddrInfo",
"0x73c7448760517E3E6e416b2c130E3c6dB2026A1d"
)
{:ok, f} = ~a"0x1::coin::transfer<CoinType>(address, u64)"
payload = Aptos.call_function(f, ["0x1::aptos_coin::AptosCoin"], [account_ol.address, 100])
Aptos.submit_txn_with_auto_acct_updating(client, account_ol, payload)
Parse the smart contract code, it is the basis for generating call-codes for mutiple langugage, and the embedding for the smart contract to vector dataset!
# TODO: make it run in livebook
payload = " module hello_blockchain::message {\n use std::error;\n use std::signer;\n use std::string;\n use aptos_framework::account;\n use aptos_framework::event;\n\n //:!:>resource\n struct MessageHolder has key {\n message: string::String,\n message_change_events: event::EventHandle<MessageChangeEvent>,\n }\n //<:!:resource\n\n struct MessageChangeEvent has drop, store {\n from_message: string::String,\n to_message: string::String,\n }\n\n /// There is no message present\n const ENO_MESSAGE: u64 = 0;\n\n #[view]\n public fun get_message(addr: address): string::String acquires MessageHolder {\n assert!(exists<MessageHolder>(addr), error::not_found(ENO_MESSAGE));\n borrow_global<MessageHolder>(addr).message\n }\n\n public entry fun set_message(account: signer, message: string::String)\n acquires MessageHolder {\n let account_addr = signer::address_of(&account);\n if (!exists<MessageHolder>(account_addr)) {\n move_to(&account, MessageHolder {\n message,\n message_change_events: account::new_event_handle<MessageChangeEvent>(&account),\n })\n } else {\n let old_message_holder = borrow_global_mut<MessageHolder>(account_addr);\n let from_message = old_message_holder.message;\n event::emit_event(&mut old_message_holder.message_change_events, MessageChangeEvent {\n from_message,\n to_message: copy message,\n });\n old_message_holder.message = message;\n }\n }\n\n #[test(account = @0x1)]\n public entry fun sender_can_set_message(account: signer) acquires MessageHolder {\n let addr = signer::address_of(&account);\n aptos_framework::account::create_account_for_test(addr);\n set_message(account, string::utf8(b\"Hello, Blockchain\"));\n\n assert!(\n get_message(addr) == string::utf8(b\"Hello, Blockchain\"),\n ENO_MESSAGE\n );\n }\n }"
{:ok, tokens, _} = :smart_move_leex.string(String.to_charlist(payload))
:smart_move_yecc.parse(tokens)
Bug report or pull request are welcome.
- Fork it
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Add some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create new Pull Request
Please write unit test with your code if necessary.
web3_aptos_ex is available as open source under the terms of the MIT License.
Contributors:
pool, 20%
https://github.com/leeduckgo, 30%
https://github.com/zven21, 50%