2

I tried to send ether from multiaddress, for that I have created one contract. Contract is deployed successfully in ropsten testnet.

I have started service in background using this command.

parity --warp --chain ropsten --rpcapi 'eth,net,web3,personal'

Contract Code:

pragma solidity ^0.4.20;

contract ERC20 {
  function transfer(address _recipient, uint256 _value) public returns (bool success);
}

contract Airdrop {
  function drop(ERC20 token, address[] recipients, uint256[] values) public {
    for (uint256 i = 0; i < recipients.length; i++) {
      token.transfer(recipients[i], values[i]);
    }
  }
}

Contract Deployed URL: https://ropsten.etherscan.io/address/0x84265173B2386D674ABA59b35D8C2A77C8A88181

Tried to apply send_transaction using Web3Js but Not able to success.

const Web3 = require('web3')
const abi = require('human-standard-token-abi') 

const web3 = new Web3(new Web3.providers.HttpProvider("http://localhost:8545"));


// Define the contract addresses and the contract instance
const contractAddress = '0x84265173B2386D674ABA59b35D8C2A77C8A88181'
//const contract = new web3.eth.contract(abi, contractAddress)

var contractAbi = web3.eth.contract(abi);
var contract = contractAbi.at(contractAddress);
// suppose you want to call a function named myFunction of myContract

/*console.log(web3.eth.accounts[0]);
return false;*/

contract.drop.sendTransaction('0x627306090abaB3A6e1400e9345bC60c78a8BEf57',["0x2885f9904f3d1790ba53009bc9e0baae377d67df","0x7b7cd7d5cee9fb36b7995a3d81df0122a0b1af4a"],[100,200],{
    from:web3.eth.accounts[0],
    gas:4000000},function (error, result){ //get callback from function which is your transaction key
    if(!error){
        console.log(result);
    } else{
        console.log(error);
    }
})

Please let me know what is wrong in this steps. What I missed from my side. I am not able to send my transaction to multiaddress using contract.

Currently I am getting this error:

TypeError: name.match is not a function
    at SolidityTypeAddress.isType (/var/www/html/BlockChain/parity/node_modules/web3/lib/solidity/address.js:23:19)
    at /var/www/html/BlockChain/parity/node_modules/web3/lib/solidity/coder.js:57:18
    at Array.filter (<anonymous>)
    at SolidityCoder._requireType (/var/www/html/BlockChain/parity/node_modules/web3/lib/solidity/coder.js:56:36)
    at /var/www/html/BlockChain/parity/node_modules/web3/lib/solidity/coder.js:231:21
    at Array.map (<anonymous>)
    at SolidityCoder.getSolidityTypes (/var/www/html/BlockChain/parity/node_modules/web3/lib/solidity/coder.js:230:18)
    at SolidityCoder.encodeParams (/var/www/html/BlockChain/parity/node_modules/web3/lib/solidity/coder.js:88:30)
    at SolidityFunction.toPayload (/var/www/html/BlockChain/parity/node_modules/web3/lib/web3/function.js:92:52)
    at SolidityFunction.sendTransaction (/var/www/html/BlockChain/parity/node_modules/web3/lib/web3/function.js:163:24)

But I don't think it is related to contract. I am missing something or going in wrong way?

Please help me urgent so, I can continue my work based on it.

1

You are passing human-standard-token-abi (which is an ERC20 contract ABI) to create your Airdrop contract that has a completely different functions.

ABI for Airdrop contract:

[
    {
      "constant": false,
      "inputs": [
        {
          "name": "token",
          "type": "address"
        },
        {
          "name": "recipients",
          "type": "address[]"
        },
        {
          "name": "values",
          "type": "uint256[]"
        }
      ],
      "name": "drop",
      "outputs": [],
      "payable": false,
      "stateMutability": "nonpayable",
      "type": "function"
    }
  ]

That is the ABI that you need to pass to web3.eth.contract(abi); to instantiate your contract object.

  • 1
    Hello @Andrey, I changed ABI as per you gave and it was stuck lock account so, i did unlock but now it is not returning any output or not any error return in sendTransaction functionality. I think something is wrong in sendTransaction function, Can you pls check once? is it correct or not? – kiran malvi Feb 28 '18 at 4:44
  • 1
    Your function looks fine. Is the callback function getting called at all? If before if(!error) you make a line and call console.log(result); console.log(error); - does either outputs anything? – Andrey Feb 28 '18 at 5:05
  • Yes i checked it stil it is getting nothing. @Andrey – kiran malvi Feb 28 '18 at 7:56
  • Transaction done but it is getting fail. ropsten.etherscan.io/tx/… Why it is fail? – kiran malvi Feb 28 '18 at 8:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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