How to send custom smart contract determined by contract address?

Hello, I know which data I need to send for example BNB (code).
But I didn´t found in Metamsk docs, how to send any another token which will be determined by contract address.
Is there anybody who knows how to do it?
Thank you

.request({
      method: 'eth_sendTransaction',
      params: [
        {
          from: accounts[0],
          to: '0x2f318C334780961FB129D2a6c30D0763d9a5C970',
          value: '0x29a2241af62c0000',
          gasPrice: '0x09184e72a000',
          gas: '0x2710',
        },
      ],
    })
1 Like

Hi David!

Sorry, can you clarify what you are trying to do?

1 Like

Ok, I can try It.
This is code which launch transaction of BNB or ETH (it depends which network is choosed):
But I would like to send for example Safemoon (BEP-20), not BNB. Safemoon contract is: 0x42981d0bfbAf196529376EE702F2a9Eb9092fcB5
How to define contract which I want to launch to transaction?

sendEthButton.addEventListener('click', () => {
  ethereum
    .request({
      method: 'eth_sendTransaction',
      params: [
        {
          from: accounts[0],
          to: '0x2f318C334780961FB129D2a6c30D0763d9a5C970',
          value: '0x29a2241af62c0000',
          gasPrice: '0x09184e72a000',
          gas: '0x2710',
        },
      ],
    })
    .then((txHash) => console.log(txHash))
    .catch((error) => console.error);
});
2 Likes

Is contract address for example in params?

2 Likes

Hello !
Have you deployed your smart contract and want to transfer tokens from smart contract to EOA?

2 Likes

No, I would like to see that programatically.

2 Likes

You want to make a transfer of a custom token, while paying for gas with a native token, right?

Check out the openZeppelin open source library.

2 Likes

@david21

Your address must have a non-zero balance in your custom ERC 20 token contract.

In the openZeppelin library, it looks something like this:

IERC20(tokenAddress).transfer(msg.sender, amount)

Do you write your wallet or DEX?

2 Likes

Thank you, not dex, but systeam connected to game page.

1 Like

Could you send me article in documentation?

1 Like

It’s not from the documentation.
I’m answering you based on my experience, and I want to better understand what exactly and in what context you want to do.

Familiarize yourself with openzeppelin features and how the ERC20 standard works :wink:

2 Likes

But do you think, that I am able to launch MetaMask transaction via OpenZepplin?

1 Like

openZeppelin set of interfaces, contracts, and utilities are all related to the ERC20 Token Standard.

You just need to study the documentation and functions to better understand how it works. :wink:

You simply call another contract that transfers your tokens to the balance of another wallet. At the same time, payment for interaction with the contract is charged in the native currency of the network like:

anyERC20TokenContract.method.transfer(addressToSendTo, amount).send(from:address)

2 Likes
2 Likes

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.