Here is my contract example.
pragma solidity ^0.4.18;
contract LocalEthereum {
address public owner;
event Created(bytes32 _tradeHash);
function createEvent() onlyOwner external {
Created(0x01);
}
}
version one
import {default as contract} from 'truffle-contract';
import Web3 from 'web3';
const contractAbstraction = contract(abi);
contractAbstraction.setProvider(this.web3.currentProvider);
contractAbstraction.deployed().then(function(contractInstance) {
}).catch(function(e) {
console.log(e);
})
version 2
const contractAbstraction = contract(abi);
contractAbstraction.setProvider(this.web3.currentProvider);
contractAbstraction.new().then(instance){}.catch(err){}
}
version 3
const contractAbstraction = web3.eth.contract(abi);
var contractInstance = contractAbstraction.at(address);
My first question is compared with code 1 and 2, if I am using the truffle framework to deploy the contract, then I just need to contractAbstraction.deployed() for each call, so what is the use of new().
My assumption of new() will make a new instance of the contract, which initialize the contract, the owner address in the contract is the address of those who uses new(). But why do some examples I see don't use new() at all?
Secondly, compared with code 1 and 3, what is the difference with them, I see different examples using the two, I assume they are the same?