0

I am newbee about smart contract and eth tokens. I have created an eth account by:

let account = web3Client.eth.accounts.create()

I have my account details. I need to add some true usd token to eth address. How to mind token to eth address programatically? Can anyone help?

closed as unclear what you're asking by flygoing, Achala Dissanayake, shane, eth Feb 15 at 10:36

Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.

1

To interact with a contract programatically you need its ABI and address. Then you can use web3 to create an interface to the contract:

const tokenAddress = "0x1234.....5678";
const tokenABI = [{.....}];

const token = new web3.eth.Contract(tokenABI, tokenAddress, {
    from: '0x1234....', // default from address
    gasPrice: '20000000000' // default gas price in wei, 20 gwei in this case
});

Now you should be able to call methods from the contract. For an ERC20 token a transfer is

const recipient = '0x111....11';
const amount = 123456;
await token.methods.transfer(recipient, amount).send();

PD For any token the easier way to buy the is from an exchange.

  • Thanks for the reply. For example, say this is a contract Address -> 0x3d5f344e54c9f10c542e0152bcfeeace48d55078 in rinkeby, (rinkeby.etherscan.io/address/…), I am not sure how to get the tokenAddress/tokenABI. Thats the main problem – user2805885 Feb 14 at 8:07
  • @user2805885 For popular tokens you can get both from Etherscan, search for the token name and you will find it. Check the reputation because some of them have fake copies with the same name. Otherwise you have to ask the developers of the contract for the correct address and ABI. – Ismael Feb 14 at 20:08
  • Thanks for the reply. I have one doubt. What exactly is token address? say, i have one eth address it can hold as many token say, if my address is having around 10 different token, so this token address will be different from eth address? if the address is same, how can I transfer one type of token alone? – user2805885 Feb 15 at 3:40
  • It is hard to explain in a few lines. I'd advice to consult some tutorials about ERC20 tokens in Ethereum. Every smart contract in ethereum has its address. When you want to operate with a token you send a transaction to the token address, inside the operation is included all data that is needed, for example for a transfer it includes the recipient and the amount. Wallets with ERC20 supprt should make it very easy to operate with tokens. – Ismael Feb 15 at 6:05
  • I have created the token, and I was able to transfer token successfully. I have another issue, I have a wallet(multisignatire contract), trying to transfer a token with my multisignature wallet. Can you please help me to do? – user2805885 Feb 20 at 15:20

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