Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // A $( document ).ready() block.
- $(document).ready(function() {
- console.log('ready!');
- });
- // Initialize Web3
- if (typeof web3 !== 'undefined') {
- web3 = new Web3(web3.currentProvider);
- } else {
- web3 = new Web3(new Web3.providers.HttpProvider('http://localhost:8545'));
- }
- // Set Account
- web3.eth.defaultAccount = web3.eth.accounts[0];
- // Set Contract Abi
- var contractAbi = [
- {
- constant: false,
- inputs: [
- {
- name: '_ipfsAddress',
- type: 'string'
- },
- {
- name: '_author',
- type: 'string'
- }
- ],
- name: 'createKidney',
- outputs: [],
- payable: false,
- stateMutability: 'nonpayable',
- type: 'function'
- },
- {
- anonymous: false,
- inputs: [
- {
- indexed: false,
- name: 'id',
- type: 'uint256'
- },
- {
- indexed: false,
- name: 'date',
- type: 'uint256'
- },
- {
- indexed: false,
- name: 'ipfsAddress',
- type: 'string'
- },
- {
- indexed: false,
- name: 'author',
- type: 'string'
- }
- ],
- name: 'KidneyCreated',
- type: 'event'
- },
- {
- constant: false,
- inputs: [
- {
- name: 'id',
- type: 'uint256'
- }
- ],
- name: 'toggleActive',
- outputs: [],
- payable: false,
- stateMutability: 'nonpayable',
- type: 'function'
- },
- {
- inputs: [],
- payable: false,
- stateMutability: 'nonpayable',
- type: 'constructor'
- },
- {
- constant: true,
- inputs: [
- {
- name: 'id',
- type: 'uint256'
- }
- ],
- name: 'getKidney',
- outputs: [
- {
- name: '',
- type: 'uint256'
- },
- {
- name: '',
- type: 'uint256'
- },
- {
- name: '',
- type: 'string'
- },
- {
- name: '',
- type: 'string'
- },
- {
- name: '',
- type: 'bool'
- }
- ],
- payable: false,
- stateMutability: 'view',
- type: 'function'
- },
- {
- constant: true,
- inputs: [],
- name: 'getKidneyIds',
- outputs: [
- {
- name: '',
- type: 'uint256[]'
- }
- ],
- payable: false,
- stateMutability: 'view',
- type: 'function'
- }
- ]; // Add Your Contract ABI here!!!
- // Set Contract Address
- var contractAddress = '0xd24be3716b795be94a9a1c7e85c2f14135a4ee81'; // Add Your Contract address here!!!
- // Set the Contract
- var contract = web3.eth.contract(contractAbi).at(contractAddress);
- $('#form1').on('submit', event => {
- event.preventDefault();
- var organ = $('#organ').val();
- var author = $('#author').val();
- var obj = {
- organ,
- author
- };
- console.log(obj);
- contract.createKidney(
- organ,
- author,
- { from: web3.eth.defaultAccount, gas: 1000000 },
- err => {
- console.log(err);
- }
- );
- });
- $('#form2').on('submit', event => {
- event.preventDefault();
- var id = $('#kidneyId').val();
- contract.getKidney(id, err => {
- console.log(err);
- });
- });
- (async () => {
- const accounts = await web3.eth.getAccounts();
- console.log(accounts);
- const balance = await web3.eth.getBalance(accounts[0]);
- console.log('balance', web3.utils.fromWei(balance, 'ether'));
- })();
- $('#getKidneyIds').click(() => {
- contract.getKidneyIds().call(err => console.log(err));
- });
Add Comment
Please, Sign In to add comment