1

I have a contract code with 3 params (_orcid , _researchID , _name )

var _orcid = "param1" ;
var _researchID = "param2" ;
var _name = "param3";
var browser_uactor_sol_actorContract = web3.eth.contract([{"constant":true,"inputs":[],"name":"getName","outputs":[{"name":"","type":"string"}],"payable":false,"type":"function"},{"constant":false,"inputs":[],"name":"kill","outputs":[],"payable":false,"type":"function"},{"constant":false,"inputs":[{"name":"_keyword","type":"string"}],"name":"addKeyword","outputs":[],"payable":false,"type":"function"},{"constant":false,"inputs":[{"name":"_relate","type":"string"}],"name":"addRelated","outputs":[],"payable":false,"type":"function"},{"inputs":[{"name":"_orcid","type":"string"},{"name":"_researchID","type":"string"},{"name":"_name","type":"string"}],"payable":false,"type":"constructor"}]);
var browser_uactor_sol_actor = browser_uactor_sol_actorContract.new(
   _orcid,
   _researchID,
   _name,
   {
     from: web3.eth.accounts[0], 
     data: '0x6060604052341561000f57600080fd5b604051610639380380610639833981016040528080518201919060200180518201919060200180518201919050505b606060405190810160405280848152602001838152602001828152506001600082015181600001908051906020019061007892919061010f565b50602082015181600101908051906020019061009592919061010f565b5060408201518160020190805190602001906100b292919061010f565b50905050336000806101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff160217905550600060058190555060006007819055505b5050506101b4565b828054600181600116156101000203166002900490600052602060002090601f016020900481019282601f1061015057805160ff191683800117855561017e565b8280016001018555821561017e579182015b8281111561017d578251825591602001919060010190610162565b5b50905061018b919061018f565b5090565b6101b191905b808211156101ad576000816000905550600101610195565b5090565b90565b610476806101c36000396000f30060606040526000357c0100000000000000000000000000000000000000000000000000000000900463ffffffff16806317d7de7c1461005f57806341c0e1b5146100ee5780637e57812714610103578063cc64aec314610160575b600080fd5b341561006a57600080fd5b6100726101bd565b6040518080602001828103825283818151815260200191508051906020019080838360005b838110156100b35780820151818401525b602081019050610097565b50505050905090810190601f1680156100e05780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b34156100f957600080fd5b610101610269565b005b341561010e57600080fd5b61015e600480803590602001908201803590602001908080601f016020809104026020016040519081016040528093929190818152602001838380828437820191505050505050919050506102fb565b005b341561016b57600080fd5b6101bb600480803590602001908201803590602001908080601f01602080910402602001604051908101604052809392919081815260200183838082843782019150505050505091905050610346565b005b6101c5610391565b60016002018054600181600116156101000203166002900480601f01602080910402602001604051908101604052809291908181526020018280546001816001161561010002031660029004801561025e5780601f106102335761010080835404028352916020019161025e565b820191906000526020600020905b81548152906001019060200180831161024157829003601f168201915b505050505090505b90565b6000809054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff1614156102f8576000809054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16ff5b5b565b80600660075481548110151561030d57fe5b906000526020600020900160005b50908051906020019061032f9291906103a5565b506007546007600082825401925050819055505b50565b80600460055481548110151561035857fe5b906000526020600020900160005b50908051906020019061037a9291906103a5565b506005546005600082825401925050819055505b50565b602060405190810160405280600081525090565b828054600181600116156101000203166002900490600052602060002090601f016020900481019282601f106103e657805160ff1916838001178555610414565b82800160010185558215610414579182015b828111156104135782518255916020019190600101906103f8565b5b5090506104219190610425565b5090565b61044791905b8082111561044357600081600090555060010161042b565b5090565b905600a165627a7a7230582048713c28426216ca30f7251474fe750043e3a47f742789ec2af822d7e6f9c4bf0029', 
     gas: '4300000'
   }, function (e, contract){
    console.log(e, contract);
    if (typeof contract.address !== 'undefined') {
         console.log('Contract mined! address: ' + contract.address + ' transactionHash: ' + contract.transactionHash);
    }
 }) 

I am trying to créate a contract from HTML page with


hash =web3.eth.sendTransaction({from: '0xXXXXXXXXXXXXXX',gas: '0xDBBE2', data: code, _orcid: '12345', _researchID : 'b0978', _name: 'myName' }); 

The contract is created, but the params are not loaded on it. I do not know how these areguments have to be added within web3.eth.sendTransaction.

Can someone help me with this?

  • you're trying to call a function of the smart-contract? – Sepultura Aug 8 '17 at 11:57
1

@Sepultura Finally I did it, I deployed a new contract from a web site with all the parameters. I didn´t use sendTransaction but new, this is the code:

