GithubHelp home page GithubHelp logo

diem / my-first-client Goto Github PK

View Code? Open in Web Editor NEW
9.0 18.0 9.0 137 KB

A tutorial to demonstrate how to build a client on the Libra testnet.

License: Apache License 2.0

Makefile 3.59% Shell 9.03% Java 49.71% Python 37.67%

my-first-client's Introduction

My First Client Tutorial sample code

This repo includes example code for the My First Client tutorial.

Setup

git clone https://github.com/diem/my-first-client.git

Install language dependencies.

Requirements for each SDK:

  • Python: Python v 3.7.*, pipenv
  • Java: Java 8+, gradle v5

Run examples

make java		# for Java
make python		# for Python

my-first-client's People

Contributors

capcap avatar ericnakagawa avatar jnaulty avatar xli avatar yanivmo avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

my-first-client's Issues

it error when run [ testnet.Faucet.mint(faucet, sender_auth_key.hex(), 100000000, "Coin1")]

when i was run this scrip it:

`import time

from cryptography.hazmat.primitives.asymmetric.ed25519 import Ed25519PrivateKey
from libra import stdlib, utils, libra_types, testnet, AuthKey
from libra.testnet import CHAIN_ID

CURRENCY = "Coin1"

"""
submit_peer_to_peer_transaction_example demonstrates currencies transfer between 2 accounts on the Libra blockchain
"""

def main():
# connect to testnet
client = testnet.create_client()

# generate private key for sender account
sender_private_key = Ed25519PrivateKey.generate()
# generate auth key for sender account
sender_auth_key = AuthKey.from_public_key(sender_private_key.public_key())
print(f"Generated sender address: {utils.account_address_hex(sender_auth_key.account_address())}")
# create sender account
faucet = testnet.Faucet(client)
**testnet.Faucet.mint(faucet, sender_auth_key.hex(), 100000000, "Coin1")**

# get sender account
sender_account = client.get_account(sender_auth_key.account_address())

# generate private key for receiver account
receiver_private_key = Ed25519PrivateKey.generate()
# generate auth key for receiver account
receiver_auth_key = AuthKey.from_public_key(receiver_private_key.public_key())
print(f"Generated receiver address: {utils.account_address_hex(receiver_auth_key.account_address())}")

# create receiver account
faucet = testnet.Faucet(client)
testnet.Faucet.mint(faucet, receiver_auth_key.hex(), 10000000, CURRENCY)

# create script
script = stdlib.encode_peer_to_peer_with_metadata_script(
    currency=utils.currency_code(CURRENCY),
    payee=receiver_auth_key.account_address(),
    amount=10000000,
    metadata=b'',  # no requirement for metadata and metadata signature
    metadata_signature=b'',
)
# create transaction
raw_transaction = libra_types.RawTransaction(
    sender=sender_auth_key.account_address(),
    sequence_number=sender_account.sequence_number,
    payload=libra_types.TransactionPayload__Script(script),
    max_gas_amount=1_000_000,
    gas_unit_price=0,
    gas_currency_code=CURRENCY,
    expiration_timestamp_secs=int(time.time()) + 30,
    chain_id=CHAIN_ID,
)
# sign transaction
signature = sender_private_key.sign(utils.raw_transaction_signing_msg(raw_transaction))
public_key_bytes = utils.public_key_bytes(sender_private_key.public_key())

signed_txn = utils.create_signed_transaction(raw_transaction, public_key_bytes, signature)
# submit transaction
client.submit(signed_txn)
# wait for transaction
client.wait_for_transaction(signed_txn)

if name == "main":
main()
`

it error
Traceback (most recent call last):
File "D:/work/libra-python-test/main.py", line 71, in
main()
File "D:/work/libra-python-test/main.py", line 25, in main
testnet.Faucet.mint(faucet, sender_auth_key.hex(), 100000000, "Coin1")
File "C:\Python38\lib\site-packages\libra\testnet.py", line 66, in mint
self._retry.execute(lambda: self._mint_without_retry(authkey, amount, currency_code))
File "C:\Python38\lib\site-packages\libra\jsonrpc\client.py", line 86, in execute
raise e
File "C:\Python38\lib\site-packages\libra\jsonrpc\client.py", line 80, in execute
return fn()
File "C:\Python38\lib\site-packages\libra\testnet.py", line 66, in
self._retry.execute(lambda: self._mint_without_retry(authkey, amount, currency_code))
File "C:\Python38\lib\site-packages\libra\testnet.py", line 85, in _mint_without_retry
self._client.wait_for_transaction(txn)
File "C:\Python38\lib\site-packages\libra\jsonrpc\client.py", line 425, in wait_for_transaction
return self.wait_for_transaction2(
File "C:\Python38\lib\site-packages\libra\jsonrpc\client.py", line 460, in wait_for_transaction2
txn = self.get_account_transaction(address, seq, True)
File "C:\Python38\lib\site-packages\libra\jsonrpc\client.py", line 320, in get_account_transaction
return self.execute("get_account_transaction", params, _parse_obj(lambda: rpc.Transaction()))
File "C:\Python38\lib\site-packages\libra\jsonrpc\client.py", line 491, in execute
return self._retry.execute(
File "C:\Python38\lib\site-packages\libra\jsonrpc\client.py", line 80, in execute
return fn()
File "C:\Python38\lib\site-packages\libra\jsonrpc\client.py", line 492, in
lambda: self.execute_without_retry(method, params, result_parser, ignore_stale_response)
File "C:\Python38\lib\site-packages\libra\jsonrpc\client.py", line 523, in execute_without_retry
json = self._rs.send_request(self, request, ignore_stale_response or False)
File "C:\Python38\lib\site-packages\libra\jsonrpc\client.py", line 98, in send_request
return client._send_http_request(client._url, request, ignore_stale_response)
File "C:\Python38\lib\site-packages\libra\jsonrpc\client.py", line 554, in _send_http_request
self.update_last_known_state(
File "C:\Python38\lib\site-packages\libra\jsonrpc\client.py", line 262, in update_last_known_state
if curr.version > version:
TypeError: '>' not supported between instances of 'int' and 'NoneType'

Process finished with exit code 1

image

it ok last monday!

Makefile

Create a Makefile for compiled languages to allow running examples quickly.

chainID mismatch when building

Note: this was captured on 2/13/2021

  1. try to gradle build 'my-first-client' per the documentation
    ==> see in the attached screenshot 'chainID mismatch exception'

I'm assuming a step from the stack trace that a step
chainIDmismatch
is missing from the documentation

OS: Macos 11
tried with both jdk 8 as well as 11

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.