Я хотел бы отправить суммы созданного токена с одного адреса на другой. Я хотел бы использовать eth_sendTransaction:
eth_sendTransaction
Creates new message call transaction or a contract creation, if the data field contains code.
Parameters
Object - The transaction object
from: DATA, 20 Bytes - The address the transaction is send from.
to: DATA, 20 Bytes - (optional when creating new contract) The address the transaction is directed to.
gas: QUANTITY - (optional, default: 90000) Integer of the gas provided for the transaction execution. It will return unused gas.
gasPrice: QUANTITY - (optional, default: To-Be-Determined) Integer of the gasPrice used for each paid gas
value: QUANTITY - (optional) Integer of the value send with this transaction
data: DATA - The compiled code of a contract OR the hash of the invoked method signature and encoded parameters. For details see Ethereum Contract ABI
nonce: QUANTITY - (optional) Integer of a nonce. This allows to overwrite your own pending transactions that use the same nonce.
params: [{
"from": "0xb60e8dd61c5d32be8058bb8eb970870f07233155",
"to": "0xd46e8dd67c5d32be8058bb8eb970870f07244567",
"gas": "0x76c0", // 30400,
"gasPrice": "0x9184e72a000", // 10000000000000
"value": "0x9184e72a", // 2441406250
"data": "0xd46e8dd67c5d32be8d46e8dd67c5d32be8058bb8eb970870f072445675058bb8eb970870f072445675"
}]
The Token uses a basic ERC20 compliant function:
/* Send coins */
function transfer(address _to, uint256 _value) {
if (_to == 0x0) throw; // Prevent transfer to 0x0 address. Use burn() instead
if (balanceOf[msg.sender] < _value) throw; // Check if the sender has enough
if (balanceOf[_to] + _value < balanceOf[_to]) throw; // Check for overflows
balanceOf[msg.sender] -= _value; // Subtract from the sender
balanceOf[_to] += _value; // Add the same to the recipient
Transfer(msg.sender, _to, _value); // Notify anyone listening that this transfer took place
}
Некоторые другие вопросы здесь близки и помогают с eth_call, но не с отправкой транзакций.
Как вызвать метод контракта с помощью API eth_call JSON-RPC
Как я могу получить баланс токена Augur (REP) моей учетной записи через JSON-RPC?
Я вижу, вы должны хешировать имя метода, но на самом деле не знаете, как создать параметры для отправки в транзакцию, поскольку это похоже на добавление первых 4 байтов из хеш-подписи, а затем добавление адреса, заполненного левым нулем.
Пожалуйста, помогите создать вызов JSON RPC для транзакции смарт-токена.
Если есть простой способ сделать это в web3.py, это тоже будет полезно.
Если есть простой способ сделать это в web3.py, это тоже будет полезно.
Вы можете создать объект контракта, используя стандартный ABI токена EIP20 , а затем вызвать его, используя сгенерированные методы, например:
from web3.contract import ConciseContract
token = web3.eth.contract(
token_contract_address,
abi=EIP20_ABI,
ContractFactoryClass=ConciseContract,
)
token.transfer(
"0xd46e8dd67c5d32be8058bb8eb970870f07244567",
2441406250,
transact={
"from": "0xb60e8dd61c5d32be8058bb8eb970870f07233155",
"gasPrice": Web3.toWei(4, 'gwei'),
}
)
Боковые примечания:
token_contract_address