function addActor(){ var address = document.getElementById('add').value; var _orcid = '12345' ; var _researchID = '12345' ; var _name = 'Jon' ; var code= '0x606060405....544fd506e7e40029'; var contract= web3.eth.contract(actorABI).new( _orcid, _researchID, _name,{from: address, data: code, gas: '0xDBBE2'}); hash= contract.transactionHash; var trx= web3.eth.getTransactionReceipt(hash);

In order to check the new contract I run:

 var abi =[{"constant":false,"inputs...."type":"constructor"}];
console.log("ABI: "+abi);
var MyContract3 = eth.contract(abi);
console.log(MyContract3);
var contractInstance3 = MyContract3.at("0x1f2a50d8deb332d78466fc2077eb2152cb05fa39");
console.log("Instancia3:"+contractInstance3.address);

console.log("Name:"+contractInstance3.getName.call());
console.log("Creador:"+contractInstance3.getCreator.call());  

This is the console output:

ABI: [object Object],[object Object],[object Object],[object Object],[objectObject],[object Object] [object Object]
Instancia3:0x1f2a50d8deb332d78466fc2077eb2152cb05fa39
Name:Jon
Creador:0x767c5be07b8603782f9c69a1ed1fd9b759ba3057
true

0

Assuming you're trying to call a contract-function from a web-application, it should work this way:

let _orcid = "param1" ;
let _researchID = "param2" ;
let _name = "param3";

// init web3, http-provider
let web3 = new Web3(new Web3.providers.HttpProvider('192.168.1.10:8042'));

// init contract
let contract = web3.eth.contract([{"constant":true,"inputs":[],"name":"getName","outputs":[{"name":"","type":"string"}],"payable":false,"type":"function"},{"constant":false,"inputs":[],"name":"kill","outputs":[],"payable":false,"type":"function"},{"constant":false,"inputs":[{"name":"_keyword","type":"string"}],"name":"addKeyword","outputs":[],"payable":false,"type":"function"},{"constant":false,"inputs":[{"name":"_relate","type":"string"}],"name":"addRelated","outputs":[],"payable":false,"type":"function"},{"inputs":[{"name":"_orcid","type":"string"},{"name":"_researchID","type":"string"},{"name":"_name","type":"string"}],"payable":false,"type":"constructor"}]);

// set address of the contract
contract.at('0x0000000...');

// call function
contract.myFunction(_orcid, _researchID, _name, (error, result) => {
    // finished
});

First you need to init web3 with your http-provider (which is a running node you can connect to). You need the IP-address of that node and the RPC-Port of the HTTP-RPC-Server.

Then you can get the contract instance from web3, but you also have to set the address of the contract (where the contract is saved in the blockchain).

Finally you're able to call your smart-contract functions.

If you running a private node by your own, you have to make sure, that you configured it proberly, so that the RPC-HTTP-Server is startet, the web3-API is unlocked and your node is accepting requests from outside.

Here is a example of how I start my node, but keep in mind that it accepts requests from everyone, which is a high security risk if the node is accessible from the internet:

geth --identity "node1" --fast --networkid 15 --datadir /home/pi/ethereum-private/node --nodiscover --rpc --rpcaddr "0.0.0.0" --rpcapi "eth,web3,net" --rpccorsdomain "*" --rpcport "8042" --port "30303" --unlock 0 --password "/home/pi/ethereum-private/node/password.txt" --ipcpath /home/pi/.ethereum/geth.ipc

edit: if you just wan't to deploy a Contract, you can use a Framework like Truffle. I'm not going into detail, but here is a good tutorial.

  • I am trying to créate a new contract with some parameters, I do not want to use an existing contract. – Alienado Aug 8 '17 at 13:34
  • Thanks for your response, but I am trying to create a new contract with some parameters. I can also create the contract using this, but the parameters are no loaded in the contract MyContract = web3.eth.contract(actorABI); contact = MyContract.new(['param1'], ['param2'],['param3'],{from: '0x00000000000000000',gas: '0xDBBE2', data: code}); – Alienado Aug 8 '17 at 13:40
  • you need to deploy the contract on the blockchain, you can't do that like this, see the link I postet for a tutorial – Sepultura Aug 8 '17 at 13:42
  • The contract is created in the privite blockchain that I have. <br/> I was reading the API info link for web3.eth.sendTransaction where I find: <br/> data: String - (optional) Either a byte string containing the associated data of the message, or in the case of a contract-creation transaction, the initialisation code. – Alienado Aug 8 '17 at 13:55
  • I don't understand what you're trying to do ... so you have your contract deployed on the blockchain? What is the address of the contract? – Sepultura Aug 8 '17 at 13:58

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.