1

I have a function that sends eth to a function in a contract with web3:

await contract.methods.withdraw(i).send({
    from: from
    });
    debug("withdraw in battle: "+i);
}

I would like to use a different token instead of ether. How can I pay with tokens? How can I do that? I see no token parameter in web3.

2 Answers 2

0

Let's start with this - ETH isn't a token, but a coin, because it's native to Ethereum blockchain. Tokens are logic built on top of already existing blockchain. Making blockchain movements in ethereum network can be paid only in ETH fees.

But if what you're trying to do is not paying the fee with tokens, but actually sending tokens to a contract method then your contract should be already built in such way to accept these tokens and do something with them based on your logic. You can define the parameters of your contract methods in the smart contract and then pass them from the web3 part.

0

Miroslav gave a good explanation. You can also check this out.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.