Web3 Registering a Cargo Shipment
Solidity; \n
<code>
contract gonderitakip {
struct gonderi {
uint256 id;
string timespan;
string consignor;
string consignee;
string code;
string ReceiverAddress;
string lastTransportPoint;
string email;
uint256 contact_phone;
}
mapping(uint256 => gonderi) gonderiler;
uint256[] internal gonderiIds;
function set(uint256 id, string memory timespan, string memory consignor,
string memory consignee, string memory code,
string memory ReceiverAddress, string memory lastTransportPoint,
string memory email, uint256 contact_phone) public {
gonderi storage newG = gonderiler[id];
newG.timespan = timespan;
newG.consignor = consignor;
newG.consignee = consignee;
newG.code = code;
newG.ReceiverAddress = ReceiverAddress;
newG.lastTransportPoint = lastTransportPoint;
newG.email = email;
newG.contact_phone = contact_phone;
gonderiIds.push(id);
}
function get(uint256 id) public view returns (uint256, string memory, string memory, string memory, string memory,
string memory, string memory, string memory, uint256){
gonderi storage s = gonderiler[id];
return (s.id, s.timespan, s.consignor, s.consignee, s.code, s.ReceiverAddress, s.lastTransportPoint, s.email, s.contact_phone);
}
}
contract gonderitakip { struct gonderi { uint256 id; string timespan; string consignor; string consignee; string code; string ReceiverAddress; string lastTransportPoint; string email; uint256 contact_phone; } mapping(uint256 => gonderi) gonderiler; uint256[] internal gonderiIds; function set(uint256 id, string memory timespan, string memory consignor, string memory consignee, string memory code, string memory ReceiverAddress, string memory lastTransportPoint, string memory email, uint256 contact_phone) public { gonderi storage newG = gonderiler[id]; newG.timespan = timespan; newG.consignor = consignor; newG.consignee = consignee; newG.code = code; newG.ReceiverAddress = ReceiverAddress; newG.lastTransportPoint = lastTransportPoint; newG.email = email; newG.contact_phone = contact_phone; gonderiIds.push(id); } function get(uint256 id) public view returns (uint256, string memory, string memory, string memory, string memory, string memory, string memory, string memory, uint256){ gonderi storage s = gonderiler[id]; return (s.id, s.timespan, s.consignor, s.consignee, s.code, s.ReceiverAddress, s.lastTransportPoint, s.email, s.contact_phone); } }
contract gonderitakip {
struct gonderi {
uint256 id;
string timespan;
string consignor;
string consignee;
string code;
string ReceiverAddress;
string lastTransportPoint;
string email;
uint256 contact_phone;
}
mapping(uint256 => gonderi) gonderiler;
uint256[] internal gonderiIds;
function set(uint256 id, string memory timespan, string memory consignor,
string memory consignee, string memory code,
string memory ReceiverAddress, string memory lastTransportPoint,
string memory email, uint256 contact_phone) public {
gonderi storage newG = gonderiler[id];
newG.timespan = timespan;
newG.consignor = consignor;
newG.consignee = consignee;
newG.code = code;
newG.ReceiverAddress = ReceiverAddress;
newG.lastTransportPoint = lastTransportPoint;
newG.email = email;
newG.contact_phone = contact_phone;
gonderiIds.push(id);
}
function get(uint256 id) public view returns (uint256, string memory, string memory, string memory, string memory,
string memory, string memory, string memory, uint256){
gonderi storage s = gonderiler[id];
return (s.id, s.timespan, s.consignor, s.consignee, s.code, s.ReceiverAddress, s.lastTransportPoint, s.email, s.contact_phone);
}
}
</code>
JS; \n
<code>
const web3 = new Web3(window.ethereum);
const contract_adr='0xbBc7Aad82';
const abi = "abijson";
const contract = new web3.eth.Contract(JSON.parse(abi), contract_adr);
async function connect() {
await window.ethereum.enable();
web3.eth.accounts = await web3.eth.getAccounts();
web3.eth.defaultAccount = web3.eth.accounts[0];
}
async function getFunc(){
let request = await contract.methods.get(10).call();
console.log(request);
}
async function setFunc(){
contract.methods.set(
10,
'2022-01-27',
'metin yakar',
'A Müşterisi',
'GDR2022001RD',
'Turkey, Ankara, Çankaya',
'Bolu 2 Nolu Transfer Merkezi',
'test@metinyakar.net',
5551234567
).send({from:web3.eth.defaultAccount});
}
</code>