首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Erdpy:令牌颁发事务失败,代码为: internal_issue

Erdpy:令牌颁发事务失败,代码为: internal_issue
EN

Stack Overflow用户
提问于 2021-10-16 11:59:56
回答 1查看 308关注 0票数 5

我尝试使用以下Python代码进行ESDT令牌发布事务

代码语言:javascript
复制
from erdpy.accounts import Account, Address
from erdpy.proxy import ElrondProxy
from erdpy.transactions import BunchOfTransactions
from erdpy.transactions import Transaction
from erdpy.wallet import signing


TOKEN_NAME = b"Cowdings"
TOKEN_SYMBOL = b"MOO"

DECIMALS = 18
SUPPLY = 1000 * 10**DECIMALS


def hex_string(s: str) -> str:
    assert type(s) == bytes, "Make sure everything is bytes data or utf-8 encoded"
    return hexlify(s).decode("ascii")


def hex_int(i: int) -> str:
    assert type(i) == int, "Make sure everything is bytes data or utf-8 encoded"
    return hex(i)[2:]


proxy = ElrondProxy("https://devnet-gateway.elrond.com")
sender = Account(pem_file="test-wallet.pem")
sender.sync_nonce(proxy)

tx = Transaction()
tx.nonce = sender.nonce
tx.value = str(0.05 * 10**18)  # 0.05 EGLD, as required for issuing a token according to the documentation
tx.sender = sender.address.bech32()
# System contract address to issue out the new token as per
# https://docs.elrond.com/developers/esdt-tokens/#issuance-of-fungible-esdt-tokens
tx.receiver = "erd1qqqqqqqqqqqqqqqpqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqzllls8a5w6u"
tx.gasPrice = 1000000000
tx.gasLimit = 50000
tx.data = f"issue" \
          f"@{hex_string(TOKEN_NAME)}" \
          f"@{hex_string(TOKEN_SYMBOL)}" \
          f"@{hex_int(SUPPLY)}" \
          f"@{hex_int(DECIMALS)}" 

tx.chainID = "D"  # For devnet https://devnet-gateway.elrond.com/network/config
tx.version = 1

tx.signature = signing.sign_transaction(tx, sender)
tx.send(proxy)

它失败了,错误为

代码语言:javascript
复制
ProxyRequestError: Proxy request error for url [https://devnet-gateway.elrond.com/transaction/send]: 
{
    'data': None, 
    'error': 'transaction generation failed: invalid value', 
    'code': 'internal_issue'
}
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2021-10-16 13:59:13

您可以使用str(0.05 * 10**18)来获取该值的字符串。

然而,这实际上是以科学记数法输出的值,这并不是区块链所期望的。

代码语言:javascript
复制
>>> str(0.05 * 10**18)
'5e+16'

首先将其转换为int将强制执行正确的输出,因此您可以使用str(int(0.05 * 10**18)) :)

因此,完整的代码应该如下所示:

代码语言:javascript
复制
from erdpy.accounts import Account, Address
from erdpy.proxy import ElrondProxy
from erdpy.transactions import BunchOfTransactions
from erdpy.transactions import Transaction
from erdpy.wallet import signing


TOKEN_NAME = b"Cowdings"
TOKEN_SYMBOL = b"MOO"

DECIMALS = 18
SUPPLY = 1000 * 10**DECIMALS


def hex_string(s: str) -> str:
    assert type(s) == bytes, "Make sure everything is bytes data or utf-8 encoded"
    return hexlify(s).decode("ascii")


def hex_int(i: int) -> str:
    assert type(i) == int, "Make sure everything is bytes data or utf-8 encoded"
    return hex(i)[2:]


proxy = ElrondProxy("https://devnet-gateway.elrond.com")
sender = Account(pem_file="test-wallet.pem")
sender.sync_nonce(proxy)

tx = Transaction()
tx.nonce = sender.nonce
tx.value = str(int(0.05 * 10**18))  # 0.05 EGLD, as required for issuing a token according to the documentation
tx.sender = sender.address.bech32()
# System contract address to issue out the new token as per
# https://docs.elrond.com/developers/esdt-tokens/#issuance-of-fungible-esdt-tokens
tx.receiver = "erd1qqqqqqqqqqqqqqqpqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqzllls8a5w6u"
tx.gasPrice = 1000000000
tx.gasLimit = 50000
tx.data = f"issue" \
          f"@{hex_string(TOKEN_NAME)}" \
          f"@{hex_string(TOKEN_SYMBOL)}" \
          f"@{hex_int(SUPPLY)}" \
          f"@{hex_int(DECIMALS)}" 

tx.chainID = "D"  # For devnet https://devnet-gateway.elrond.com/network/config
tx.version = 1

tx.signature = signing.sign_transaction(tx, sender)
tx.send(proxy)
票数 5
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/69595384

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档