作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我尝试使用以下 Python 代码进行 ESDT 代币发行交易
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)
它失败了
ProxyRequestError: Proxy request error for url [https://devnet-gateway.elrond.com/transaction/send]:
{
'data': None,
'error': 'transaction generation failed: invalid value',
'code': 'internal_issue'
}
最佳答案
您使用 str(0.05 * 10**18)
获取值的字符串。
然而,这实际上是以科学记数法输出的值,这不是区块链所期望的。
>>> str(0.05 * 10**18)
'5e+16'
将其转换为
int
首先将强制正确输出,因此您可以使用
str(int(0.05 * 10**18))
反而 :)
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)
关于elrond - Erdpy:代币发行交易失败,代码为:internal_issue,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/69595384/
我是一名优秀的程序员,十分优秀!