def init_account(): private_key = b58decode(bytes(KEY, 'utf8')) kp = KeyPair(Ed25519, private_key) testid_account = Account(TESTID) testid_account.add_key_pair(kp, 'active') testid_account.add_key_pair(kp, 'owner') iost.publisher = testid_account
def new_account(self, new_name: str, creator_name: str, initial_ram: int = 0, initial_gas_pledge: float = 11.0, initial_coins: float = 0.0, algo_cls: Type[Algorithm] = Ed25519) -> Account: """Helper function that combines `KeyPair` and `Account` creation then calls to `create_new_account_tx` and `send_and_wait_tx`. Creates an `Account` with new ``owner`` and ``active`` `KeyPair`, then creates a `Transaction` that contains a list of `Actions` to create an account, pledge tokens, buy RAM and transfer coins to the new account, and finally sends it. Args: new_name: The name of the account to create. creator_name: The name of the account that will pledge tokens to the new account. initial_ram: The amount of RAM to buy for the new account. initial_gas_pledge: The amount of tokens to pledge for the new account. initial_coins: The amount of coins to transfer to the new account. algo_cls: The class type of the `Algorithm` to use to generate the `KeyPair`. Returns: A `Account` object. Raises: TransactionError: If Transaction.Status is unknown or if TxReceipt.StatusCode is not SUCCESS. TimeoutError: If TxReceipt.StatusCode is TIMEOUT or no transaction can be found after `wait_time` x `wait_max_retry` have passed. """ account = Account(new_name) kp = KeyPair(algo_cls) account.add_key_pair(kp, 'owner') account.add_key_pair(kp, 'active') tx = self.create_new_account_tx( new_name, creator_name, b58encode(account.get_key_pair('owner').pubkey), b58encode(account.get_key_pair('active').pubkey), initial_ram, initial_gas_pledge, initial_coins) self.send_and_wait_tx(tx) return account
import time from pyost.iost import IOST from pyost.account import Account from pyost.algorithm import Ed25519 from pyost.signature import KeyPair from base58 import b58decode if __name__ == '__main__': iost = IOST('localhost:30002') admin_seckey = b58decode( b'1rANSfcRzr4HkhbUFZ7L1Zp69JZZHiDDq5v7dNSbbEqeU4jxy3fszV4HGiaLQEyqVpS1dKT9g7zCVRxBVzuiUzB' ) admin_kp = KeyPair(Ed25519, admin_seckey) admin = Account('producer00001') admin.add_key_pair(admin_kp, 'active') admin.add_key_pair(admin_kp, 'owner') account_seckey = b58decode( b'4vZ8qw2MaGLVXsbW7TcyTDcEqrefAS34vuM1eJf7YrBL9Fpnq3LgRyDjnUfv7kjvPfsA5tQGnou3Bv2bYNXyorK1' ) account_kp = KeyPair(Ed25519, account_seckey) account = Account('testacc1') account.add_key_pair(account_kp, 'active') account.add_key_pair(account_kp, 'owner') # Create token token_sym = 't' + str(int(time.time() * 1000000))[-4:] tx = iost.create_call_tx('token.iost', 'create', token_sym, admin.name, 21000000, { "fullName": "bit coin",
from pyost.transaction import TransactionError from base58 import b58decode def print_balance(account_name: str): account = iost.get_account_info(account_name) print( f'{account.name}: balance={account.balance} gas={account.gas_info.current_total} ram={account.ram_info.available}') if __name__ == '__main__': iost = IOST('localhost:30002') admin_seckey = b58decode(b'1rANSfcRzr4HkhbUFZ7L1Zp69JZZHiDDq5v7dNSbbEqeU4jxy3fszV4HGiaLQEyqVpS1dKT9g7zCVRxBVzuiUzB') admin_kp = KeyPair(Ed25519, admin_seckey) admin = Account('admin') admin.add_key_pair(admin_kp, 'active') admin.add_key_pair(admin_kp, 'owner') acc1 = admin print_balance(acc1.name) acc2_seckey = b58decode(b'4vZ8qw2MaGLVXsbW7TcyTDcEqrefAS34vuM1eJf7YrBL9Fpnq3LgRyDjnUfv7kjvPfsA5tQGnou3Bv2bYNXyorK1') acc2_kp = KeyPair(Ed25519, acc2_seckey) acc2 = Account('producer01') acc2.add_key_pair(acc2_kp, 'active') acc2.add_key_pair(acc2_kp, 'owner') print_balance(acc2.name) tx = iost.create_transfer_tx('iost', acc1.name, acc2.name, 10000) # Those 2 lines are not necessary for transfer, this is just for illustrating multi-sig
from base58 import b58decode from pyost.iost import IOST from pyost.account import Account from pyost.algorithm import Secp256k1, Ed25519 from pyost.signature import KeyPair from pyost.transaction import TransactionError if __name__ == '__main__': iost = IOST('localhost:30002') acc_seckey = b58decode( b'1rANSfcRzr4HkhbUFZ7L1Zp69JZZHiDDq5v7dNSbbEqeU4jxy3fszV4HGiaLQEyqVpS1dKT9g7zCVRxBVzuiUzB' ) acc_kp = KeyPair(Ed25519, acc_seckey) acc = Account('admin') acc.add_key_pair(acc_kp, 'active') acc.add_key_pair(acc_kp, 'owner') print('Account Info:') print(iost.get_account_info(acc.name)) print('\nToken Balance:') print(iost.get_token_balance(acc.name)) print('\nToken 721 Balance:') print(iost.get_token721_balance(acc.name, 'iost')) tx = iost.create_call_tx('token.iost', 'supply', 'iost') acc.sign_publish(tx) try: receipt = iost.send_and_wait_tx(tx)
import time import json from pyost.iost import IOST from pyost.account import Account from pyost.algorithm import Ed25519 from pyost.signature import KeyPair from base58 import b58decode if __name__ == '__main__': iost = IOST('localhost:30002') admin_seckey = b58decode( b'1rANSfcRzr4HkhbUFZ7L1Zp69JZZHiDDq5v7dNSbbEqeU4jxy3fszV4HGiaLQEyqVpS1dKT9g7zCVRxBVzuiUzB' ) admin_kp = KeyPair(Ed25519, admin_seckey) admin = Account('producer00001') admin.add_key_pair(admin_kp, 'active') admin.add_key_pair(admin_kp, 'owner') iost.publisher = admin iost.gas_limit = 1000000 hw_contract = '{"ID":"hw","info":{"lang":"javascript","version":"1.0.0","abi":[{"name":"hello"}, {"name":"can_update", "args": ["string"]}]},"code":"class Contract {init(){} hello(){return \\"world\\";} can_update(data){return true;}} module.exports = Contract;"}' print('setting code...') txr = iost.call('system.iost', 'setCode', hw_contract) contract_id = json.loads(txr.returns[0])[0] print(f'Contract ID: {contract_id}') print('sending hello...') txr = iost.call(contract_id, 'hello')
from base58 import b58decode from pyost.iost import IOST from pyost.account import Account from pyost.algorithm import Ed25519 from pyost.signature import KeyPair if __name__ == '__main__': iost = IOST('localhost:30002') account_seckey = b58decode( b'4vZ8qw2MaGLVXsbW7TcyTDcEqrefAS34vuM1eJf7YrBL9Fpnq3LgRyDjnUfv7kjvPfsA5tQGnou3Bv2bYNXyorK1') account_kp = KeyPair(Ed25519, account_seckey) account = Account('testacc1') account.add_key_pair(account_kp, 'active') account.add_key_pair(account_kp, 'owner') print(f'Account RAM: {iost.get_account_info(account.name).ram_info.available}') print(f'RAM price: {iost.get_ram_info().buy_price}') tx = iost.create_call_tx('ram.iost', 'buy', account.name, account.name, 50000) tx.gas_limit = 1000000 account.sign_publish(tx) print('Waiting for transaction to be processed...') try: receipt = iost.send_and_wait_tx(tx) print(receipt) except TimeoutError as e: print(f'ERROR: {e}') except RuntimeError as e: print(f'ERROR: {e}')