第三方可以将 ERC20 令牌交易发送到以太坊区块链吗?
Can third party send an ERC20 token transaction to ethereum blockchain?
我想创建一个智能合约,人们可以在钱包中没有以太币的情况下转移代币。
假设 A 想给 B 转 ERC20 代币,但他的钱包里没有以太币。
第三方 C 是否可以为 A 发送交易并因此支付 gas?是否可以在合约中为这个 usgae 创建一个函数?
我在网上搜索了解决方案,但没有找到。
正是这种情况已经在ERC20标准中定义了。它的这个功能:
function transferFrom(address from, address to, uint tokens) public returns (bool success);
但在 C 方可以使用它并从 A 向 B 发送代币之前,A 必须通过以下功能批准 C 执行此操作,该功能也在 ERC20 标准中定义:
function approve(address spender, uint tokens) public returns (bool success);
不,在标准的 ERC20 代币合约中,代币持有者必须至少发起一笔交易(调用 transfer()
或 approve()
),并且交易必须始终由其发起者支付.
这是以太坊 dApp 开发的关键问题,也是代币的关键问题。这是一个very old thread on Ethereum Stack Exchange, and also this one.
There are 2 options with their pros and cons:
Use signatures
- Every function in your smart contract must have
signature
parameter.
- People who want to interact with the smart contract must sign the function parameters with their account's private key and send it to the smart contract owner (via any communication channel).
- The owner then submits the parameters along with the signature to the blockchain, paying for gas. The signature guarantees that the message was approved by the user.
Refund used gas at the end of the transaction. A modifier refundGasCost
can be used for this (see below).
但是 (1) 真的很难应用于代币转移,因为您只是不知道谁在使用代币,并且 (2) 并没有真正解决这个问题。
最近发生了很多事情,有这个博客 post 关于 How to save your Ethereum Dapp users from paying gas for transactions, and since you ask about tokens, there is an ERC that suggests to Pay transfers in tokens instead of gas, in one transaction 如果你有代币但没有 ETH 就好了。
希望对您有所帮助。
我想创建一个智能合约,人们可以在钱包中没有以太币的情况下转移代币。
假设 A 想给 B 转 ERC20 代币,但他的钱包里没有以太币。
第三方 C 是否可以为 A 发送交易并因此支付 gas?是否可以在合约中为这个 usgae 创建一个函数?
我在网上搜索了解决方案,但没有找到。
正是这种情况已经在ERC20标准中定义了。它的这个功能:
function transferFrom(address from, address to, uint tokens) public returns (bool success);
但在 C 方可以使用它并从 A 向 B 发送代币之前,A 必须通过以下功能批准 C 执行此操作,该功能也在 ERC20 标准中定义:
function approve(address spender, uint tokens) public returns (bool success);
不,在标准的 ERC20 代币合约中,代币持有者必须至少发起一笔交易(调用 transfer()
或 approve()
),并且交易必须始终由其发起者支付.
这是以太坊 dApp 开发的关键问题,也是代币的关键问题。这是一个very old thread on Ethereum Stack Exchange, and also this one.
There are 2 options with their pros and cons:
Use signatures
- Every function in your smart contract must have
signature
parameter.- People who want to interact with the smart contract must sign the function parameters with their account's private key and send it to the smart contract owner (via any communication channel).
- The owner then submits the parameters along with the signature to the blockchain, paying for gas. The signature guarantees that the message was approved by the user.
Refund used gas at the end of the transaction. A modifier
refundGasCost
can be used for this (see below).
但是 (1) 真的很难应用于代币转移,因为您只是不知道谁在使用代币,并且 (2) 并没有真正解决这个问题。
最近发生了很多事情,有这个博客 post 关于 How to save your Ethereum Dapp users from paying gas for transactions, and since you ask about tokens, there is an ERC that suggests to Pay transfers in tokens instead of gas, in one transaction 如果你有代币但没有 ETH 就好了。
希望对您有所帮助。