3

I am creating a frontend app based on Truffle + Webpack, following this tuto : http://truffleframework.com/tutorials/building-testing-frontend-app-truffle-3, and have no uderstanding of JavaScript at all.

The code works on truffle console and the app globally works, except for the function "append_buy_brent", adding a new element to a struct array called buy_orderbook_brent

Solidity :

contract Petroleum{

// Initialisations

address _creator;
uint user_number;

struct Baril_order {
    uint price;
    uint quantity;
    address addr;
}

Baril_order[] buy_orderbook_brent;

mapping(address => uint) account_map;
mapping(uint => uint) user_balance;
mapping(uint => uint) number_of_brent;

function Petroleum() payable{       

    _creator=msg.sender;
    user_number=0;
    test=0;

    account_map[_creator]=0;
    account_map[0x7f8105da4dd1af61da7bf587766103ba8534fcdc]=1;

    user_balance[account_map[msg.sender]]=100000;
    number_of_brent[account_map[msg.sender]]=5;
    number_of_wti[account_map[msg.sender]]=2;
    debt[account_map[msg.sender]]=20;
    user_balance[account_map[0x7f8105da4dd1af61da7bf587766103ba8534fcdc]]=200000;
    number_of_brent[account_map[0x7f8105da4dd1af61da7bf587766103ba8534fcdc]]=7;
    number_of_wti[account_map[0x7f8105da4dd1af61da7bf587766103ba8534fcdc]]=10;
    debt[account_map[0x7f8105da4dd1af61da7bf587766103ba8534fcdc]]=3;
}

function append_buy_brent(uint price, uint quantity, address addr) payable {
        buy_orderbook_brent.push(
            Baril_order({
                price:price,
                quantity: quantity,
                addr: addr,
            })
        );
    }
}

JavaScript :

import { default as Web3} from 'web3';
import { default as contract } from 'truffle-contract'
import Petroleum_artifacts from '../../build/contracts/Petroleum.json'
var Petroleum = contract(Petroleum_artifacts);

var accounts;
var account;
var account1;

window.App = {
start: function() {
    var self = this;

    Petroleum.setProvider(web3.currentProvider);

    web3.eth.getAccounts(function(err, accs) {
      if (err != null) {
        alert("There was an error fetching your accounts.");
        return;
      }

      if (accs.length == 0) {
        alert("Couldn't get any accounts! Make sure your Ethereum client is configured correctly.");
        return;
      }

      accounts = accs;
      account = accounts[0];
      account1 = accounts[1];

      self.refreshBalance1();
      self.refreshBalance2();
    });
  },

append_buy_brent: function(){
        var self = this;

        var price_buy_brent= parseInt(document.getElementById("price_buy_brent").value);
        var quantity_buy_brent=parseInt(document.getElementById("quantity_buy_brent").value);

        this.setStatus("Initiating transaction... (please wait)");

        var petro;

        Petroleum.deployed().then(function(instance) {
          petro = instance;
          return petro.append_buy_brent(price_buy_brent,quantity_buy_brent, account, {from: account, value: web3.toWei(1000, "ether")});
        }).then(function(value) {
            self.setStatus("Transaction complete!");
            self.refreshBalance1();
            self.refreshBalance2();
        }).catch(function(e) {
          console.log(e);
          self.setStatus("Error placing buy_brent; see log.");
        });
     },
}

Log :

Error: VM Exception while processing transaction: invalid JUMP at d8abbe98e23bfa2cd66729f537c8dd23bb72c25425af350243627a30533c3b73/a8c9aca1a9b5fd638a6aa025545e1274787f3456:790

I hope I gave enough information, first time here. Thanks a lot.

  • This usually means your Solidity code has thrown an exception or failed otherwise. The question does not contain the relevant smart contract code, so it's impossible to tell. – Mikko Ohtamaa Apr 15 '17 at 15:41
  • Thank you, I updated by giving a full contract and all the structures involved (I think). – Alex Sala Apr 16 '17 at 7:47
  • Trying testing your smart contract using browser solidity first to make sure that your functions work. Then incorporate web3/truffle – Karan Kurbur Jan 11 '18 at 1:59

Your Answer

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

Browse other questions tagged or ask your own question.