2017-10-14 87 views
2

我一直在努力嘗試在2個以太坊錢包之間轉移自定義令牌。如何使用geth在錢包之間轉移令牌

我正在使用Populus(python)和它似乎很容易做一個ETH轉移,但我不明白如何做自定義令牌相同。

這是我的python代碼:

from decimal import Decimal 
import populus 
from populus.utils.accounts import is_account_locked 
from populus.utils.cli import request_account_unlock 
from eth_utils import from_wei 
from ico.utils import check_succesful_tx 

# Which network we deployed our contract 
chain_name = "horton" 

# Owner account on geth 
owner_address = "0xaeCb8415d5553F080d351e82b2000f123BFBc23C" 

# Where did we deploy our token 
contract_address = "0x15f173b7aca7cd4a01d5f8360e65fb4491d270c1" 

receiver = "0x4c042bf285689891117AED16005004a6de2cC4FB" 

amount = Decimal("1.0") 

project = populus.Project() 

with project.get_chain(chain_name) as chain: 

    web3 = chain.web3 
    print("Web3 provider is", web3.currentProvider) 
    print("Owner address is", owner_address) 
    print("Owner balance is", from_wei(web3.eth.getBalance(owner_address), "ether"), "ETH") 

    # Goes through geth account unlock process if needed 
    if is_account_locked(web3, owner_address): 
     request_account_unlock(chain, owner_address, None) 

    transaction = {"from": owner_address} 
    FractionalERC20 = chain.contract_factories.FractionalERC20 

    token = FractionalERC20(address=contract_address) 
    decimals = token.call().decimals() 
    decimal_multiplier = 10 ** decimals 

    decimals = 18 
    decimal_multiplier = 10 ** decimals 
    print("Token has", decimals, "decimals") 
    print("Owner token balance is", token.call().balanceOf(owner_address)/decimal_multiplier) 

    # Use lowest denominator amount 
    normalized_amount = int(amount * decimal_multiplier) 

    # Transfer the tokens 
    txid = token.transact({"from": owner_address}).transfer(receiver, normalized_amount) 
    print("TXID is", txid) 
    check_succesful_tx(web3, txid) 

但在執行上面的代碼中,我得到一個錯誤:

File "ICO_transfering_tokens.py", line 39, in <module> 
    FractionalERC20 = chain.contract_factories.FractionalERC20 
AttributeError: 'LocalGethChain' object has no attribute 'contract_factories' 

我理解錯誤但不知道如何解決它。


如果有人在其他語言比python一個解決方案,我會很樂意接受它作爲正確答案。我需要將小額付款發送到錢包清單,而且我的日程安排緊張,歡迎任何幫助!

+0

嘗試下載胡楊林的新版本,並設置一個本地霍頓鏈的新途徑HTTP://populus.readthedocs .io/en/latest/tutorial.part-2.html –

回答

2

顯然你已經從ICO project複製了這段代碼。爲了讓用戶更容易回答,請告訴您從哪裏獲得源代碼。 This project has its own chat group here

該例外的原因是在某些版本的Populous中,API已更改,您使用的示例適用於舊版API。請將ICO存儲庫和Populous升級到最新的兼容版本配置,您可以找到in ICO repo Travis output

請替換此行:

FractionalERC20 = chain.contract_factories.FractionalERC20 

有了這個:

from ico.utils import get_contract_by_name 

FractionalERC20 = = get_contract_by_name(chain, "FractionalERC20") 
+0

我試過了你的代碼,但是我得到一個錯誤:'KeyError:'Key'priority'not found in {}「' - https://pastebin.com/zwSC8uam –

+0

請根據https://github.com/TokenMarketNet/ico/blob/mast檢查您的Python庫版本是否兼容er/requirements.txt –

+0

我會這麼做的。 TKS! –

相關問題