mirror of
https://github.com/status-im/web3.js.git
synced 2025-02-23 19:48:13 +00:00
return values are now objects with named return values
This commit is contained in:
parent
fe47e80d4e
commit
a6f804b15b
@ -454,12 +454,11 @@ Example
|
|||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
// MULTI RETURN:
|
// MULTI-ARGUMENT RETURN:
|
||||||
|
|
||||||
// Solidity
|
// Solidity
|
||||||
contract MyContract {
|
contract MyContract {
|
||||||
function myFunction() returns(uint256 myNumber, string myString) {
|
function myFunction() returns(uint256 myNumber, string myString) {
|
||||||
|
|
||||||
return (23456, "Hello!%");
|
return (23456, "Hello!%");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -467,8 +466,7 @@ Example
|
|||||||
// web3.js
|
// web3.js
|
||||||
var MyContract = new web3.eth.contract(abi, address);
|
var MyContract = new web3.eth.contract(abi, address);
|
||||||
MyContract.methods.myFunction().call()
|
MyContract.methods.myFunction().call()
|
||||||
.then(function(result){
|
.then(console.log);
|
||||||
console.log(result);
|
|
||||||
> {
|
> {
|
||||||
myNumber: '23456',
|
myNumber: '23456',
|
||||||
myString: 'Hello!%',
|
myString: 'Hello!%',
|
||||||
@ -476,14 +474,12 @@ Example
|
|||||||
1: 'Hello!%'
|
1: 'Hello!%'
|
||||||
}
|
}
|
||||||
|
|
||||||
});
|
|
||||||
|
|
||||||
// SINGLE RETURN:
|
// SINGLE-ARGUMENT RETURN:
|
||||||
|
|
||||||
// Solidity
|
// Solidity
|
||||||
contract MyContract {
|
contract MyContract {
|
||||||
function myFunction() returns(string myString) {
|
function myFunction() returns(string myString) {
|
||||||
|
|
||||||
return "Hello!%";
|
return "Hello!%";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -491,12 +487,9 @@ Example
|
|||||||
// web3.js
|
// web3.js
|
||||||
var MyContract = new web3.eth.contract(abi, address);
|
var MyContract = new web3.eth.contract(abi, address);
|
||||||
MyContract.methods.myFunction().call()
|
MyContract.methods.myFunction().call()
|
||||||
.then(function(result){
|
.then(console.log);
|
||||||
console.log(result);
|
|
||||||
> "Hello!%"
|
> "Hello!%"
|
||||||
|
|
||||||
});
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
------------------------------------------------------------------------------
|
------------------------------------------------------------------------------
|
||||||
|
@ -248,9 +248,11 @@ Example
|
|||||||
// auto detects: uint256, bytes, bool, int256
|
// auto detects: uint256, bytes, bool, int256
|
||||||
> "0x3e27a893dc40ef8a7f0841d96639de2f58a132be5ae466d40087a2cfa83b7179"
|
> "0x3e27a893dc40ef8a7f0841d96639de2f58a132be5ae466d40087a2cfa83b7179"
|
||||||
|
|
||||||
|
|
||||||
web3.utils.soliditySha3('Hello!%'); // auto detects: string
|
web3.utils.soliditySha3('Hello!%'); // auto detects: string
|
||||||
> "0x661136a4267dba9ccdf6bfddb7c00e714de936674c4bdb065a531cf1cb15c7fc"
|
> "0x661136a4267dba9ccdf6bfddb7c00e714de936674c4bdb065a531cf1cb15c7fc"
|
||||||
|
|
||||||
|
|
||||||
web3.utils.soliditySha3('234'); // auto detects: uint256
|
web3.utils.soliditySha3('234'); // auto detects: uint256
|
||||||
> "0x61c831beab28d67d1bb40b5ae1a11e2757fa842f031a2d0bc94a7867bc5d26c2"
|
> "0x61c831beab28d67d1bb40b5ae1a11e2757fa842f031a2d0bc94a7867bc5d26c2"
|
||||||
|
|
||||||
@ -266,18 +268,22 @@ Example
|
|||||||
web3.utils.soliditySha3({t: 'uint', v: new BN('234')})); // same as above
|
web3.utils.soliditySha3({t: 'uint', v: new BN('234')})); // same as above
|
||||||
> "0x61c831beab28d67d1bb40b5ae1a11e2757fa842f031a2d0bc94a7867bc5d26c2"
|
> "0x61c831beab28d67d1bb40b5ae1a11e2757fa842f031a2d0bc94a7867bc5d26c2"
|
||||||
|
|
||||||
|
|
||||||
web3.utils.soliditySha3('0x407D73d8a49eeb85D32Cf465507dd71d507100c1');
|
web3.utils.soliditySha3('0x407D73d8a49eeb85D32Cf465507dd71d507100c1');
|
||||||
> "0x4e8ebbefa452077428f93c9520d3edd60594ff452a29ac7d2ccc11d47f3ab95b"
|
> "0x4e8ebbefa452077428f93c9520d3edd60594ff452a29ac7d2ccc11d47f3ab95b"
|
||||||
|
|
||||||
web3.utils.soliditySha3({t: 'bytes', v: '0x407D73d8a49eeb85D32Cf465507dd71d507100c1'});
|
web3.utils.soliditySha3({t: 'bytes', v: '0x407D73d8a49eeb85D32Cf465507dd71d507100c1'});
|
||||||
> "0x4e8ebbefa452077428f93c9520d3edd60594ff452a29ac7d2ccc11d47f3ab95b" // same result as above
|
> "0x4e8ebbefa452077428f93c9520d3edd60594ff452a29ac7d2ccc11d47f3ab95b" // same result as above
|
||||||
|
|
||||||
|
|
||||||
web3.utils.soliditySha3({t: 'address', v: '0x407D73d8a49eeb85D32Cf465507dd71d507100c1'});
|
web3.utils.soliditySha3({t: 'address', v: '0x407D73d8a49eeb85D32Cf465507dd71d507100c1'});
|
||||||
> "0x4e8ebbefa452077428f93c9520d3edd60594ff452a29ac7d2ccc11d47f3ab95b" // same as above, but will do a checksum check, if its multi case
|
> "0x4e8ebbefa452077428f93c9520d3edd60594ff452a29ac7d2ccc11d47f3ab95b" // same as above, but will do a checksum check, if its multi case
|
||||||
|
|
||||||
|
|
||||||
web3.utils.soliditySha3({t: 'bytes32', v: '0x407D73d8a49eeb85D32Cf465507dd71d507100c1'});
|
web3.utils.soliditySha3({t: 'bytes32', v: '0x407D73d8a49eeb85D32Cf465507dd71d507100c1'});
|
||||||
> "0x3c69a194aaf415ba5d6afca734660d0a3d45acdc05d54cd1ca89a8988e7625b4" // different result as above
|
> "0x3c69a194aaf415ba5d6afca734660d0a3d45acdc05d54cd1ca89a8988e7625b4" // different result as above
|
||||||
|
|
||||||
|
|
||||||
web3.utils.soliditySha3({t: 'string', v: 'Hello!%'}, {t: 'int8', v:-23}, {t: 'address', v: '0x85F43D8a49eeB85d32Cf465507DD71d507100C1d'});
|
web3.utils.soliditySha3({t: 'string', v: 'Hello!%'}, {t: 'int8', v:-23}, {t: 'address', v: '0x85F43D8a49eeB85d32Cf465507DD71d507100C1d'});
|
||||||
> "0xa13b31627c1ed7aaded5aecec71baf02fe123797fffd45e662eac8e06fbe4955"
|
> "0xa13b31627c1ed7aaded5aecec71baf02fe123797fffd45e662eac8e06fbe4955"
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user