Ich habe folgende Funktion:
/// @notice send `_value` token to `_to` from `msg.sender`
/// @notice send `Pl_value` token to `_to` from `msg.sender`
/// @param _to The address of the recipient
/// @param _value The amount of token to be transferred
/// @param Pl_value The payload to be transferred
/// @return Whether the transfer was successful or not
function transfer(address _from, address _to, uint256 _value, string Pl_value) public returns (bool) {
require(_to != address(0));
// SafeMath.sub will throw if there is not enough balance.
balances[_from] = balances[_from].sub(_value);
balances[_to] = balances[_to].add(_value);
Payload[_to] = Pl_value;
return true;
}
}
Und ich erstelle eine Instanz aus meinem Vertrag wie folgt:
var contractInstance = new web3.eth.Contract(abi, 'address-of-contract');
Wie kann ich diese Funktion aufrufen über:
contractInstance.methods.
Was ist seine Syntax genau? (Ich mache es über die Eingabeaufforderung und das Terminal)
Hier ist die gesamte .sol-Datei:
import './SafeMath.sol';
contract BasicToken {
// Using safe math library for all uint256 operations
using SafeMath for uint256;
// Total supply of token
uint256 public totalSupply;
// Balances for each account
mapping(address => uint256) balances;
mapping(address => string) Payload;
/// @param _owner The address from which the balance will be retrieved
/// @return The balance
function balanceOf(address _owner) constant returns (uint256 balance) {
return balances[_owner];
}
/// @param _owner The address from which the balance will be retrieved
/// @return The payload
function PayloadOf(address _owner) constant returns (string payload) {
return Payload[_owner];
}
/// @notice send `_value` token to `_to` from `msg.sender`
/// @notice send `Pl_value` token to `_to` from `msg.sender`
/// @param _to The address of the recipient
/// @param _value The amount of token to be transferred
/// @param Pl_value The payload to be transferred
/// @return Whether the transfer was successful or not
function transfer(address _from, address _to, uint256 _value, string Pl_value) public returns (bool) {
require(_to != address(0));
// SafeMath.sub will throw if there is not enough balance.
balances[_from] = balances[_from].sub(_value);
balances[_to] = balances[_to].add(_value);
Payload[_to] = Pl_value;
return true;
}
}
Mit web3.js 1.0 nennen Sie es so:
contractInstance.methods.transfer(<method parameters>).send(<options>)
Wo sind die Parameter der Übertragungsmethode: _from
, _to
, _value
und Pl_value
. Mit können Sie die Transaktionsoptionen angeben, wie die Adresse, von der die Transaktion gesendet werden soll, oder den Gaspreis. Siehe Dokumentation: http://web3js.readthedocs.io/en/1.0/web3-eth-contract.html#methods-mymethod-send
Fragesteller
Fragesteller
lunr
from
sollte das Konto sein, das den Smart Contract aufrufen wird.Fragesteller
lunr
Fragesteller