Contracts
Get Contract ABI for Verified contract source code
Returns the contract ABI for the verified contract source code.
GET https://testnetapi.metadium.com/v1/contracts/{contract_hash}/abi
api-key: Your API Key
Query Parameters
Parameter
Description
contract_hash
type: String
value: Address of contract
required: true
//Response Sample Result
{
"status": "200",
"message": "success",
"results": {
"data": [
{
"name": "withdraw",
"type": "function",
"inputs": [
{
"name": "value",
"type": "uint256"
}
],
"outputs": [
{
"name": "",
"type": "bool"
}
],
"payable": false,
"constant": false,
"stateMutability": "nonpayable"
},
...
]
}
}
Get Contract Source Code for Verified Contract Source Code
Returns the contract source code for the verified contract source code.
GET https://explorerapi.test.wemix.com/v1/contracts/0x9afffe2525f25515c127c42ca18dacc5b331995a/code
api-key: Your API Key
Query Parameters
Parameter
Description
contract_hash
type: String
value: Address of contract
required: true
//Response Sample Result
{
"status": "200",
"message": "success",
"results": {
"data": {
"address": "0x9afffe2525f25515c127c42ca18dacc5b331995a",
"logo": null,
"compiler": "v0.5.2+commit.1df8f40c",
"libraries": "[]",
"verify_date": "2019-03-19T07:39:19Z",
"contract_name": "MetaCoin",
"runs_optimizer": "200",
"optimization_enabled": "0",
"contract_code": "0x60806040526 ...,
"contract_abi": [
{
"name": "allowance",
"type": "function",
"inputs": [
{
"name": "owner",
"type": "address"
},
{
"name": "spender",
"type": "address"
}
],
"outputs": [
{
"name": "",
"type": "uint256"
}
],
"payable": false,
"constant": true,
"stateMutability": "view"
}
],
"contract_source": "pragma solidity ^0.5.2; ...,
"constructor_arguments": "",
"swam_source": "bzzr://cb0f24b7c4ce26be17e04ba507a83092072124a305bb7b18926e5eb7b78f73a70029",
"verify_status": "1",
"verify_message": null
}
}
}
Verify Contract Source Code
Returns verification results for contract source code.
POST https://testnetapi.metadium.com/v1/contracts/{contract_hash}/verify
api-key: Your API Key
Content-Type: application/json
{
"contract_name": "TestNFT",
"compiler": "0.6.2",
"runs_optimizer": 200,
"optimization_enabled": 1,
"contract_source": "Ly8gRmlsZTogb3BlbnplcHBlbGluLXNvbGl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YgUmV0dXJucyB0aGUgcmVtYWluZGVyIG9mIGRpdmlkaW5nIHR3byB1bnNpZ25lZCBpbnRlZ2Vycywgd2l0aCBhIGRpdmlzaW9uIGJ5IHplcm8gZmxhZy4KICAgICAqCiAgICAgKiBfQXZhaWxhYmxlIHNpbmNlIHYzLjQuXwogICAgICovCiAgICBmdW5jdGlvbiB0cnlNb2QodWludDI1NiBhLCB1aW50MjU2IGIpIGludGVybmFsIHB1cmUgcmV0dXJucyAoYm9vbCwgdWludDI1NikgewogICAgICAgIGlmIChiID09IDApIHJldHVybiAoZmFsc2UsIDApOwogICAgICAgIHJldHVybiAodHJ1ZSwgYSAlIGIpOwogICAgfQoKICAgIC8qKgogICAgICogQGRldiBSZXR1cm5zIHRoZSBhZGRpdGlvbiBvZiB0d28gdW5zaWduZWQgaW50ZWdlcnMsIHJldmVydGluZyBvbgogICAgICogb3ZlcmZsb3cuCiAgICAgKgogICAgICogQ291bnRlcnBhcnQgdG8gU29saWRpdHkncyBgK2Agb3BlcmF0b3IuCiAgICAgKgogICAgICogUmVxdWlyZW1lbnRzOgogICAgICoKICAgICAqIC0gQWRkaXRpb24gY2Fubm90IG92ZXJmbG93LgogICAgICovCiAgICBmdW5jdGlvbiBhZGQodWludDI1NiBhLCB1aW50MjU2IGIpIGludGVybmFsIHB1cmUgcmV0dXJucyAodWludDI1NikgewogICAgICAgIHVpbnQyNTYgYyA9IGEgKyBiOwogICAgICAgIHJlcXVpcmUoYyA+PSBhLCAiU2FmZU1hdGg6IGFkZGl0aW9uIG92ZXJmbG93Iik7CiAgICAgICAgcmV0dXJuIGM7CiAgICB9CgogICAgLyoqCiAgICAgKiBAZGV2IFJldHVybnMgdGhlIHN1YnRyYWN0aW9uIG9mIHR3byB1bnNpZ25lZCBpbnRlZ2VycywgcmV2ZXJ0aW5nIG9uCiAgICAgKiBvdmVyZmxvdyAod2hlbiB0aGUgcmVzdWx0IGlzIG5lZ2F0aXZlKS4KICAgICAqCiAgICAgKiBDb3VudGV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kpIHsKICAgICAgICBpZiAoc3VjY2VzcykgewogICAgICAgICAgICByZXR1cm4gcmV0dXJuZGF0YTsKICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAvLyBMb29rIGZvciByZXZlcnQgcmVhc29uIGFuZCBidWJibGUgaXQgdXAgaWYgcHJlc2VudAogICAgICAgICAgICBpZiAocmV0dXJuZGF0YS5sZW5ndGggPiAwKSB7CiAgICAgICAgICAgICAgICAvLyBUaGUgZWFzaWVzdCB3YXkgdG8gYnViYmxlIHRoZSByZXZlcnQgcmVhc29uIGlzIHVzaW5nIG1lbW9yeSB2aWEgYXNzZW1ibHkKCiAgICAgICAgICAgICAgICAvLyBzb2xoaW50LWRpc2FibGUtbmV4dC1saW5lIG5vLWlubGluZS1hc3NlbWJseQogICAgICAgICAgICAgICAgYXNzZW1ibHkgewogICAgICAgICAgICAgICAgICAgIGxldCByZXR1cm5kYXRhX3NpemUgOj0gbWxvYWQocmV0dXJuZGF0YSkKICAgICAgICAgICAgICAgICAgICByZXZlcnQoYWRkKDMyLCByZXR1cm5kYXRhKSwgcmV0dXJuZGF0YV9zaXplKQogICAgICAgICAgICAgICAgfQogICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgICAgcmV2ZXJ0KGVycm9yTWVzc2FnZSk7CiAgICAgICAgICAgIH0KICAgICAgICB9CiAgICB9Cn0KCi8vIEZpbGU6IG9wZW56ZXBwZWxpbi1zb2xpZGl0eS9jb250cmFjdHMvdXRpbHMvRW51bWVyYWJsZVNldC5zb2wKCi8vIFNQRFgtTGljZW5zZS1JZGVudGlmaWVyOiBNSVQKCnByYWdtYSBzb2xpZGl0eSA+PTAuNi4wIDwwLjguMDsKCi8qKgogKiBAZGV2IExpYnJhcnkgZm9yIG1hbmFnaW5nCiAqIGh0dHBzOi8vZW4ud2lraXBlZGlhLm9yZy93aWtpL1NldF8oYWJzdHJhY3RfZGF0YV90eXBlKVtzZXRzXSBvZiBwcmltaXRpdmUKICogdHlwZXMuCiAqCiA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cHByb3ZlfS4KICAgICAqLwogICAgZnVuY3Rpb24gYXBwcm92ZShhZGRyZXNzIHRvLCB1aW50MjU2IHRva2VuSWQpIHB1YmxpYyB2aXJ0dWFsIG92ZXJyaWRlIHsKICAgICAgICBhZGRyZXNzIG93bmVyID0gRVJDNzIxLm93bmVyT2YodG9rZW5JZCk7CiAgICAgICAgcmVxdWlyZSh0byAhPSBvd25lciwgIkVSQzcyMTogYXBwcm92YWwgdG8gY3VycmVudCBvd25lciIpOwoKICAgICAgICByZXF1aXJlKF9tc2dTZW5kZXIoKSA9PSBvd25lciB8fCBFUkM3MjEuaXNBcHByb3ZlZEZvckFsbChvd25lciwgX21zZ1NlbmRlcigpKSwKICAgICAgICAgICAgIkVSQzcyMTogYXBwcm92ZSBjYWxsZXIgaXMgbm90IG93bmVyIG5vciBhcHByb3ZlZCBmb3IgYWxsIgogICAgICAgICk7CgogICAgICAgIF9hcHByb3ZlKHRvLCB0b2tlbklkKTsKICAgIH0KCiAgICAvKioKICAgICAqIEBkZXYgU2VlIHtJRVJDNzIxLWdldEFwcHJvdmVkfS4KICAgICAqLwogICAgZnVuY3Rpb24gZ2V0QXBwcm92ZWQodWludDI1NiB0b2tlbklkKSBwdWJsaWMgdmlldyB2aXJ0dWFsIG92ZXJyaWRlIHJldHVybnMgKGFkZHJlc3MpIHsKICAgICAgICByZXF1aXJlKF9leGlzdHModG9rZW5JZCksICJFUkM3MjE6IGFwcHJvdmVkIHF1ZXJ5IGZvciBub25leGlzdGVudCB0b2tlbiIpOwoKICAgICAgICByZXR1cm4gX3Rva2VuQXBwcm92YWxzW3Rva2VuSWRdOwogICAgfQoKICAgIC8qKgogICAgICogQGRldiBTZWUge0lFUkM3MjEtc2V0QXBwcm92YWxGb3JBbGx9LgogICAgICovCiAgICBmdW5jdGlvbiBzZXRBcHByb3ZhbEZvckFsbChhZGRyZXNzIG9wZXJhdG9yLCBib29sIGFwcHJvdmVkKSBwdWJsaWMgdmlydHVhbCBvdmVycmlkZSB7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lcigpLAogICAgICAgICAgICBmcm9tLAogICAgICAgICAgICB0b2tlbklkLAogICAgICAgICAgICBfZGF0YQogICAgICAgICksICJFUkM3MjE6IHRyYW5zZmVyIHRvIG5vbiBFUkM3MjFSZWNlaXZlciBpbXBsZW1lbnRlciIpOwogICAgICAgIGJ5dGVzNCByZXR2YWwgPSBhYmkuZGVjb2RlKHJldHVybmRhdGEsIChieXRlczQpKTsKICAgICAgICByZXR1cm4gKHJldHZhbCA9PSBfRVJDNzIxX1JFQ0VJVkVEKTsKICAgIH0KCiAgICAvKioKICAgICAqIEBkZXYgQXBwcm92ZSBgdG9gIHRvIG9wZXJhdGUgb24gYHRva2VuSWRgCiAgICAgKgogICAgICogRW1pdHMgYW4ge0FwcHJvdmFsfSBldmVudC4KICAgICAqLwogICAgZnVuY3Rpb24gX2FwcHJvdmUoYWRkcmVzcyB0bywgdWludDI1NiB0b2tlbklkKSBpbnRlcm5hbCB2aXJ0dWFsIHsKICAgICAgICBfdG9rZW5BcHByb3ZhbHNbdG9rZW5JZF0gPSB0bzsKICAgICAgICBlbWl0IEFwcHJvdmFsKEVSQzcyMS5vd25lck9mKHRva2VuSWQpLCB0bywgdG9rZW5JZCk7IC8vIGludGVybmFsIG93bmVyCiAgICB9CgogICAgLyoqCiAgICAgKiBAZGV2IEhvb2sgdGhhdCBpcyBjYWxsZWQgYmVmb3JlIGFueSB0b2tlbiB0cmFuc2Zlci4gVGhpcyBpbmNsdWRlcyBtaW50aW5nCiAgICAgKiBhbmQgYnVybmluZy4KICAgICAqCiAgICAgKiBDYWxsaW5nIGNvbmRpdGlvbnM6CiAgICAgKgogICAgICogLSBXaGVuIGBmcm9tYCBhbmQgYHRvYCBhcmUgYm90aCBub24temVybywgYGBmcm9tYGAncyBgdG9rZW5JZGAgd2lsbCBiZQogICAgICogdHJhbnNmZXJyZWQgdG8gYHRvYC4KICAgICAqIC0gV2hlbiBgZnJvbWAgaXMgemVybywgYHRva2VuSWRgIHdpbGwgYmUgbWludGVk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G9ubHlPd25lciB7CiAgICAgICAgcmVxdWlyZShuZXdPd25lciAhPSBhZGRyZXNzKDApLCAiT3duYWJsZTogbmV3IG93bmVyIGlzIHRoZSB6ZXJvIGFkZHJlc3MiKTsKICAgICAgICBlbWl0IE93bmVyc2hpcFRyYW5zZmVycmVkKF9vd25lciwgbmV3T3duZXIpOwogICAgICAgIF9vd25lciA9IG5ld093bmVyOwogICAgfQp9CgovLyBGaWxlOiBjb250cmFjdHMvZXJjNzIxL1Rlc3RORlQuc29sCgovLyBTUERYLUxpY2Vuc2UtSWRlbnRpZmllcjogTUlUCgpwcmFnbWEgc29saWRpdHkgXjAuNi4wOwoKCgoKY29udHJhY3QgVGVzdE5GVCBpcyBFUkM3MjEsIE93bmFibGUgewogICAgdWludDI1NiBwcml2YXRlIF9sYXN0VG9rZW5JZCA9IDA7CgogICAgY29uc3RydWN0b3IoCiAgICAgICAgc3RyaW5nIG1lbW9yeSBfbmFtZSwgCiAgICAgICAgc3RyaW5nIG1lbW9yeSBfc3ltYm9sLAogICAgICAgIHN0cmluZyBtZW1vcnkgX2Jhc2VVUkkKICAgICkgcHVibGljIEVSQzcyMShfbmFtZSwgX3N5bWJvbCl7IAogICAgICAgIF9zZXRCYXNlVVJJKF9iYXNlVVJJKTsKICAgIH0KCiAgICBmdW5jdGlvbiBfZ2VuZXJhdGVUb2tlbklkKCkgaW50ZXJuYWwgcmV0dXJucyAodWludDI1NikgewogICAgICAgIHJldHVybiArK19sYXN0VG9rZW5JZDsKICAgIH0KCiAgICBmdW5jdGlvbiBjcmVhdGVUb2tlbihhZGRyZXNzIHRvLCBzdHJpbmcgY2FsbGRhdGEgbWV0YWRhdGFVUkkpIGV4dGVybmFsIG9ubHlPd25lciByZXR1cm5zICh1aW50MjU2KSB7CiAgICAgICAgdWludDI1NiBpZCA9IF9nZW5lcmF0ZVRva2VuSWQoKTsKICAgICAgICBfbWludCh0bywgaWQpOwogICAgICAgIF9zZXRUb2tlblVSSShpZCwgbWV0YWRhdGFVUkkpOwogICAgICAgIHJldHVybiBpZDsKICAgIH0KCiAgICBmdW5jdGlvbiBjcmVhdGVUb2tlbihhZGRyZXNzIHRvKSBleHRlcm5hbCBvbmx5T3duZXIgcmV0dXJucyAodWludDI1NikgewogICAgICAgIHVpbnQyNTYgaWQgPSBfZ2VuZXJhdGVUb2tlbklkKCk7CiAgICAgICAgX21pbnQodG8sIGlkKTsKICAgICAgICByZXR1cm4gaWQ7CiAgICB9Cn0K",
"constructor_arguments": "",
"evm_version":"byzantium"
}
Query Parameters
Parameter
Description
contract_hash
type: String
value: Address of contract
required: true
contract_name
type: String
value: Name of contract
required: true
compiler
type: String
value: Solidity compiler version
required: true
runs_optimizer
type: Integer
value: Value of time which running optimizer
required: true
optimization_enabled
type: Integer
value: Identify if optimization is enable or not (1: enable, Other number: not)
required: true
contract_source
type: String
value: Solidity contract code(base64 encoding)
required: true
constructor_arguments
type: String
value: Arguments of constructor
required: true
evm_version
type: String
value: Evm version used when compiling
required: false
libraries
type: List<Object>
value: Library list used for the contract
required: false
//Response Sample Result
{
"status": "200",
"message": "success",
"results": {
"data": "1"
}
}