0

file javascript

//smartcontract
    window.onload = function() {
        if (typeof web3 === 'undefined') {
            document.getElementById('metamask').innerHTML = 'Instal metamask dulu'
        }
    }
    var abi = [
        {
            "constant": false,
            "inputs": [
                {
                    "name": "_judul",
                    "type": "string"
                },
                {
                    "name": "_content",
                    "type": "string"
                }
            ],
            "name": "addArtikel",
            "outputs": [],
            "payable": false,
            "stateMutability": "nonpayable",
            "type": "function"
        },
        {
            "constant": true,
            "inputs": [
                {
                    "name": "",
                    "type": "uint256"
                }
            ],
            "name": "artikel",
            "outputs": [
                {
                    "name": "judul",
                    "type": "string"
                },
                {
                    "name": "content",
                    "type": "string"
                },
                {
                    "name": "penulis",
                    "type": "address"
                },
                {
                    "name": "timestamp",
                    "type": "uint256"
                }
            ],
            "payable": false,
            "stateMutability": "view",
            "type": "function"
        },
        {
            "constant": true,
            "inputs": [
                {
                    "name": "",
                    "type": "address"
                },
                {
                    "name": "",
                    "type": "uint256"
                }
            ],
            "name": "penulisPost",
            "outputs": [
                {
                    "name": "judul",
                    "type": "string"
                },
                {
                    "name": "content",
                    "type": "string"
                },
                {
                    "name": "penulis",
                    "type": "address"
                },
                {
                    "name": "timestamp",
                    "type": "uint256"
                }
            ],
            "payable": false,
            "stateMutability": "view",
            "type": "function"
        }
    ]

var contractaddress = '0x9b67c76A53517A7985367e240343DDA6Ad2dBE81'
var _abi = web3.eth.contract(abi);
var _function = _abi.at(contractaddress);

$(document).ready(function(){
    $("#btnTambah").click(function(){
        _function.addArtikel.sendTransaction($("#judul").val(), {from: web3.eth.accounts[0], gas: 4000000});
    });
});

my smartcontract

pragma solidity >=0.4.22 <0.6.0;

contract blog {

// content post
struct Posting {
    string judul;
    string content;
    address penulis;
    uint256 timestamp;
}

mapping(address => Posting[]) public penulisPost;

Posting[] public artikel;

// tambah artikel

function addArtikel(string memory _judul, string memory _content) public {
   Posting memory post = Posting(_judul, _content,  msg.sender, now);
   penulisPost[msg.sender].push(post);
    artikel.push(post);
    }
}

MY ERORR

Uncaught Error: The MetaMask Web3 object does not support synchronous methods like eth_sendTransaction without a callback parameter. See https://github.com/MetaMask/faq/blob/master/DEVELOPERS.md#dizzy-all-async---think-of-metamask-as-a-light-client for details.
    at MetamaskInpageProvider._sendSync (inpage.js:1)
    at MetamaskInpageProvider.send (inpage.js:1)
    at Proxy.h.(:8887/online/anonymous function) (chrome-extension://nkbihfbeogaeaoehlefnkodbefgpgknn/inpage.js:1:3202)
    at a.send (inpage.js:1)
    at n.e [as sendTransaction] (inpage.js:1)
    at u.sendTransaction (inpage.js:1)
    at HTMLButtonElement.<anonymous> (main.js:100)
    at HTMLButtonElement.dispatch (jquery-3.3.1.slim.min.js:2)
    at HTMLButtonElement.v.handle (jquery-3.3.1.slim.min.js:2)
  • 1
    Hi there. What is the error? – Richard Horrocks Dec 20 '18 at 14:03
  • Declare function addArtikel as public payable. – goodvibration Dec 20 '18 at 14:04
0

Check your parameters. Web3.eth.sendTransaction: web3.eth.sendTransaction(transactionObject [, callback])

Your error message specifies the lack of a callback. Additionally, I'm not sure what $("#judul").val() is for you, but likely needs to be assigned in the transactionObjec, which is the first parameter

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.